Q:

how to send an array to a procedure

Hi I'm doing DES in assembler 8086 and I have a lot of arrays, also I need some procedures but I don't know how send an array to a procedure.I tried using the stack but it didn't worked. Can you give me a hand? I'm using TASM 

A:

Say you have an array of words defined as:
myArray dw 10, 9, 8, 7, 6, 5, 4, 3, 2, 1
numItems dw 10

And you want to pass that to a procedure:
push myArray  ; the address of the array
mov ax, [numItems]
push ax       ; the length of the array
call myProc
; if you want the caller to clean up ...
add sp, 4  ; adjust sp to get rid of params

Then myProc would be:
myProc:
    mov bp, sp ; save stack pointer
    mov cx, [bp+4] ; cx gets the number of items
    mov bx, [bp+6] ; bx gets the address of the array
    ; at this point, you can address the array through [bx]
    mov ax, [bx+0} ; first element of the array
    mov ax, [bx+2] ; second element of the array
    ret 4  ; cleans up the stack, removing the two words you'd pushed onto it
    ; or, if you want the caller to clean up ...
    ret

