題目一:成績評級
寫一個完整的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