<<< Ambiguous moves: PTR directive     Index     ADDR and OFFSET >>>

21. OFFSET and PTR Example


 
 ; offset_ptr.asm
 ; OFFSET and PTR demo program
 .586P
 ; Flat memory model
 .MODEL FLAT, STDCALL
 ;---------------------------------------
 ; Data segment
 _DATA SEGMENT
         num  DWORD   0
 _DATA ENDS
 ; Code segment
 _TEXT SEGMENT
 START:
         lea     ESI, num           ; Load effective address
         mov     ESI, OFFSET num
         mov     bx, WORD PTR num   ; WORD PTR needed because num declared DWORD
         mov     [ESI], bx          ; Copy a word-size value (BX is 16-bit)
         mov     BYTE PTR [ESI], 5  ; Store 8-bit value
         mov     WORD PTR [ESI], 5  ; Store 16-bit value
         mov     DWORD PTR [ESI], 5 ; Store 32-bit value
         ret                        ; Exit
 _TEXT ENDS
 END START
 
 

<<< Ambiguous moves: PTR directive     Index     ADDR and OFFSET >>>