Direct assembly language operand Offset

A variable name with a direct displacement is formed - offset operand. This allows access to those memory locations not explicitly labeled. Suppose an existing byte array arrayB:

 

arrayB BYTE 10h,20h,30h,40h,50h

The array with the source operand as a MOV instruction, the automatic transfer of the first byte of the array:

mov al, arrayB; AL = 10h

By adding 1 to access the array in the second byte offset arrayB:

mov al, [arrayB + 1]; AL = 20h

If plus 2 can access the third byte of the array:

mov al, [arrayB + 2]; AL = 30h

ArrayB + 1 shaped like the same form of expression to a so-called effective address by adding a constant offset variable. Outside of the effective address parentheses indicate, by parsing this expression can get the contents of the memory address indicated. The assembler does not require parentheses in addition to an address expression, but for clarity, we recommend using parentheses.

MASM does not have built effective address range checking. In the following example, we assume there are five bytes arrayB array, the instruction is a memory access outside of the range of the array of bytes. The result is a logic error in a difficult to find, so when checking array references to be very careful:

mov al, [arrayB + 20]; AL = ??

Word and double word

In the group of 16-bit words, the front offset ratio of more than one of each array element 2 bytes. This is why the example below, the array ArrayW to add 2 points to the second element of the array:

  .data  arrayW WORD 100h,200h,300h  .code  mov ax, arrayW                               ;AX = 100h  mov ax,[arrayW+2]                            ;AX = 200h

Similarly, if a double word, the first element 4 in order to add offset points to the second element:

  .data  arrayD DWORD l0000h,20000h  .code  mov eax, arrayD 

4.1  Operand Type
4.2  MOV instructions
4.3  MOVZX to doing it and instructions MOVSX
4.4  LAHF SAHF instruction and
4.5 of 5  XCHG instructions
4.6  immediate offset operands
4.7  assembly language data transfer Example
4.8  addition and subtraction Detailed
4.9  the OFFSET operator
4.10  the ALIGN directive
4.11  the PTR operator
4.12  the TYPE operator
4.13  lengthof operator
4.14  the LABEL directive
4.15  indirect addressing
4.16  the JMP and LOOP instruction
4.17  64 MOV instruction
4.18  64-bit addition and subtraction

Guess you like

Origin blog.csdn.net/Javaxuxuexi/article/details/93401535