跳回1000行

问题描述 投票:-3回答:1

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

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

start:
.
s20: jmp start
.
.
.
s2: jmp s3
.
s1: jmp s2
.
jmp s1

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

assembly x86 dos x86-16 tasm
1个回答
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

.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可以为您自动完成。在文件的开头(或您需要的地方)放置一个“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

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
© www.soinside.com 2019 - 2024. All rights reserved.