汇编语言温度转换

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

温度转换;

; uses formula F = (9/5)*C + 32

; author: R. Detmer

; date: revised 9/97

.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 ;

_start:

Prompt: output Prompt1 ; 提示输入摄氏温度

input Value,10 ; 读取字符

atoi Value ; 转为整数

imul ax,9 ; C*9

add ax,2 ; 加取整因子2到被除数

mov bx,5 ;

cwd ; 扩展被除数

idiv bx ; C*9/5

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

itoa Temperature,ax ;转为ascii

output Answer ;输出提示和得到最后结果

INVOKE ExitProcess, 0 ; 推出并返回0

PUBLIC _start ; 公开程序入口点

END

游戏程序

.386

.MODEL FLAT

INCLUDE io.h

ExitProcess PROTO NEAR32 stdcall, dwExitCode:DWORD

cr EQU 0dh ;

Lf EQU 0ah ;

.STACK 4096 ;

.DATA ;

prompt1 BYTE cr,Lf,Lf,"Player 1, please enter a number: ", 0 target DWORD ?

clear BYTE 24 DUP (Lf), 0

prompt2 BYTE cr,Lf,"Player 2, your guess? ", 0

stringIn BYTE 20 DUP (?)

lowOutput BYTE "too low", cr, Lf, 0

highOutput BYTE "too high", cr, Lf, 0

gotItOutput BYTE "you got it", cr, Lf, 0

countLabel BYTE Lf, "Number of guesses:"

countOut BYTE 6 DUP (?)

BYTE cr, Lf, Lf, Lf, "Do you want to play again? ",0 .CODE ; start of main program code

_start:

untilDone: output prompt1 ;

input stringIn, 20 ;取数 r

atod stringIn ; 转为整

mov target,eax ; 存目标t

output clear ; 清屏

mov cx, 0 ;计数位0

untilMatch: inc cx ; 递增猜的次数

output prompt2 ; ask player 2 for guess

input stringIn, 20 ; get number

atod stringIn ; convert to integer

cmp eax, target ; 比较所采的书和目标数

jne ifLess ; guess = target ?

equal: output gotItOutput ; 显示答对了

jmp endCompare

ifLess: jnl isGreater ; guess < target ?

output lowOutput ; 显示太小了

jmp endCompare

isGreater: output highOutput ; display "too high" endCompare:

cmp eax, target ; compare guess and target jne untilMatch ; 再次询问是否采的书=目标数

itoa countOut, cx ; 将count to ASCII

output countLabel ; 显示标号,count和提示符 input stringIn, 20 ; 取出响应

cmp stringIn, 'n' ; response = 'n' ?

je endUntilDone ; 是则退出

cmp stringIn, 'N' ; response = 'N' ?

jne untilDone ; 不是则重复endUntilDone:

INVOKE ExitProcess, 0 ;

PUBLIC _start ;

END ;

输入一个数组,报出他们的平均数以及在平均数以上的书

.386

.MODEL FLAT

INCLUDE io.h

ExitProcess PROTO NEAR32 stdcall, dwExitCode:DWORD

cr EQU 0dh ; carriage return character

Lf EQU 0ah ; linefeed character

maxNbrs EQU 100 ; 数组大小

.STACK 4096

.DATA

directions BYTE cr, Lf, 'You may enter up to 100 numbers'

相关文档
最新文档