跳回1000线 [英] Jumping back 1000 lines
问题描述
我试图让一个code,当你在最后,它会问你,如果你想再试一次。如果preSS'Y',那么它会跳回到1000行,就在节目的开头。
I was trying to make a code, that when you're at the very end, it will ask you if you want to try again. If you press 'y', then it will jump back a 1000 lines, right at the beginning of the program.
很明显嘛,就没有工作了,因为我的错误跳相对越界了。所以我做了跳跃每50行,总共具有20跳,像
Well obviously, it didn't work out, as I got the error "jump relative out of range". So I made jumps every 50 lines, having a total of 20 jumps, like
start:
.
s20: jmp start
.
.
.
s2: jmp s3
.
s1: jmp s2
.
jmp s1
现在这样做之后,我跑的程序,当我pressed'Y',TASM样冻结了。这只是显示最后一个屏幕,与Y的输入,和闪烁_。我不能preSS字符了。
Now after doing that, I ran the program, and when I pressed 'y', TASM kind of froze. It was just displaying the last screen, with the 'y' input, and a blinking _. I couldn't press a character anymore.
感谢。
推荐答案
在x86的你并不需要跳跃的层叠顺序,因为 JMP
可以跳较全分割。就像 JNE
条件跳转有一个有限的范围内。所以,你可以改变一个errorneous条件跳转到一个无条件的近跳转和有条件短跳转的组合:
In x86 you don't need a cascading sequence of jumps, since jmp
can jump over the whole segment. Just a conditional jump like jne
has a limited range. So you can change an errorneous conditional jump to a combination of an unconditional near jump and a conditional short jump:
作为一个例子,改变
.MODEL small
.STACK 1000h
.CODE
main:
top:
mov ax, 1
jmp bottom
ORG 1000h ; A big block between top and bottom
bottom:
cmp ax, 0
je top ; **Error** Relative jump out of range by 0F85h bytes
mov ax, 4C00h ; Return 0
int 21h
END main
到
.MODEL small
.STACK 1000h
.CODE
main:
top:
mov ax, 1
jmp bottom
ORG 1000h ; A big block between top and bottom
bottom:
cmp ax, 0
jne skip ; Short conditional jump
jmp top ; Near unconditional jump
skip:
mov ax, 4C00h ; Return 0
int 21h
END main
TASM能为你做自动的。放置一个跳开头(或者在你需要它)的文件:
TASM can do that automagically for you. Place a "JUMPS" at the beginning (or where you need it) of the file:
JUMPS
.MODEL small
.STACK 1000h
.CODE
main:
top:
mov ax, 1
jmp bottom
ORG 1000h ; A big block between top and bottom
bottom:
cmp ax, 0
je top ; TASM will change this line to a JNE-JMP combination
mov ax, 4C00h ; Return 0
int 21h
END main
80386指令集(ISA)有近条件跳转指令。如果你的模拟器支持80386 ISA(DOSBox中一样),你可以告诉TASM使用它。插入 .386
指令:
.MODEL small
.386 ; Use 80386 instruction set
.STACK 1000h
.CODE
main:
top:
mov ax, 1
jmp bottom
ORG 1000h ; A huge block between top and bottom
bottom:
cmp ax, 0
je top ; Correct jump because of '.386'
mov ax, 4C00h ; Return 0
int 21h
END main
这篇关于跳回1000线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!