0

Input are interger numbers and after calculation, i need the output is real number. How can I do it? Like when I enter 1,23,123 and the ouput of second calculation is -33 while the actual result is -33.3

    include \masm32\include\masm32rt.inc
    
    .code

start:
    call main
    exit
main proc
    LOCAL var1:DWORD
    LOCAL var2:DWORD
    LOCAL var3:DWORD
    LOCAL tong:DWORD
    LOCAL result:DWORD
    LOCAL remainder:DWORD
    LOCAL a:DWORD
    LOCAL b:DWORD
    mov var1, sval(input("Enter number 1: "))
    mov var2, sval(input("Enter number 2: "))
    mov var3, sval(input("Enter number 3: "))
    mov result, 0

    print chr$("v1 + v2 + v3 = ")
    mov eax, var1
    add eax, var2
    add eax, var3
    mov tong, eax
    print str$(tong)
    print chr$(13,10)

    print chr$("[(v1 * v2) - v3] / 3 = ")
    mov eax, var1
    cdq
    Imul var2
    cdq
    mov a, eax
    sub eax, var3
    mov b, eax
    mov edx, 0
    mov eax, b
    cdq
    mov ecx,3
    idiv ecx
    mov result, eax
    mov remainder, edx
    print str$(result)
    ret

main endp

end start

I need the output is real number.

  • `cvtsi2sd xmm0, eax` converts an integer to double-precision floating point. `divsd` is FP divide. But the hard part is converting FP to a decimal string, unless you have a library function for it. – Peter Cordes Mar 07 '23 at 10:12
  • You should write some code to do calculation in real number. Using MMX/SSE instructions may be the easiest way if allowed. Other options are 8087 operations (maybe harder) or manual implementaion of operations (hard). – MikeCAT Mar 07 '23 at 10:14
  • 2
    In this case (input are integers and only /3 is difficult part), instead of using real numbers, you can do calculation in integers multiplied by 10 and add some code to printing to print the least digit after a dot. – MikeCAT Mar 07 '23 at 10:17
  • @MikeCAT Thanks for your help. When I did that, the output is -33.-3. May I ask you how to convert -3 to 3 please? – Sơn Nguyễn Mar 07 '23 at 11:18

0 Answers0