简体   繁体   English

在操作码中汇编段

[英]Assembly Segments in opcodes

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? 我认为“PTR SS:”用于指定EBP-30来自堆栈? (SS: stack segment) Am I right or am I completely wrong? (SS:堆栈段)我是对还是我完全错了? :) 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? 那么在操作码中使用的DS(数据段)呢?

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

There are two separate modifiers here, DWORD PTR and SS: . 这里有两个独立的修饰符, DWORD PTRSS: .

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. 这里30也可以是一个存储的字节。

The SS: is a segment prefix, saying that we want to use an address relative to the stack segment. SS:是段前缀,表示我们想要使用相对于堆栈段的地址。 In this case it isn't strictly needed, because that is the default when using the ESP or EBP registers. 在这种情况下,它不是严格需要的,因为这是使用ESPEBP寄存器时的默认值。 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! 如果你使用EBX而不是EBP那就会有所不同!

  • SS is Stack Segment SS是Stack Segment
  • DS is Data Segment DS是数据段
  • PTR - pointer. PTR - 指针。 It's an address. 这是一个地址。

When you do 当你这样做

mov ax, some_variable

you are really substituting this form " mov ax, ds:[pointer_to_variable] " 你真的替换这个形式“ mov ax, ds:[pointer_to_variable]

In case of SS, you are accessing the value not from DS, but from the stack instead :). 在SS的情况下,您访问的值不是来自DS,而是来自堆栈而不是:)。 Think of segment registers as banks. 将段寄存器视为库。 Data comes from DS, Stack data from SS, Code data from CS, Extra segment is ES. 数据来自DS,来自SS的堆栈数据,来自CS的代码数据,额外的段是ES。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM