Assembly 为什么我会得到';相对跳转超出范围';每当我添加代码时出错

Assembly 为什么我会得到';相对跳转超出范围';每当我添加代码时出错,assembly,x86,dos,tic-tac-toe,Assembly,X86,Dos,Tic Tac Toe,这个问题我已经解决了好几次了,但我仍然不知道我是如何解决的。这是我第三次遇到这个特殊的错误,我无法修复它 代码很长(但重复性很强),所以我将把它剪切到重要部分 这是我更改并获得错误的部分 call putx fou: cmp al,'4' jE fou1 jNE fiv fou1: mov ah, 02 ;mov ch, 8 mov dh, 8 ;mov cl, 30 mov dl, 30 int 10h call

这个问题我已经解决了好几次了,但我仍然不知道我是如何解决的。这是我第三次遇到这个特殊的错误,我无法修复它

代码很长(但重复性很强),所以我将把它剪切到重要部分

这是我更改并获得错误的部分

call putx

fou:
  cmp al,'4'
  jE  fou1
  jNE fiv

  fou1:

    mov ah, 02
    ;mov ch, 8
    mov dh, 8
    ;mov cl, 30
    mov dl, 30
    int 10h

    call putx

    fiv:
      cmp al,'5'
      jE  fiv1
      jNE six

      fiv1:
         mov ah, 02
         mov dh, 8
         mov dl, 34
         int 10h

         call putx

         six:
           mov ah,'3'
每当我将代码添加到“six:”时,我都会在140上得到一个错误,即“相对跳转超出范围0002h字节”

Stosb                   ;Else no put the byte in the buffer
cmp bl,32h
Je pl1
Jne wla
  pl1:
    mov ah,09
    lea dx,p1
Stosb                   ;Else no put the byte in the buffer
cmp bl,32h
Je pl1
Jne wla ;this is line 140
  pl1:
    mov ah,09
    lea dx,p1
这是什么意思?0002字节是什么意思?我不知道为什么会出现这个错误。我早就解决了,但我不知道怎么解决

这里是完整的代码,如果需要的话。请容忍我,它很长(我不知道错误可能在哪里,所以我将把它作为一个整体)


相对跳转使用一个字节作为偏移量,因此它只能向前跳转127字节,向后跳转128字节。
如果您想向前或向后跳转更多字节,则需要指定一个支持该功能的CPU,而原来的8086不支持

如果在文件顶部使用MASM put
.386
,这将启用8086之后引入的特定扩展名。其中一个扩展是16位相对跳转偏移量,足以满足您的需要

如果您正在使用另一个汇编器,请使用google:
汇编器指令[assembler name]cpu


这将解决您的问题

相对跳转使用一个字节作为偏移量,因此它只能向前跳转127字节,向后跳转128字节。
如果您想向前或向后跳转更多字节,则需要指定一个支持该功能的CPU,而原来的8086不支持

如果在文件顶部使用MASM put
.386
,这将启用8086之后引入的特定扩展名。其中一个扩展是16位相对跳转偏移量,足以满足您的需要

如果您正在使用另一个汇编器,请使用google:
汇编器指令[assembler name]cpu


这将解决您的问题

您忘记告诉您的汇编器您有一个支持16位跳转的cpu,并且您的代码超过了默认的8位距离。指定cpu或重写代码,使其不需要长时间的条件跳转。通常的技巧是反转条件并使用更长的无条件
jmp
。事实上,您的代码已经为此进行了设置,在
je
之后的
jne
可能只是
jmp
…我不认为这是那种问题。谢谢你的回答。如何指定cpu?如果我不能用更短的条件重写代码,请在指令编码处单击OK,相对跳转将在编码中有一个pc相对偏移量。每个编码只有这么多位,有些只能达到127字节,如果你要求它前进129,那么你比它前进了2字节…可能有不止一种编码,但你需要知道你的特定汇编程序需要什么来获得其他编码(如果这是问题)删除添加的行,汇编然后反汇编,检查编码(如果成功,但在页边空白处),这应该会告诉你发生了什么…它会变得更有趣,因为如果你将该指令延长,可能是你有另一个接近pc的指令,你现在推过了限制…你没有指定汇编程序,看起来像是
masm
。尝试将
.386
放在文件的顶部。您忘记告诉汇编程序您有一个支持16位跳转的cpu,并且您的代码超过了默认的8位距离。指定cpu或重写代码,使其不需要长时间的条件跳转。通常的技巧是反转条件并使用更长的无条件
jmp
。事实上,您的代码已经为此进行了设置,在
je
之后的
jne
可能只是
jmp
…我不认为这是那种问题。谢谢你的回答。如何指定cpu?如果我不能用更短的条件重写代码,请在指令编码处单击OK,相对跳转将在编码中有一个pc相对偏移量。每个编码只有这么多位,有些只能达到127字节,如果你要求它前进129,那么你比它前进了2字节…可能有不止一种编码,但你需要知道你的特定汇编程序需要什么来获得其他编码(如果这是问题)删除添加的行,汇编然后反汇编,检查编码(如果成功,但在页边空白处),这应该会告诉你发生了什么…它会变得更有趣,因为如果你将该指令延长,可能是你有另一个接近pc的指令,你现在推过了限制…你没有指定汇编程序,看起来像是
masm
。请尝试将
.386
放在文件顶部。谢谢。这帮了大忙,谢谢。这帮了大忙
.model small
.code
org 100h

