TASM 中带参数的函数

发布于 2024-12-20 10:14:08 字数 568 浏览 3 评论 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

Could you please post an example in assembly language that uses functions with parameters. Something simple, like function that returns a sum of two elements.

Couldn't google any example that is simple enough.

ADDED:

.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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

无敌元气妹 2024-12-27 10:14:08

这取决于您使用的 TASM 版本。在现代的你可以写这样的东西:

add_numbers PROC
    ARG number1:DWORD
    ARG number2:DWORD

    MOV eax, [number1]
    MOV ebx, [number2]
    ADD eax, ebx
    RET
add_numbers ENDP

That would depend on the version of TASM you're using. On modern ones you can write something like:

add_numbers PROC
    ARG number1:DWORD
    ARG number2:DWORD

    MOV eax, [number1]
    MOV ebx, [number2]
    ADD eax, ebx
    RET
add_numbers ENDP
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文