본문 바로가기
코스웨어/13년 스마트컨트롤러

어셈블리어 과제_ 진종영

by 알 수 없는 사용자 2013. 9. 2.
728x90
반응형

 

 The formula for converting a Fahrenheit to a Celsius temperature is
  C = (5/9) * (F - 32)
 Write a complete 80x86 assembly language program to prompt for a Fahrenheit temperature

 and display the corresponding Celsius temperature.

 
.386
.MODEL FLAT

 

ExitProcess PROTO NEAR32 stdcall, dxExitCode:DWORD

 

INCLUDE io.h

 

cr  EQU  0dh
Lf  EQU  0ah

 

.STACK 4096

 

.DATA

Prompt1        BYTE  CR,LF,"This program will convert"
                   BYTE  "a Fahrenheit to a Celsius temperature ",cr,Lf,Lf
                   BYTE  "Enter Fahrenheit temperature: ", 0
Value           BYTE  10 DUP (?)

Answer        BYTE  CR,LF,"C ="
Temperature  BYTE  6 DUP (?)
                   BYTE  cr,Lf,0
        

.CODE
_start:
Prompt:
                  ;C = (5/9) * (F - 32)
                  output  Prompt1
                  input  Value,  10 
                  atoi  Value

           

            sub  ax, 32                     ; ax = (F-32)
            imul ax, 5                        

            cwd                               ;ax 부호확장
            mov  bx, 9
            idiv  bx                           ;ax =  5*(F-32) /9

           

            itoa Temperature, ax

            output Answer

  
            INVOKE ExitProcess, 0


PUBLIC _start
END
 


 

.386
.MODEL FLAT

 

ExitProcess PROTO NEAR32 stdcall, dxExitCode:DWORD

 

INCLUDE io.h

 

cr  EQU  0dh
Lf  EQU  0ah

 

.STACK 4096

 

.DATA

Prompt1         BYTE  CR,LF,"This program will convert a Celsius "
                    BYTE  "temperature to the Fahrenheit scale",cr,Lf,Lf
                    BYTE  "Enter Celsius temperature: ",0
Value            BYTE  10 DUP (?)
Answer         BYTE  CR,LF,"The temperature is"
Temperature   BYTE  6 DUP (?)
                    BYTE  " Fahrenheit",cr,Lf,0
        
.CODE
_start:
Prompt:

 

 ;F = (9/5)*C + 32
 output  Prompt1
 input  Value,  10
 atoi  Value

 

 imul  ax,  9                     ; C*9
 add  ax, 2
 mov  bx, 5
 cwd
 idiv  bx                         ; C*9/5
 add  ax, 32                   ; C*9/5 + 32
 
 itoa Temperature, ax

 output Answer
  
 INVOKE ExitProcess, 0

PUBLIC _start
END

 

 

728x90