IAR 中的乘法子例程返回随机值

发布于 2025-01-19 00:56:49 字数 687 浏览 4 评论 0原文

目前,我已经创建了一种相当硬编码的方式,将值乘以10。虽然测试表示子例程,但我注意到,如果我将subroutine称为多次以上,那么返回的值不是我所期望的。我越过呼叫,但是,如果我将其按预期运行,则该调用的工作原理。

例如:

digit1: 5

fiveThousand:
        call   #multiply10
        call   #multiply10
        call   #multiply10
        mov.b  digit1,R10
       


multiply10:
        mov.b digit1,R12
        mov.b digit1,R13
        add   R13,R12  
        add   R13,R12  
        add   R13,R12  
        add   R13,R12  
        add   R13,R12  
        add   R13,R12  
        add   R13,R12  
        add   R13,R12  
        add   R13,R12  
        mov.b R12,digit1
        mov.b #0,R13
        mov.b #0,R12
        ret

然后,返回到R10的值将为160,而不是预期的5,000。

Currently I've created a rather hardcoded way of multiplying a value by 10. While testing said subroutine, I've noticed that if I call the subroutine more than one time, the value that'll be returned is not the one I anticipated if I step over the call, however if I step into the call it works as intended.

For example:

digit1: 5

fiveThousand:
        call   #multiply10
        call   #multiply10
        call   #multiply10
        mov.b  digit1,R10
       


multiply10:
        mov.b digit1,R12
        mov.b digit1,R13
        add   R13,R12  
        add   R13,R12  
        add   R13,R12  
        add   R13,R12  
        add   R13,R12  
        add   R13,R12  
        add   R13,R12  
        add   R13,R12  
        add   R13,R12  
        mov.b R12,digit1
        mov.b #0,R13
        mov.b #0,R12
        ret

Then the value returned to R10 will be 160, not 5,000 as expected.

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

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

发布评论

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