Bug 291 - GAS assemble direct constant as memory reference
Summary: GAS assemble direct constant as memory reference
Status: RESOLVED WONTFIX
Alias: None
Product: binutils
Classification: Unclassified
Component: gas (show other bugs)
Version: 2.22
: P2 normal
Target Milestone: ---
Assignee: unassigned
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-07-28 18:28 UTC by ermo
Modified: 2022-07-22 06:25 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description ermo 2004-07-28 18:28:30 UTC
Hello,

   in the following code snippet, GAS assemble what should
be a direct constant as it were a memory reference.

binutils 2.15.90
GAS version 2.15.90
Platform Windows XP.

Comments show the interesting line. Comments follow.

_________________________________________________________________________

.intel_syntax noprefix

.data
	Format: .asciz "FormatLen = %d - %d\n"
	FormatLen= . - Format # FormatLen=0x15

.text

.global _main

_main:
	push ebp
	mov ebp, esp

	# Following instruction assembles as
	# it were written:	 
	# push dword ptr [0x15]
	push FormatLen
	# whereas it should be just like:	
	push 0x15
	push offset Format
	call _printf
	add esp, 12
	
	xor eax, eax
	
	mov esp, ebp	
	pop ebp
   	ret

.end
_________________________________________________________________________

Maybe that doesn't show up in AT&T syntax because
constants are $-prefixed.

As far as I know, Intel syntax is:

- Load a constant (note no brackets):

    mov eax, 0x12

   which should also be for symbolic constants

- Load the value at the specified address (note brackets):

    mov eax, dword ptr [myLabel]

- Load address (note the OFFSET keyword):

    mov eax, offset myLabel

Thank you for your attention. And thank you all for your work
aimed to allowing Windows users easy access to GNU tools.
Comment 1 Alan Modra 2005-09-16 07:38:13 UTC
Fixed on mainline
Comment 2 Kenney 2012-02-19 02:02:18 UTC
This bug has reappeared, or is still present (using .intel_syntax noprefix)

GNU assembler version 2.22.51 (i686-cygwin) using BFD version (GNU Binutils) 2.2
2.51.20111013

Example: (test.s)
--------------------------------------
.intel_syntax noprefix
.text
.equ    A,      0xaaaa
        B =     0xbbbb

        mov     ax, A
        mov     ax, B
        mov     ax, C
        mov     ax, D

.equ    C,      0xcccc
        D =     0xdddd
-------------------------------------
$ as test.s
$ objdump -Mintel-mnemonic -d a.out
-----------------------------------------------------
a.out:     file format pe-i386

Disassembly of section .text:

00000000 <.text>:
   0:   66 b8 aa aa             mov    ax,0xaaaa
   4:   66 b8 bb bb             mov    ax,0xbbbb
   8:   66 a1 cc cc 00 00       mov    ax,ds:0xcccc
   e:   66 a1 dd dd 00 00       mov    ax,ds:0xdddd
------------------------------------------------------

EXPECTED output:
-----------------------------------------------------
00000000 <.text>:
   0:   66 b8 aa aa             mov    ax,0xaaaa
   4:   66 b8 bb bb             mov    ax,0xbbbb
   8:   66 b8 cc cc             mov    ax,0xcccc
   e:   66 b8 dd dd             mov    ax,0xdddd
-----------------------------------------------------
Comment 3 Alan Modra 2022-07-22 06:25:49 UTC
The comment #2 testcase isn't fixable without a two-pass assembler or a change in assembly syntax.