0

您能否用汇编语言发布一个使用带参数的函数的示例。一些简单的东西,比如返回两个元素之和的函数。

无法谷歌任何足够简单的例子。

添加:

.model small 
.data

.stack  320h 
.code   
    extrn  writer:near

    add_numbers PROC
        ARG number1:WORD
        ARG number2:WORD

        MOV ax, number1
        MOV bx, number2
        ADD ax, bx
        CALL writer ; this procedure prints the contents of ax

        RET 
    add_numbers ENDP

    .startup
    PUSH 1
    PUSH 2
    CALL add_numbers ; instead of 3 it prints -11602
    call writer ; instead of 3 it prints 0
.EXIT
    END
4

1 回答 1

2

这取决于您使用的 TASM 版本。在现代的上,您可以编写如下内容:

add_numbers PROC
    ARG number1:DWORD
    ARG number2:DWORD

    MOV eax, [number1]
    MOV ebx, [number2]
    ADD eax, ebx
    RET
add_numbers ENDP
于 2011-12-10T10:34:29.397 回答