如何将数组发送到过程

时间:2012-04-14 18:06:56

标签: arrays assembly procedure x86-16

你好我在汇编程序8086中做DES而且我有很多数组,我也需要一些程序,但我不知道如何将数组发送到一个程序。我尝试使用堆栈但它没有工作。你能帮我个忙吗?我正在使用TASM

1 个答案:

答案 0 :(得分:2)

假设你有一个单词数组定义为:

myArray dw 10, 9, 8, 7, 6, 5, 4, 3, 2, 1
numItems dw 10

你想把它传递给一个程序:

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

然后myProc将是:

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