; CIS-261
; c_arrays.asm
; @topic W090110 ASM addressing similar to C array
; @brief ASM program using indirect addressing

.386                ; Tells MASM to use Intel 80386 instruction set.
.MODEL FLAT         ; Flat memory model
option casemap:none ; Treat labels as case-sensitive

INCLUDE IO.H        ; header file for input/output

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
.CONST              ; Constant data segment
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
.DATA               ; Begin initialized data segment
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

num_one DWORD ?
table   DWORD    10 DUP (0)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
.CODE               ; Begin code segment
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

_main PROC          ; Beginning of code
    mov EAX, 5
    mov DWORD PTR [num_one], EAX    ; use direct memory access to store integer 5
    mov ESI, 0                      ; array index is in ESI
    mov EAX, table[ ESI*4 ]         ; access data inside C array
    mov EAX, [ table + ESI*4 ]      ; the same as above
    ret
    
_main ENDP
END _main       ; Marks the end of the module and sets the program entry point label