PTR
Operator
PTR
operator is to override the declared size of an operand.
It is used when access the variable using a size attribute that is different from the one used to declared the variable.
The code on the right tries to move the higher 16 bits of a DWORD (32 bits) variable named X into AX register. The sizes of the two operands of MOV instruction must be equal.
|
|
X DWORD 12345678h
|
||||||
---|---|---|---|---|---|---|
X | X+1 | X+2 | X+3 | |||
Offset | 0000 | 0001 | 0002 | 0003 | ||
DWORD |
12345678h | |||||
WORD |
5678h | 1234h | ||||
BYTE |
78h | 56h | 34h | 12h |
PTR
operator moves larger values to smaller destinations, but it also moves smaller values to larger destinations.
DWORD+2 |
WORD PTR DWORD+2 |
WORD PTR BYTE+2 |
.data X DWORD 12345678h .code mov eax, 0 mov ax, X+2 call WriteHex |
.data X DWORD 12345678h .code mov eax, 0 mov ax, WORD PTR X+2 call WriteHex |
.data X BYTE 12h,34h,56h,78h .code mov eax, 0 mov ax, WORD PTR X+2 call WriteHex |
Output | Output | Output |