我正在进行装配项目(使用tasm),我在跳跃时遇到了一个非常奇怪的问题,我得到的错误是: 相对超出范围(NUMBER)字节,从我理解的是当你尝试跳过太多行时,这是(我认为)相关代码:
IDEAL
MODEL small
STACK 100h
proc keyUsagePaint
mov bx,[playerSize]
mov ah,[byte ptr keyHolder]
push [playerX]
pop [tempX]
push [playerY]
pop [tempY]
;Checking the key and jumping accordingly.
keyUsageForPaint:
cmp ah,77
je moveRight
cmp ah,72
je moveUp
cmp ah,75
je moveLeft
cmp ah,80
je moveDown
cmp ah,26
je decBrushSize
cmp ah,27
je incBrushSize
cmp ah,2
je changeColor
cmp ah,3
je changeColor
cmp ah,4
je changeColor
cmp ah,5
je changeColor
cmp ah,6
je changeColor
cmp ah,7
je changeColor
cmp ah,8
je changeColor
cmp ah,9
je changeColor
cmp ah,38
je _loadPicture
cmp ah,1
je goToMenu
jmp jumpEnd
;Moving the brush to the right by increasing the playerX.
moveRight:
add [tempX],bx
cmp [tempX],320
je jumpEnd
add [playerX],bx
jmp jumpEnd
;Moving the brush to the left by decreasing the playerX.
moveLeft:
sub [tempX],bx
cmp [tempX],0
je jumpEnd
sub [playerX],bx
jmp jumpEnd
;Moving the brush to the up by decreasing the playerY.
moveUp:
sub [tempY],bx
cmp [tempY],0
je jumpEnd
sub [playerY],bx
jmp jumpEnd
;Moving the brush to the up by increasing the playerY.
moveDown:
add [tempY],bx
cmp [tempY],200
je jumpEnd
add [playerY],bx
jmp jumpEnd
;Increasing the brush size by increasing playerSize.
incBrushSize:
cmp [playerSize],25
je jumpEnd
inc [playerSize]
jmp jumpEnd
;Decreasing the brush size by decreasing playerSize.
decBrushSize:
cmp [playerSize],1
je jumpEnd
dec [playerSize]
jmp jumpEnd
;Changing the brush color by changing colorHolder.
changeColor:
mov [colorHolder],ah
jmp jumpEnd
;Going back to the menu by changing programMode.
goBackToTheMenu:
mov [programMode],1
jmp jumpEnd
;Loading the picture using loadPicture procedures.
_loadPicture:
push [keyHolder]
call loadPicture
pop [keyHolder]
jmp jumpEnd
goToMenu:
mov [programMode],1
call closeFile
jmp jumpEnd
jumpEnd:
cmp [isLoading],1
je _jumpRet
cmp [keyHolder],38
je _mainProc
cmp [programMode],1
je _mainProc
call writeKeyToFile
_mainProc:
call MainProc
_jumpRet:
ret
endp keyUsagePaint
如果您需要更多详细信息,请告诉我您的需求,谢谢!
答案 0 :(得分:4)
对于80x86,编码的分支目标是来自下一条指令的8位有符号位移,因此目标必须在下一条指令的-128 ... +127字节内。
使用相反的条件来跳过jmp指令,而不是分支到(超出范围)目标。例如(你没有说出哪个分支出现故障):
cmp ah,77
je moveRight ;branch out of range?
cmp ah,72
可以写成
cmp ah,77
jne notRight ;opposite test
jmp moveRight
notRight:
cmp ah,72
对于某些处理器(早期的PIC?),这是唯一的选择,因为测试条件只是跳过一条指令。
编辑:在以后的处理器上有一个长分支可用,但指令MODEL small
表明这不是这种情况。