start:


start: jmp main
lin db "|===|===|===|$"
r1 db "| 1 | 2 | 3 |$"
r2 db "| 4 | 5 | 6 |$"
r3 db"| 7 | 8 | 9 |$"
spa db 0ah,0dh,24h

p1 db"Player 1's Turn (X) : $"
p2 db"Player 2's Turn (O) : $"


main:

;start of the crap
mov ah, 02
mov ch, 5
mov dh, 5
mov cl, 28
mov dl, 28
int 10h

call line
call down
call row1

mov ah,09
lea dx,r1
int 21h

call down
;le end



;start of the crap
mov ah, 02
mov ch, 7
mov dh, 7
mov cl, 28
mov dl, 28
int 10h

call line
call down
call row2

mov ah,09
lea dx,r2
int 21h

call down
;le end




;start of the crap
mov ah, 02
mov ch, 9
mov dh, 9
mov cl, 28
mov dl, 28
int 10h

call line
call down
call row3

mov ah,09
lea dx,r3
int 21h

call down
;le end

mov ah, 02
mov ch, 11
mov dh, 11
mov cl, 28
mov dl, 28
int 10h

call line
call down





;input goes here
mov ah, 02
mov ch, 20
mov dh, 20
mov cl, 10
mov dl, 10
int 10h

mov ah,09
lea dx,p1
int 21h

mov ah,02
mov dl,al
int 21h

call down



;mov cx,2 
;again:
          CLD                     ;Incrementing direction
  mov bl,30h
  Get_another_byte:

    add bl,1h
    call down
    mov ah,02
    mov dl,bl
    int 21h                ;show the bl

    Mov AH, 7               ;Ms.Dos code to get one char
    Int 21h                 ;Ms.Dos does that for us and puts it in AL

    Cmp AL, 20h             ;Did he hit the return key ?
    Je  exi          ;Yes, now we can go on

    Stosb                   ;Else no put the byte in the buffer
    cmp bl,32h
    Je pl1
    Jne wla
      pl1:
        mov ah,09
        lea dx,p1
        int 21h

        mov ah,02
        mov dl,al
        int 21h

          ;code ni player 1

cmp al,'1'
jE  one
jNE two

one:

mov ah, 02
mov ch, 6
mov dh, 6
mov cl, 30
mov dl, 30
int 10h


call putx

two:

  cmp al,'2'
  jE  two1
  jNE thr

  two1:

  mov ah, 02
  mov ch, 6
  mov dh, 6
  mov cl, 34
  mov dl, 34
  int 10h

  call putx


  thr:

    cmp al,'3'
    jE  thr1
    jNE fou

    thr1:

    mov ah, 02
    mov ch, 6
    mov dh, 6
    mov cl, 38
    mov dl, 38
    int 10h

    call putx

    fou:
      cmp al,'4'
      jE  fou1
      jNE fiv

      fou1:

        mov ah, 02
        ;mov ch, 8
        mov dh, 8
        ;mov cl, 30
        mov dl, 30
        int 10h

        call putx

        fiv:
          cmp al,'5'
          jE  fiv1
          jNE six

          fiv1:
             mov ah, 02
             mov dh, 8
             mov dl, 34
             int 10h

             call putx

             six:
               mov ah,'3'


  taps:
    mov bl,30h
    jmp Get_another_byte

  exi:
    jmp exit
          ;end of code player1

        ;mov bl,30h
        sub bl, 2h   ;babalik niya yung 32 sa 1 (32-2 = 31)
        call down
        Jmp Get_another_byte
    wla:
        mov ah,09
        lea dx,p2
        int 21h

        mov ah,02
        mov dl,al
        int 21h

        ;mov bl,30h
        call down
        Jmp Get_another_byte    ;He's not done, so keep on

;loop again


row1 proc
  mov ah, 02
  mov ch, 6
  mov dh, 6
  mov cl, 28
  mov dl, 28
  int 10h
  ret
row1 endp


row2 proc
  mov ah, 02
  mov ch, 8
  mov dh, 8
  mov cl, 28
  mov dl, 28
  int 10h
  ret
row2 endp


row3 proc
  mov ah, 02
  mov ch, 10
  mov dh, 10
  mov cl, 28
  mov dl, 28
  int 10h
  ret
row3 endp




line proc
  mov ah, 09
  lea dx, lin
  int 21h
  ret
line endp

down proc
  mov ah, 09
  lea dx, spa
  int 21h
  ret
down endp



putx proc
  mov ah,02
  mov dl,"X"
  int 21h
  ret
putx endp


  exit:

int 20h
end start