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

帅比萌擦擦* 提交于 2021-02-18 23:01:08

问题


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.

enter image description here

questions :

enter image description here

answer : l-w-b-b-l-w-l

Source: Computer Systems: A Programmer's Perspective (CSAPP) by Bryant, O'Hallaron


回答1:


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)




回答2:


In step 4 the target is not the espregister, but the memory it points to. Thus the b is valid and means move the byte with the value -17h to the location where esp points currently to.



来源:https://stackoverflow.com/questions/20247944/chosing-suffix-l-b-w-for-mov-instruction

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!