如何使用ASM中的浮点堆栈乘以2个数字(用户输入)?

发布于 2025-01-28 02:19:57 字数 768 浏览 4 评论 0原文

我创建了一个PROC,该PROC将收集用户输入以达到余额,利率&单独文件中的期限(年数)。利率是浮点(分数数 - 不是整数)。我不确定我的平衡是否需要转换为浮点以使其乘以速率。

然后,我在单独的文件中原型原型并在main下打电话。我需要使用此公式: 利息=余额 *利率 / 100.0;计算利息。我正在努力增加平衡和速率。请指教。

该代码仅将利率自身乘以主要。

fmul ST(0), ST(0)
call writeFloat

balances.asm proc

yearlyBalance PROC

    mov edx, OFFSET balanceNum
    call writeLine
    call readInt
    fst bal
    fld bal
    

    mov edx, OFFSET interestRate
    call writeLine
    call readFloat

    mov edx, OFFSET years
    call writeLine
    call readInt
    endl 

    ret

yearlyBalance ENDP

main.asm

main PROC

    call yearlyBalance
    
    fmul ST(0), ST(0)
    call writeFloat 
    endl

    exit
main ENDP 
END main

I've created a PROC that will gather user input for a balance, interest rate & length of term (# of years) in a separate file. The interest rate is a floating point (fractional number - not an integer). I'm not sure if my balance needs to be converted to a floating point to multiply it by the rate.

I then PROTOtype that PROC in the separate file and call under main. I need to use this formula:
interest = balance * rate / 100.0; to calculate the interest. I'm struggling to multiply the balance and rate. Please advise.

this code just multiplies the interest rate by itself in main.

fmul ST(0), ST(0)
call writeFloat

balances.asm PROC

yearlyBalance PROC

    mov edx, OFFSET balanceNum
    call writeLine
    call readInt
    fst bal
    fld bal
    

    mov edx, OFFSET interestRate
    call writeLine
    call readFloat

    mov edx, OFFSET years
    call writeLine
    call readInt
    endl 

    ret

yearlyBalance ENDP

main.asm

main PROC

    call yearlyBalance
    
    fmul ST(0), ST(0)
    call writeFloat 
    endl

    exit
main ENDP 
END main

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

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

发布评论

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

评论(1

灼痛 2025-02-04 02:19:57

使用ReadFloat将第一值放在堆栈ST的顶部(0)(1st readFloat)

使用ReadFloat将值放在堆栈ST(0)的顶部,然后将第一个推到ST(1)(2nd ReadFloat)

使用FMUL ST (0),st(1)乘以两个数字并将结果放在st(0)

use readFloat to place first value on the top of the stack ST(0) (1st readFloat)

use readFloat to put value on top of the stack ST(0) and push the first to ST(1) (2nd readFloat)

use fmul ST(0), ST(1) to multiply the two numbers and puts the result at ST(0)

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