题目1 求解绝对值。
实验要求:从键盘输入一个数字,转换成数值后,求解其绝对值,并显示结果在屏幕上。
;求解绝对值
;作者:KUN.A.A
;date:2022/04/08
.386
.MODEL FLAT
ExitProcess PROTO NEAR32 stdcall, dwExitCode:DWORD
INCLUDE io.h
cr EQU 0dh ; carriage return character
LF EQU 0ah ; linefeed character
.STACK 4096 ; reserve 4096-byte stack
.DATA ; reserve storage for data
Prompt1 BYTE "This program will output absolute value you input",cr,Lf,Lf
BYTE "Please input value: ",0
value BYTE 10 DUP(?),0
Prompt2 BYTE cr,Lf,Lf,"The result is: ",0
.CODE ; start of main program code
_start:
output Prompt1 ;输出语句1
input value,10 ;输入value
atoi value ;转为整型
cmp ax,0 ;比较value与0
jge overZero ;大于等于0跳转
neg ax ;小于零取反
overZero: output Prompt2 ;大于0直接输出结果,小于0取反后输出结果
itoa value,ax ;转为ASCII码,转为整型
output value ;输出value
INVOKE ExitProcess, 0 ; exit with return code 0
PUBLIC _start ; make entry point public
END ; end of source code
题目2 求总评成绩
从键盘输入一同学的期中成绩、实验成绩、期末成绩和它们在总评成绩中分别占的百分比,计算得到该同学的总评成绩,并显示出来。
要求:该程序提示输入3个成绩和所占百分比。可参考如下的例子显示:
grade 1 ? 85
percent 1 ? 20
grade 2 ? 75
percent 2 ? 20
grade 3 ? 82
percent 3 ? 60
score is : 81
提示:
总评成绩 = (期中成绩×百分比1+实验成绩×百分比2+期末成绩×百分比3)/100
;求总评成绩
;作者:KUN.A.A
;date:2022/04/08
.386
.MODEL FLAT
ExitProcess PROTO NEAR32 stdcall, dwExitCode:DWORD
INCLUDE io.h
cr EQU 0dh ; carriage return character
LF EQU 0ah ; linefeed character
.STACK 4096 ; reserve 4096-byte stack
.DATA ; reserve storage for data
count WORD 1,0
Prompt1 BYTE "This program will calculate your final point",cr,Lf,Lf,0
PromptP BYTE cr,Lf,Lf,"Please input percent ",0
PromptG BYTE cr,Lf,Lf,"Please input grade ",0
MaoHao BYTE " : ",0
acount WORD 16 DUP(?),0
sum WORD 16 DUP(?),0
grade WORD 16 DUP(?),0
percent WORD 16 DUP(?),0
result BYTE cr,Lf,Lf,"The score is: ",0
.CODE ; start of main program code
_start:
output Prompt1 ;输出语句1
whileLess3: cmp count,3 ;循环3次
jg endwhile ;大于3退出循环
output PromptG ;输出成绩语句
itoa acount,count ;count转为ASCII输出第几次
output acount ;输出第几科成绩
output MaoHao ;输出冒号
input grade,16 ;输入成绩
atoi grade ;转为整型
mov bx,ax ;成绩放入BX
output PromptP ;输出占比语句
output acount ;输出第几科成绩
output MaoHao ;输出冒号
input percent,16 ;输入占比
atoi percent ;转为整型
imul bx,ax ;百分比X分数
add sum,bx ;加入和
inc count
jmp whileLess3
endwhile:
mov ax,sum ;和放入AX
cwd ;字扩展方便除法
mov bx,100 ;除数放入bx
idiv bx ;SUM/100 AX/BX
itoa percent,ax ;结果放入percent
output result ;输出结果语句
output percent ;结果
INVOKE ExitProcess, 0 ; exit with return code 0
PUBLIC _start ; make entry point public
END ; end of source code