Assembly Segments in opcodes

偶尔善良 提交于 2020-08-21 05:28:59

问题


I noticed that in Assembly segments are used in opcodes.

Example:

MOV DWORD PTR SS:[EBP-30],30

I think that "PTR SS:" is used to specify that EBP-30 comes from the stack? (SS: stack segment) Am I right or am I completely wrong? :) And, could you please tell me the difference between the example above and

MOV DWORD PTR[EBP-30],30

And what about DS (data segment) used in opcodes?


回答1:


MOV DWORD PTR SS:[EBP-30],30

There are two separate modifiers here, DWORD PTR and SS:.

The first one tells us that we want to store a word at the address pointed to. This is needed when the assembler cannot tell that from the operands of the instruction. Here 30 could just as well be a byte to store.

The SS: is a segment prefix, saying that we want to use an address relative to the stack segment. In this case it isn't strictly needed, because that is the default when using the ESP or EBP registers. So the second version of the instruction is identical to the first one.

Had you used EBX instead of EBP there would have been a difference!




回答2:


  • SS is Stack Segment
  • DS is Data Segment
  • PTR - pointer. It's an address.

When you do

mov ax, some_variable

you are really substituting this form "mov ax, ds:[pointer_to_variable]"

In case of SS, you are accessing the value not from DS, but from the stack instead :). Think of segment registers as banks. Data comes from DS, Stack data from SS, Code data from CS, Extra segment is ES.



来源:https://stackoverflow.com/questions/10820836/assembly-segments-in-opcodes

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