我的女士给我布置了一个作业,其中我必须编写一个程序,该程序将通过键盘获取输入并检查嵌套括号的常规顺序。
例如:
input= {[()]},output= 正确的格式,input= ({[]})output= 不正确
我的程序:
.model small
.stack 100h
.386
.data
msg1 db "this is a correct format of nested brackets$"
msg2 db "this is no a correct format of nested brakets$"
.code
main proc
mov ax,@data
mov ds,ax
mov cx,15
push '#'
l1:
mov ah,1
int 21h
cmp al,'['
je pushh1
cmp al,'{'
je pushh2
cmp al,'('
je pushh3
cmp al,']'
je pop1
cmp al,'}'
je pop2
cmp al,')'
je pop3
jmp ser
pushh1:
pop dx
cmp dx,'('
push dx
je wrongorder
movzx dx,al
push dx
jmp ser
pushh2:
pop dx
cmp dx,'['
je wrongorder
cmp dx,'('
je wrongorder
push dx
movzx dx,al
push dx
jmp ser
pushh3:
pop dx
cmp dx,'{'
push dx
je wrongorder
movzx dx,al
push dx
jmp ser
wrongorder:
mov dx,'*'
push dx
jmp ser
pop1:
pop dx
cmp dx,'#'
push dx
je ser
pop dx
cmp dx,'{'
push dx
je ser
pop dx
cmp dx,'('
push dx
je ser
pop dx
jmp ser
pop2:
pop dx
cmp dx,'#'
push dx
je ser
pop dx
cmp dx,'('
push dx
je ser
pop dx
cmp dx,'['
push dx
je ser
pop dx
jmp ser
pop3:
pop dx
cmp dx,'#'
push dx
je ser
pop dx
cmp dx,'{'
push dx
je ser
pop dx
cmp dx,'['
push dx
je ser
pop dx
ser:
cmp al,'q'
je labo
loop l1
labo:
mov ah,2
mov dl,0ah
int 21h
mov dl,0dh
int 21h
mov ah,2h
pop dx
;int 21h
cmp dx,'#'
je labe
cmp dx,'#'
jnz labr
labe:
mov dx, offset msg1
mov ah,9h
int 21h
jmp lab8
labr:
mov dx, offset msg2
mov ah,9h
int 21h
lab8:
mov ah,4ch
int 21h
main endp
end main
但是当我编译这段代码时,masm 显示了一个错误:
jmp 目标距离太远 30 个字节。
请告诉我应该怎么做才能消除此消息并运行我的程序。