0

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

4

1 回答 1

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
于 2012-04-14T19:28:28.503 回答