题目一:成绩评级
写一个完整的8086汇编语言程序,该程序从键盘输入一个成绩,判断其属于哪个等级,等级分别为’A’ (80-100),’B’(60-80),’C’(0-59),并显示结果在屏幕上。
源码:
如果运行报错或死机,尝试把中文注释删除(分号“;”后面的为注释)
;Program:成绩评级
;Author:Nonoas
;Date:20191023
.386
.MODEL FLAT
ExitProcess PROTO NEAR32 stdcall, dwExitCode:DWORD
INCLUDE io.h ; header file for input/output
cr EQU 0dh ; carriage return character
Lf EQU 0ah ; line feed
.STACK 4096 ; reserve 4096-byte stack
.DATA ; reserve storage for data
prompt1 byte "Enter a source:",0
prompt2 byte cr,lf,"The result is:",0
number DWORD ?
str1 byte 40 dup (?)
result DWORD ?
.CODE ; start of main program code
_start:
output prompt1
input str1,40
atod str1
mov number,eax
cmp eax,59
jle endc
cmp eax,80
jle endb
cmp eax,100
jle enda
endc:
mov ebx,"C"
jmp endall
endb: mov ebx,"B"
jmp endall
enda: mov ebx,"A"
jmp endall
endall:
mov result,ebx
output prompt2
output result
INVOKE ExitProcess, 0 ; exit with return code 0
PUBLIC _start ; make entry point public
END ; end of source code
题目二:1~N的平方
写出一段完整的80*86程序,实现输入一个正整数值N后,用两栏格式显示从1到N和它们的平方。如:从键盘输入5,则显示如下内容
数字 | 平方 |
---|---|
1 | 1 |
2 | 4 |
3 | 9 |
4 | 16 |
5 | 25 |
源码:
;Program:
;Author:
;Date:
.386
.MODEL FLAT
ExitProcess PROTO NEAR32 stdcall, dwExitCode:DWORD
INCLUDE io.h ; header file for input/output
cr EQU 0dh ; carriage return character
Lf EQU 0ah ; line feed
.STACK 4096 ; reserve 4096-byte stack
.DATA ; reserve storage for data
prompt byte "Enter a data:",0
sign byte " num num^2",cr,lf,0
space byte " ",0
nextline byte cr,lf,0
number DWORD ?
num1 DWORD ?
num2 DWORD ?
count DWORD 1
num3 byte 10 dup (?)
string byte 40 dup (?)
.CODE ; start of main program code
_start:
output prompt
input string,40
atod string
mov number,eax
output sign
cmp eax,count
jle endall
again:
mov ecx,count
mov ebx,count
imul ebx,count
dtoa num1,ecx
output num1
dtoa num2,ebx
output num2
output nextline
add ecx,1
mov count,ecx
cmp ecx,number
jle again
endall:
INVOKE ExitProcess, 0 ; exit with return code 0
PUBLIC _start ; make entry point public
END ; end of source code