跳回1000行

xTa*_*Tan -3 x86 assembly dos tasm x86-16

我试图制作一个代码,当你最后,它会问你是否想再试一次.如果按'y',它将在程序开头直接跳回1000行.

很明显,它没有成功,因为我得到错误"跳跃相对超出范围".所以我每50次跳跃,共有20次跳跃,比如说

start:
.
s20: jmp start
.
.
.
s2: jmp s3
.
s1: jmp s2
.
jmp s1
Run Code Online (Sandbox Code Playgroud)

在这之后,我运行了程序,当我按下"y"时,TASM有点冻结.它只是显示最后一个屏幕,带有'y'输入和一个闪烁的_.我再也不能按下一个角色了.

谢谢.

rkh*_*khb 6

在x86中,您不需要级联跳转序列,因为它jmp可以跳过整个段.只是有条件的跳跃就像jne有限的范围.因此,您可以将错误的条件跳转更改为无条件近似跳转和条件短跳转的组合:

举个例子,改变

.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
Run Code Online (Sandbox Code Playgroud)

.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
Run Code Online (Sandbox Code Playgroud)

TASM可以为您自动完成.在文件的开头(或您需要的地方)放置一个"JUMPS":

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
Run Code Online (Sandbox Code Playgroud)

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
Run Code Online (Sandbox Code Playgroud)

  • @PeterCordes:这是8086的限制。80386体系结构引入了近似条件跳转“ 0F 8x ...”。 (2认同)