在此代码块中,Sub的目的是什么?使用SUB的替代方法是什么?

发布于 2025-02-12 00:40:17 字数 525 浏览 0 评论 0原文

.386
.MODEL FLAT, stdcall
.STACK 4096

ExitProcess PROTO, dwExitCode:DWORD

.data
arr1 DWORD 25, 89, 49, 80 
arr2 DWORD 30, 100, 50, 150 

.code
_main PROC
    sub eax, eax
    add eax, [arr1 + 0]
    add eax, [arr1 + 4]
    add eax, [arr1 + 8]
    add eax, [arr1 + 12]

    INVOKE ExitProcess, 0
_main ENDP

END

当我取出sub添加数组中值的总和是错误的,但我不明白为什么。为了理解sub eax,eax清除了寄存器,但我可能错了。我被告知使用movsx而不是sub,但不是MOVSX仅在不同的数据类型大小之间使用时才使用?

.386
.MODEL FLAT, stdcall
.STACK 4096

ExitProcess PROTO, dwExitCode:DWORD

.data
arr1 DWORD 25, 89, 49, 80 
arr2 DWORD 30, 100, 50, 150 

.code
_main PROC
    sub eax, eax
    add eax, [arr1 + 0]
    add eax, [arr1 + 4]
    add eax, [arr1 + 8]
    add eax, [arr1 + 12]

    INVOKE ExitProcess, 0
_main ENDP

END

When I took out sub the sum of adding the values in the array was wrong but I don't understand why. To my understanding sub eax, eax clears the register but I could be wrong. I was told to use something like movsx instead of sub but isn't movsx only used when going between different data type sizes?

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文