您如何知道如何在以下汇编代码中填写下划线:
mov_ %eax, (%rsp)
字节为“b”,字为“w”,双字为“l”,四字为“q”。寄存器的语法应该(我认为)表明移动了多少数据。我查看了我的书,似乎无法确定如何确定。
有没有通用的方法来解决这个问题?
答案 0 :(得分:6)
If one operand of mov
is a register, then the size is implied: AL
is one byte, AX
two, EAX
four and RAX
eight. If one operand is a memory location and the other an immediate value, you have to specify the desired size:
mov BYTE PTR [RAX], 1 ; *(uint8_t *)(rax) = 1
mov WORD PTR [RAX], 1 ; *(uint16_t *)(rax) = 1
mov DWORD PTR [RAX], 1 ; *(uint32_t *)(rax) = 1
mov QWORD PTR [RAX], 1 ; *(uint64_t *)(rax) = 1
The above is Intel syntax as used by the architecture manual. In AT&T syntax, the first line would be movb $1, (%rax)
; AT&T syntax uses suffixed instructions like movb
, movw
, movd
and movq
to indicate operand widths.
答案 1 :(得分:4)
AT&T assembler is not ambiguous, so it must match the operands, even if the operands(registers) contain enough size information.
%eax is a 32-bit register (just like %al is 8-bit, %ax is 16-bit and %rax is 64-bit).
While %rsp in (%rsp) is 64-bit, the expression (%rsp) is a move to the memory location held in %rsp, and as such has no register size associated to it.
So the mov(e) is 32-bit, and the suffix is l.