为 mov 指令选择后缀 (l-b-w) [英] Chosing suffix (l-b-w) for mov instruction
问题描述
我是汇编新手.我正在阅读计算机系统程序员的观点.我不明白如何为 mov
指令选择后缀.我知道每个寄存器和位数.后缀使用由位数决定(32 位 l
、16 位 w
、8 位 b
).很少有例子对前面的句子无效.例如 %esp
是 32 位寄存器,但对于 4. 步骤后缀 b
用于代替 l
.请给出使用后缀的解释.
I am new to assembly.I am reading computers system programmer's perspective. I don't understand how I choose suffix for mov
instruction. I know each register and bit count.
Suffix usage is determined by bit count (32 bit l
, 16 bit w
, 8 bit b
). Few example is not valid for prior sentence. For example %esp
is 32-bit register but for 4. step suffix b
is used instead of l
. Please give an explanation for using suffix.
问题:
答案:l-w-b-b-l-w-l
资料来源:Bryant, O'Hallaron 的《计算机系统:程序员的视角》(CSAPP)
Source: Computer Systems: A Programmer's Perspective (CSAPP) by Bryant, O'Hallaron
推荐答案
在 movb $-17,(%esp)
中的目标不是寄存器 %esp
而是地址在 %esp
中的内存位置.由于 movb
中的 b
,单个字节将存储在该内存位置.存储在那里的值将为 -17(相当于无符号字节 0xef).
In movb $-17,(%esp)
the destination is not the register %esp
but the memory location whose address is in %esp
. Because of the b
in movb
, a single byte will be stored at that memory location. The value stored there will be -17 (which is equivalent to the unsigned byte 0xef).
movw $-17,(%esp)
和 movl $-17,(%esp)
也是合法的指令,它们会做不同的事情,存储内存位置 %esp
到 %esp+1
或 %esp+3
处的 2 或 4 字节值 0xffef 或 0xffffffef.
movw $-17,(%esp)
and movl $-17,(%esp)
would also be legal instructions and they'd do different things, storing the 2 or 4 byte values 0xffef or 0xffffffef at memory locations %esp
through %esp+1
or %esp+3
.
该指令需要 b
或 w
或 l
来消除歧义,这与其他示例不同,因为 $-17
和 (%esp)
是固定大小的实体.如果你尝试 mov $-17,(%esp)
汇编器会报错.
This instruction needs the b
or w
or l
to disambiguate the meaning, unlike your other examples, because neither $-17
nor (%esp)
is a fixed-size entity. If you try mov $-17,(%esp)
the assembler will complain.
更新:我刚刚注意到问题 #5,push $0xFF
,这似乎也可能不明确(pushl $0xFF
和 pushw $0xFF
都是合法的),但是 push
有一个特殊的规则,只要有歧义就假定 l
.16 位推送非常少见(sysv ABI 将堆栈上的所有内容以 4 字节的倍数对齐,因此您始终为函数参数推送 32 位,即使它是 short
或 char
)
UPDATE: I just noticed question #5, push $0xFF
which also seems like it could be ambiguous (pushl $0xFF
and pushw $0xFF
are both legal), but there is a special rule for push
that assumes l
whenever there is an ambiguity. 16-bit pushes are very rare (the sysv ABI keeps everything aligned on the stack in multiples of 4 bytes so you always push 32 bits for a function argument, even if it's a short
or char
)
这篇关于为 mov 指令选择后缀 (l-b-w)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!