myvar1 DW 01234h ; define word variable (value=1234h) myvar2 DW 01234 ; define word variable (value=1234d = 4D2) myvar3 DW ? ; define word variable (value uncertain) myvar4 DW ABCDh ; Illegal! ece291msg DB 'ECE291 is great' start: mov ax,cs ; set up data segment mov ds,ax ; DS=CS ; NASM syntax for memory access ; any memory reference we make is assumed to reside in the DS segment mov ax,[myvar2] ; AX <- myvar ; == mov ax,[offset myvar] ; == mov ax,[2] mov si,myvar2 ; use SI as a pointer to myvar2 ; (equiv C code: SI=&myvar2 ) mov ax,[si] ; read memory at myvar2 (*(&myvar2)) ; (indirect reference) mov bx,ece291msg ; BX is a pointer to a string ; (equiv C code: BX=&hellomsg) dec BYTE [bx+1] ; make that 'C' a 'B' !!!! mov si, 1 ; Use SI as an index inc [ece291msg+SI] ; == inc [SI + offset ece291msg] ; == inc [SI + 8] ; == inc [9] ; Memory can be addressed using four registers: ; SI -> Assumes DS ; DI -> Assumes DS ; BX -> Assumes DS ; BP -> Assumes SS !!! (this is why it isn't frequently used) ; Examples: mov ax,[bx] ; ax <- word in memory pointed to by BX mov al,[bx] ; al <- byte in memory pointed to by BX mov ax,[si] ; ax <- word pointed to by SI mov ah,[si] ; ah <- byte pointed to by SI mov cx,[di] ; di <- word pointed to by DI mov ax,[bp] ; AX <- SS:[BP] STACK OPERATION!!!! ; In addition, BX+SI and BX+DI are allowed: mov ax,[bx+si] mov ch,[bx+di] ; Furthermore, a fixed 8-bit or 16-bit displacement from the ; registers!: mov ax,[23h] ; ax <- word in memory DS:0023 mov ah,[bx+5] ; ah <- byte in memory DS:(BX+5) mov ax,[bx+si+107] ; ax <- word at DS:(BX+SI+107) mov ax,[bx+di+47] ; ax <- word at DS:(BX+DI+47) ; REMEMBER: memory to memory moves are ILLEGAL!!! ; mov [bx],[si] ;ILLEGAL mov [di],[si] ;ILLEGAL (use movsw) ; Special case: stack operations! pop myvar ; myvar <- SS:[SP]