任务1-改写菜单程序
读懂并运行菜单程序,然后
(1)用代码的直接定址表改写程序
(2)增加一个功能,菜单显示项为“ 5. DEBUG”
(3)在报告中比较原程序与改写后程序的优劣。
报告内容:
assume cs:code, ss:stack
stack segment
db 100H dup (?)
stack ends
code segment
org 100h
start:
jmp beg
menu db 10,13,10,13,' MENU '
db 10,13
db 10,13,' 1. FILE'
db 10,13,' 2. EDIT'
db 10,13,' 3. COMPILE'
db 10,13,' 4. RUN'
db 10,13,' 0. QUIT'
db 10,13
db 10,13,' please choose one of 0~4:','$'
beg:
push cs
pop ds ;设置数据段
disp0:
lea dx,menu ;DS:DX=待输出字符的地址
mov ah,9
int 21h ;调用21h中断的第9号功能,显示以'$'结束的字符串
mov ah,1
int 21h ;调用21h中断的第1号功能,从键盘读入字符,AL保存读入字符的ASCII码
cmp al,'0'
je exit
cmp al,'1'
je disp1
cmp al,'2'
je disp2
cmp al,'3'
je disp3
cmp al,'4'
je disp4
jmp disp0
disp1:
call sub1
jmp disp0
disp2:
call sub2
jmp disp0
disp3:
call sub3
jmp disp0
disp4:
call sub4
jmp disp0
exit:
mov ah,4ch
int 21h
sub1 proc near
jmp sub1_disp
file db 10,13,' --new, open, save, print files.---','$',10,13
sub1_disp:
lea dx,file
mov ah,9
int 21h ;调用21h中断的第9号功能,显示以'$'结束的字符串
ret
sub1 endp
sub2 proc near
jmp sub2_disp
edit db 10,13,' --copy, cut, paste the text.---','$',10,13
sub2_disp:
lea dx,edit
mov ah,9
int 21h ;调用21h中断的第9号功能,显示以'$'结束的字符串
ret
sub2 endp
sub3 proc near
jmp sub3_disp
compile db 10,13,' --compile the source file, then get target file.---','$',10,13
sub3_disp:
lea dx,compile
mov ah,9
int 21h ;调用21h中断的第9号功能,显示以'$'结束的字符串
ret
sub3 endp
sub4 proc near
jmp sub4_disp
run db 10,13,' --run, run, run, cannot stop.---','$',10,13
sub4_disp:
lea dx,run
mov ah,9
int 21h ;调用21h中断的第9号功能,显示以'$'结束的字符串
ret
sub4 endp
code ends
end start
(1)我改写的程序是(我已经加入了足够的注释):
assume cs:code, ss:stack stack segment db 100H dup (?) stack ends code segment org 100h start: jmp beg menu db 10,13,10,13,' MENU ' db 10,13 db 10,13,' 1. FILE' db 10,13,' 2. EDIT' db 10,13,' 3. COMPILE' db 10,13,' 4. RUN' db 10,13,' 5. DEBUG' db 10,13,' 0. QUIT' db 10,13 db 10,13,' please choose one of 0~4:','$' ;13代表回车,10代表换行 table dw sub1,sub2,sub3,sub4,sub5 ;设置子程序地址表 beg: push cs pop ds ;设置数据段 disp0: lea dx,menu ;DS:DX=待输出字符的地址 mov ah,9 int 21h ;调用21h中断的第9号功能,显示以'$'结束的字符串 mov ah,1 int 21h ;调用21h中断的第1号功能,从键盘读入字符,AL保存读入字符的ASCII码 ;注意!!!保存的是ASCII码!!!需要处理为数字 ;table dw sub1,sub2,sub3,sub4 sub al,48 ;ASCII码减48得到数字 cmp al,0 je exit ;0的时候结束程序 mov bl,al mov bh,0 add bx,bx ;以字存储所以需要二倍 sub bx,2 ;因为是从2开始的第一个需要减2 call word ptr table[bx] ;寻址指令 jmp disp0 ;重新输入 exit: mov ah,4ch int 21h sub1 proc near jmp sub1_disp file db 10,13,' --new, open, save, print files.---','$',10,13 sub1_disp: lea dx,file mov ah,9 int 21h ;调用21h中断的第9号功能,显示以'$'结束的字符串 ret sub1 endp sub2 proc near jmp sub2_disp edit db 10,13,' --copy, cut, paste the text.---','$',10,13 sub2_disp: lea dx,edit mov ah,9 int 21h ;调用21h中断的第9号功能,显示以'$'结束的字符串 ret sub2 endp sub3 proc near jmp sub3_disp compile db 10,13,' --compile the source file, then get target file.---','$',10,13 sub3_disp: lea dx,compile mov ah,9 int 21h ;调用21h中断的第9号功能,显示以'$'结束的字符串 ret sub3 endp sub4 proc near jmp sub4_disp run db 10,13,' --run, run, run, cannot stop.---','$',10,13 sub4_disp: lea dx,run mov ah,9 int 21h ;调用21h中断的第9号功能,显示以'$'结束的字符串 ret sub4 endp sub5 proc near jmp sub5_disp debug db 10,13,' --enter, change, track, run assembly language source directly,---','$',10,13 sub5_disp: lea dx,debug mov ah,9 int 21h ;调用21h中断的第9号功能,显示以'$'结束的字符串 ret sub5 endp code ends end start
任务2-输数字,出字母
输入1-9的数字,以其作为序号,输出对应的字母。例如,输入1,输出a;而输入4,输出d
报告内容:
我的程序是(我已经加入了足够的注释):
assume cs:code code segment alpha db 'abcdefghi' start: mov ah,1 int 21h ;External input. dec al ;Because a corresponds to 1, it is reduced by one. sub al,48 ;Into numbers. mov bl,al mov bh,0 mov ah,02h mov dl,0ah int 21h ;Newline output mov dl,cs:[bx] mov ah,2 int 21h ;Output dl. mov ah,4ch int 21h code ends end start
贺利坚老师汇编实验六
最新推荐文章于 2021-09-16 15:51:40 发布