实现各个菜单敲回车时候的跳转
第一篇的时候解释了,代码中敲回车会跳转到exit那里
我们对其进行修改,使其跳到我们自己的子程序中去
修改 scan里面的
cmp al,0dh
je exit
这里,判断是回车的时候跳转至select
scan: mov ah,1
int 16h
jz scan
mov ah,0
int 16h
cmp ah,80
je down
cmp ah,72
je up
cmp al,0dh
je select
jmp scan
select的代码,这里先把nn的值给al,对al进行判断,选中的是第几行
然后分别跳到对应的代码,
再call各自的子程序,子程序执行完ret之后回来,这里为了测试用,直接
mov ah,4ch
int 21h
结束程序
select:
mov al,byte ptr nn
cmp al,1
je first
cmp al,2
je second
cmp al,3
je third
cmp al,4
je fourth
cmp al,5
je exit
first:
call function1
mov ah,4ch
int 21h
second:
call function2
mov ah,4ch
int 21h
third:
call function3
mov ah,4ch
int 21h
fourth:
call function4
mov ah,4ch
int 21h
exit:
mov ah,4ch
int 21h
各自对应的子程序:这里四个全是清屏功能,测试程序有没有正确执行进来
function1 proc
mov ah,0
mov al,3
int 10h
ret
function1 endp
function2 proc
mov ah,0
mov al,3
int 10h
ret
function2 endp
function3 proc
mov ah,0
mov al,3
int 10h
ret
function3 endp
function4 proc
mov ah,0
mov al,3
int 10h
ret
function4 endp
运行一下看看效果,
每个菜单敲完回车变成这样,说明程序正确的执行了
清屏和退出
完整代码如下
stack segment para stack 'stack'
db 256 dup(0)
stack ends
disp macro x,length,color
mov ax,1301h
mov bx,color
mov cx,length
mov dh,yy
mov dl,x
mov bp,addr
int 10h
endm
data segment
l0 db ' MENU '
l1 db '====================='
l2 db '| score-recording ';录入
l3 db '| score-update ';修改
l4 db '| score-sort ';排序
l5 db '| score-output ';输出
l6 db '| RETURN '
l7 db '====================='
LL EQU $-l7
XX equ (80-ll)/2
yy db ?
nn dw 1
tab dw ?,l2,l3,l4,l5,l6
addr dw ?
data ends
code segment
assume cs:code,ds:data,es:data
beg: mov ax,data
mov ds,ax
mov es,ax
mov ax,3
int 10h
mov yy,8
mov addr,offset l0
last2: disp xx,ll,0fh
add addr,ll
inc yy
cmp yy,16
jl last2
mov nn,1
call compute
disp xx+3,ll-6,51h
scan: mov ah,1
int 16h
jz scan
mov ah,0
int 16h
cmp ah,80
je down
cmp ah,72
je up
cmp al,0dh
je select
jmp scan
down: cmp nn,5
je scan
call compute
disp xx+3,ll-6,0fh
inc nn
call compute
disp xx+3,ll-6,51h
jmp scan
up: cmp nn,1
je scan
call compute
disp xx+3,ll-6,0fh
dec nn
call compute
disp xx+3,ll-6,51h
jmp scan
select:
mov al,byte ptr nn
cmp al,1
je first
cmp al,2
je second
cmp al,3
je third
cmp al,4
je fourth
cmp al,5
je exit
first:
call function1
mov ah,4ch
int 21h
second:
call function2
mov ah,4ch
int 21h
third:
call function3
mov ah,4ch
int 21h
fourth:
call function4
mov ah,4ch
int 21h
exit:
mov ah,4ch
int 21h
function1 proc
mov ah,0
mov al,3
int 10h
ret
function1 endp
function2 proc
mov ah,0
mov al,3
int 10h
ret
function2 endp
function3 proc
mov ah,0
mov al,3
int 10h
ret
function3 endp
function4 proc
mov ah,0
mov al,3
int 10h
ret
function4 endp
compute proc near
mov di,nn
add di,di
mov ax,tab[di]
add ax,3
mov addr,ax
mov al,byte ptr nn
add al,9
mov yy,al
ret
compute endp
code ends
end beg