9월2일자 ASM 숙제
화씨의 온도를 입력받아 섭씨 온도로 출력하기
C = (5/9) * (F-32)
소스.
.386
.MODEL FLAT
;1. The formula for converting a Fahrenheit to a Celsius temperature is
;C = (F - 32) * (5 / 9)
;Write a complete 80x86 assembly language program to prompt for a
;Fahrenheit temperature and display the corresponding Celsius temperature.
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 temperature scale", cr, Lf, Lf
BYTE "Enter Celsius Fahrenheit: ", 0
value BYTE 10 DUP (?)
answer BYTE cr, Lf, "The temperature is"
Fahrenheit BYTE 6 DUP (?)
BYTE " temperature", cr, Lf, 0
.CODE
_smart:
output prompt1 ; prompt for Celsius temperature
input value, 10 ; read ASCII characters
atoi value ; convert to integer
sub ax, 32
mov bx, 9
cwd
idiv bx
imul ax, 5
itoa Fahrenheit, ax
output answer
INVOKE ExitProcess, 0
PUBLIC _smart
실행 결과