レジスタ、間接、ベース + ディスプレイスメント、二重間接、および PC 相対の違いは何ですか。状況によっては、これらの異なるアドレッシング モードを区別する方法を理解しているかどうかはよくわかりません。誰かがそれらの違いを認識するのを手伝ってもらえますか?
1 に答える
Syntactically, at the level of the assembly code, the addressing mode is determined by multiple factors...
- the OP code used (e.g. some operations use implicitly specific registers or addressing modes)
- the operands: are these references to registers, to memory or immediate values
- some directives such as the byte directives as in
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. 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.
MOV
has the effect of copying the data referenced by its 2nd argument into the location referred by its first argument. 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.
Also, the indirect memory location in bracket may be expressed as a simple arithmetic expression such as 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. Note that this needn't be just two registers, it could also be expressions like [esi + 8*ebx]
or [esi - 16]
etc.
With all that in mind, here a few examples of the MOV operation in context:
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.