读懂并运行菜单程序,然后
(1)用代码的直接定址表改写原始程序
(2)增加一个功能,菜单显示项为“ 5. DEBUG”
附:原始程序如下
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
用直接定址表改写后的程序(并增加功能5)如下所示:
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 ' ; 10和13分别是回车换行符的ASCII值
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' ;新添加debug功能
db 10,13,' 0. QUIT'
db 10,13
db 10,13,' please choose one of 0~5:','$'
codetab dw sub1, sub2, sub3, sub4, sub5 ;直接定址表
beg:
push cs
pop ds ;设置数据段
disp0:
lea dx,menu ;
mov ah,9
int 21h ;调用21h中断的第9号功能,显示以'$'结束的字符串
mov ah,0
int 16h ;调用16号中断的第0号功能,从外设读取字符信息
sub al, 30h ;使输入字符的ASCII变为数字
cmp al, 0 ;输入的数字和0作比较
je exit ;相等则跳到exit
mov bl, al ;将al中的数字放到bl中
mov bh, 0 ;bx中放al的信息
add bx, bx
sub bx, 2
call word ptr codetab[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
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
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
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
ret
sub4 endp
sub5 proc near
nop
ret
sub5 endp
code ends
end start