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

2013.09.02_4장어셈블리과제_김성엽

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


 예제 4장

 .386

.MODEL FLAT

ExitProcess PROTO NEAR32 stdcall, dwExitCode: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
_smart:
Prompt:   output Prompt1 ; prompt for Celsius temperature
          input Value,10 ; read ASCII characters
          atoi Value ; convert to integer
     
          imul ax,9 ; C*9

          add ax,2 ; rounding factor for division

          mov bx,5 ; divisor

          cwd ; prepare for division

    
          idiv bx ; C*9/5

          add ax,32 ; C*9/5 + 32

    
          itoa Temperature,ax ; convert to ASCII characters

          output Answer ; output label and result

    
          INVOKE ExitProcess, 0 ; exit with return code 0


PUBLIC _smart ; make entry point public 

END






 4장 4_4 1번문제

;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, dwExitCode:DWORD

INCLUDE io.h

cr EQU 0dh
Lf EQU 0ah

.STACK 4096 

.DATA
Prompt1       BYTE CR,LF,"This program will convert a Fahrenheit "
              BYTE "temperature to the Celsius scale",cr,Lf,Lf
              BYTE "Enter Fahrenheit temperature: ",0
Value         BYTE 10 DUP (?)
Answer        BYTE CR,LF,"The temperature is"
Temperature   BYTE 6 DUP (?)
              BYTE " Celsius",cr,Lf,0
.CODE
_smart:
Prompt:   output   Prompt1 ; prompt for Celsius temperature
          input   Value,10 ; read ASCII characters
          atoi   Value ; convert to integer
    
          sub   ax, 32 ; ax = ax-32
          imul   ax, 5 ; ax = ax*5
          add   ax, 4 ; rounding factor for division
     
          mov  cx, 9 ; divisor
          cwd ; prepare for division

          idiv  cx ; C = (5/9) * (F - 32)
      
          itoa Temperature, ax ; convert to ASCII characters
          output Answer ; output label and result
    
          INVOKE ExitProcess, 0 ; exit with return code 0

PUBLIC _smart ; make entry point public
END





728x90