0

I want to create a program that can transfer Fahrenheit degree into Celsius . The problem is that my program output crazy number when the Celsius degree is negative, even though I tried to use idiv and div instruction but it doesn't work . Does anyone have ideas on how to fix this?

Here is my assembly code

.386
.MODEL FLAT

ExitProcess PROTO NEAR32 stdcall, dwExitCode:DWORD

include io.h            ; header file for input/output

cr      equ     0dh     ; carriage return character
Lf      equ     0ah     ; line feed

.STACK  4096             ; reserve 4096-byte stack

.DATA                   ; reserve storage for data
enterdegree   byte    "Enter the temperature in fahrenheit:",0
degree        qword      ?

result        byte    "the temperature in celsius is: "
celi           byte    40 dup(?)


.CODE                           ; start of main program code
_start:
            ;input degree in fahrenheit
            output enterdegree
            input  degree ,8
            atod   degree
            ;(f-32)
            sub    eax,32
            
            ;(f-32)*5
            mov    edx,0
            mov    ebx,5
            imul   eax,ebx
            
            ;(f-32)*5/9
            mov    edx,0
            mov    ebx,9
            idiv    ebx
            
            dtoa   celi,eax
            
            output result


            INVOKE ExitProcess, 0   ; exit with return code 0

PUBLIC _start                       ; make entry point public
END                                 ; end of source code

0 Answers0