我正在阅读一篇关于AT&T语法下x86汇编的教程,并遇到了这个指令:
movb $5, var(,1)
— 将值5存储到var位置上的字节中。
var(,1)
后面的 (,1)
是什么意思?这种后缀的通用语法是什么?var: # this won't be in writeable memory, it will assemble but not run
movb $5, var
movb $5, var(,1)
movb $5, (var) # turns out this is valid, too!
#movb $5, var(%rip) # RIP-relative is x86-64 only, but it's recommended when available.
# movb $5, var() # Error: junk `()' after expression
# movb $5, (var,,1) # also invalid
# movb $5, (var,%ecx,1) # also invalid.
# movb $5, (var+%eax,%ecx,1) # also invalid.
as --version
命令会输出 GNU assembler (GNU Binutils) 2.31.1
。$ gcc -m32 -no-pie -nostdlib foo.s
/usr/bin/ld: warning: cannot find entry symbol _start; defaulting to 0000000008049000
# I just wanted a linked binary with real addresses filled in, not to run it.
# entry = start of the .text section is fine.
$ objdump -drwC -Mintel a.out
08049000 <var>:
8049000: c6 05 00 90 04 08 05 mov BYTE PTR ds:0x8049000,0x5
8049007: c6 05 00 90 04 08 05 mov BYTE PTR ds:0x8049000,0x5
804900e: c6 05 00 90 04 08 05 mov BYTE PTR ds:0x8049000,0x5
cmp $1,(var)
”是使内存操作数明确的好方法?但这并不太好,因为与英特尔语法不同,你不能仅仅通过添加寄存器来实现,你必须将“var
”移出括号。
var
相同。其他版本可能需要发出一个 SIB 字节。 - Jester