2015-09-24 14 views
4

我的女士给了我一个任务,我必须创建一个程序,它将通过键盘输入并检查嵌套括号的传统顺序。 例如:masm错误A2075:跳转目标太远:减30字节

input= {[()]}, output = correct format, input = ({[]}) output = incorrect

我的程序:

.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 destination too far by 30 bytes.

请告诉我,我应该怎么办摆脱这个信息并运行我的程序。

+0

究竟哪个跳转正是汇编程序抱怨的?既然你的目标是80386,我会希望MASM在短暂的跳跃不可能的时候自动使用跳跃。 MASM有一个“OPTION LJMP”来启用跳跃延长,但它应该默认启用。 – Michael

+0

养成在操作码上添加注释的习惯。在六个月内,你不会记得它做了什么/如何继续。 – Seki

回答

6

loop l1导致错误。 LOOP只能执行短跳转(-128到+127字节)。将其替换为

dec cx 
jne l1