1

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
Peter Cordes
  • 328,167
  • 45
  • 605
  • 847

1 Answers1

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)

  • 2
    You probably want `fmulp` unless you want to leave the first value in ST(1). (http://www.ray.masmcode.com/tutorial/fpuchap8.htm#fmulp / http://www.ray.masmcode.com/tutorial/index.html). But yeah, interesting that Irvine32 input functions work with a non-empty x87 register stack, unlike mainstream calling conventions where you're supposed to empty the x87 stack before calling so a callee knows it can use all 8 registers. – Peter Cordes May 14 '22 at 03:37