PTR Operator


The 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 (32 bits) variable named into register. The sizes of the two operands of instruction must be equal.
Syntax Error
 .data
  X  DWORD  12345678h
 .code
 main PROC
  mov  ax, X

The following diagram shows the little endian storage format used by the Intel processors.

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

†Not only the 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

 INCLUDE Irvine32.inc
 .data
  X  DWORD  12345678h
 .code
 main PROC 
  mov   eax, 0
  mov   ax,  X+2
  call  WriteHex
  exit
 main ENDP
 END main

 INCLUDE Irvine32.inc
 .data
  X  DWORD  12345678h
 .code
 main PROC
  mov   eax, 0
  mov   ax,  WORD PTR X+2
  call  WriteHex
  exit
 main ENDP
 END main
 INCLUDE Irvine32.inc 
 .data
  X BYTE  12h,34h,56h,78h
 .code
 main PROC 
  mov   eax, 0
  mov   ax, WORD PTR X+2
  call  WriteHex
  exit
 main ENDP
 END main
Output Output Output

 

 

 

 

 

 




      “Sometimes the road less traveled is less traveled for a reason.”    
      ― Jerry Seinfeld