如何缩短我的代码以满足命令跳转长度

问题描述 投票:0回答:1

我有这段代码正在尝试运行,但它告诉我跳跃太大了。 一开始它说“相对跳转超出范围0015h字节”,代码是这样的:

restart:
    mov ax, 0b800h
    mov es, ax
    
    mov bx, offset dir
    mov [bx], di
    mov di, 3
    mov bx, offset st_am
    mov [bx], di
    
    push offset preFrame
    push offset menu
    push offset Instructions
    push offset nowPause
    call screens
    
    call black
    
    mov di, offset app
    push di ;Give to apple apple location
    call apple
    
    mov di, offset SPL
    push di ;Give to starterSnake initial snake location
    call starterSnake
    
;Give to up/down/left/right SPL, apple & amount
    mov di, offset dir
    push di
    mov di, offset color
    push di
    mov di, offset st_am
    push di
    mov di, offset app
    push di
    mov di, offset SPL
    push di
    
wasd:
    mov ah, 1h
    int 16h
    jnz newDir ;Check if there's something in the buffer, if not continue
    
    call delay
   
    cmp [dir], 'q'
    jz exit
    cmp [dir], 'a'
    jz a
    cmp [dir], 's'
    jz s
    cmp [dir], 'd'
    jz d
    cmp [dir], 'w'
    jz w
    cmp [dir], 'r'
    jz restart

当我将其更改为:

;Give to up/down/left/right SPL, apple & amount
    push offset dir
    push offset color
    push offset st_am
    push offset app
    push offset SPL

并删除了“相对跳转超出范围 0033h 字节”的行 这是一个更大的范围,没有任何意义。有人可以帮助我吗?

*跳转来自“jz restart”!!

assembly tasm dosbox
1个回答
0
投票

感谢@500 - 内部服务器错误! 我将代码更改为:

cmp [dir], 'r'
    jnz skip
    jmp restart
skip:

jmp
范围更大。

© www.soinside.com 2019 - 2024. All rights reserved.