简体   繁体   English

这些寻址模式之间有什么区别...?

[英]What is the difference between these addressing modes...?

What is the difference between a register, indirect, base+displacement, double indirect, and PC relative.寄存器、间接、基数+位移、双重间接和 PC 相对之间有什么区别。 I'm not quite sure I understand how to differentiate between these different addressing modes given their use in some situation.鉴于它们在某些情况下的使用,我不太确定我是否理解如何区分这些不同的寻址模式。 Can someone please help me recognize the difference between them?有人可以帮我识别它们之间的区别吗?

Syntactically, at the level of the assembly code, the addressing mode is determined by multiple factors...在语法上,在汇编代码层面,寻址方式是由多种因素决定的……

  • the OP code used (eg some operations use implicitly specific registers or addressing modes)使用的 OP 代码(例如,某些操作使用隐式特定寄存器或寻址模式)
  • the operands: are these references to registers, to memory or immediate values操作数:这些是对寄存器、内存还是立即数的引用
  • some directives such as the byte directives as in MOV DWORD PTR ...一些指令,例如字节指令,如MOV DWORD PTR ...

The operand(s), and the syntax that surrounds them, however are typically the most relevant with regards to determining the addressing mode.然而,操作数和围绕它们的语法通常与确定寻址模式最相关。 This can be illustrated with the x86 MOV operation, as the same or very similar syntax applies to other operations on CPUs in the x86 family.这可以通过 x86 MOV 操作来说明,因为相同或非常相似的语法适用于 x86 系列 CPU 上的其他操作。 Similar syntax and rules apply to other processors, but of course differences in architecture such as the list and roles of registers as well as other differences make the following relatively x86-specific.类似的语法和规则适用于其他处理器,但当然架构上的差异(例如寄存器的列表和角色)以及其他差异使以下内容相对特定于 x86。
MOV has the effect of copying the data referenced by its 2nd argument into the location referred by its first argument. MOV具有将其第二个参数引用的数据复制到其第一个参数引用的位置的效果。 There are many possible combination with regard to the nature of these references:关于这些引用的性质,有许多可能的组合:

MOV <reg>, <reg>      ;  register to register
MOV <reg>, <mem>      ;  memory to register
MOV <mem>, <reg>      ;  register to memory
MOV <reg>, <const>    ;  immediate value to register
MOV <mem>, <const>    ;  immediate value to memory

Furthermore, these references may be indirect when the corresponding operand is in brackets.此外,当相应的操作数在括号中时,这些引用可能是间接的。 For example MOV WORD PTR [ebx], 99 will move the value 99 expressed as a 16 bits integer, into the memory location pointed to by the EBX register.例如MOV WORD PTR [ebx], 99会将表示为 16 位整数的值 99 移动到 EBX 寄存器指向的内存位置。

Also, the indirect memory location in bracket may be expressed as a simple arithmetic expression such as MOV [esi+eax], dl .此外,括号中的间接内存位置可以表示为简单的算术表达式,例如MOV [esi+eax], dl Here the byte in register DL is copied to the memory location found by adding the contents of ESI and EAX registers.此处将寄存器 DL 中的字节复制到通过添加 ESI 和 EAX 寄存器的内容找到的内存位置。 Note that this needn't be just two registers, it could also be expressions like [esi + 8*ebx] or [esi - 16] etc.请注意,这不仅是两个寄存器,还可以是[esi + 8*ebx][esi - 16]等表达式。

With all that in mind, here a few examples of the MOV operation in context:考虑到所有这些,这里有一些上下文中的 MOV 操作示例:

MOV eax, [edx]   ; Copies 4 bytes in memory at the address contained in EDX 
                 ; into EAX the size (4bytes) is implied by the size of EAX.

MOV [MyVar], ebx ; Copies the contents of EBX into the 4 bytes at memory address
                 ; MyVar. (Assumes MyVar is a 32-bit constant).

MOV eax, [esi-4] ; Copies 4 bytes at memory address ESI -4 into EAX

MOV [esi+eax], bl ; Copies the contents of BL (one byte) into the byte at address
                  ; ESI+EAX

MOV BYTE PTR [MyVar], 123 ;  Copies the (decimal) value 123 coded as an 8 bits
                          ; to the memory address contained by MyVar.
                          ; Here the size directive (BYTE PTR) is necessary.

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

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