Chosing suffix (l-b-w) for mov instruction

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) 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.

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.

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)

Tags:

Assembly

X86

Att