PTR assembly language operators: rewriting operands Size Type

PTR operator can be used to rewrite the operand has been declared a type size. As long as attempting to access the operand size is different from the assembler attribute set, then the operator is required.

 

For example, suppose one wanted to double word variable myDouble lower 16 bits to AXO since the operand size mismatch, therefore, the assembler will not allow this operation:

  .data  myDouble DWORD 12345678h  .code  mov ax,myDouble

However, using the operator will be able to WORD PTR low word (5678h) into AX:

  mov ax,WORD PTR myDouble

Why is not fed into the AX 1234h? Because, the x86 processor is little-endian format, which means the variables stored in the low byte of the start address. As shown below, showing three ways myDouble memory layout: The first column is a double word, the second column is the word (5678h, 1234h), the third column is four bytes (78h, 56h, 34h , 12h).

PTR assembly language operators: rewriting operands Size Type

Regardless of how the variables are defined, you can use any one of three methods to access memory. For example, if the offset myDouble 0000, places the 16-bit offset value headed address is stored in 5678h. Also be retrieved to 1234h, which is a word address myDouble + 2, the following command:

  mov ax,WORD PTR [myDouble+2]     ; 1234h

Similarly, with the BYTE PTR operator can be transmitted to a single byte myDouble BL:

  mov b1,BYTE PTR myDouble       ; 78h

Note that, the compilation and the PTR must be used with a standard data types, which include: BYTE, SEYTE, WORD, SWORD, DWORD, SDWORD, FWORD, QWORD or TBYTE.

The smaller value of the destination operand into larger

The two programs may require a smaller value into a larger destination operand. The following example, the first word copied into the lower half of EAX, copy the second word into the upper half. DWORD PTR operator and this operation can be realized:

  .data  wordList WORD 5678h,1234h  .code  mov eax, DWORD PTR wordList      ; EAX = 12345

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/93401703