Simple Data Structures

Dr. Tim McGuire
CS 272
Sam Houston State University

Addressing Data in Memory Memory-Addressing Modes Direct                    mov ax,[count]
Register-indirect     mov ax, [bx]
Base                     mov ax,[record + bp]
Indexed                mov ax,[array + si]
Base-indexed        mov ax,[recordArray + bx + si]
String       lodsw
I/O Port               in ax, dx
Direct Addresses Register-Indirect Mode Example Another example bx=1000h, si=2000h, di=3000h, [1000h]=1BACh, [2000h]=20FEh, [3000h]=031Dh

instruction source offset result

mov bx,[bx] 1000h     1BACh

mov cx,[si] 2000h     20FEh

mov bx,[ax]     illegal source register

add [si],[di]   illegal memory-memoryadd

inc [di]    3000h     031Eh

WORD and BYTE operators mov [BYTE bx],1 mov [WORD bx],1 Based and Indexed Addressing Modes Syntax of an operand


Application of Index Mode

msg     db      "this is a message"
        mov     cx,17         ; # chars in string
        xor     si,si         ; si indexes a char
top:    cmp     [si+msg],' '  ; blank?
        je      next          ; yes, skip over
        and     [si+msg],DFh  ; no, convert to upper
next:   inc     si            ; index next byte
        loop    top           ; loop until done
 
Base-Indexed Addressing Mode Use of Based, Indexed, and Base-Indexed Modes Expressions and Operators db define byte (characters)

dw define word (integers)

dd define doubleword (long integers)

dq define quadword (real numbers)

dt define tenbytes (BCD numbers)

dp define pointer (32 bits)

df define far pointer (48 bits)

arry dw 100 DUP (0) ;array of 100 words, all set to 0
str db 212 DUP (?)  ;array of 212 bytes, uninitialized
String Variables Local Labels
                jmp     There   ; jump to global label 
          @@10: 
                inc     ax 
                cmp     ax,10 
                jne     @@10    ; jump to local label above 
          There: 
                cmp     ax,20 
                je      @@10    ; jump to local label below 
                xor     cx,cx 
          @@10: