For each of the following lines of assembly language determi
For each of the following lines of assembly language, determine the appropriate instruction suffix based on the operands. (For example, mov can be rewritten as movb, movw, or movl.) mov %eax, (%esp) mov (%eax), %dx mov $0xFF, Xb1 mov (%esp, 7.edx, 4), %dh push $OxFF mov %dx, (%.eax) pop %edi
Solution
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 in the memory location. The value stored there will be -17 whose equivalent unsigned byte is 0xef.
movw $-17,(%esp), movl $-17,(%esp) are also valid but differ in storing the 2 or 4 byte values 0xffef ,0xffffffef at memory locations %esp through %esp+1 or %esp+3.
The instruction needs to be either b or w or l to avoid ambiguity since neither $-17 nor %esp is a fixed size entity. If you try with neither of them the assembler will complain.
push $0xFF can be written as pushl $0xFF or pushw $0xFF but push has special rules that assumes 1 at times of ambiguity. 16 bit pushes are rare.
