每当我添加代码时,为什么会出现“相对跳出范围”错误

时间:2017-05-23 17:08:44

标签: assembly x86 dos tic-tac-toe

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

代码很长(但重复)所以我只是把它切成重要的部分

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

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

每当我将代码添加到'six:'时,我在140上得到错误,说'相对跳出范围超过0002h字节

.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

这是什么意思? 0002字节是什么意思?我不知道为什么会出现这个错误。我早点解决了,但我不知道怎么做。

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

$host = "localhost";
$user = "user";
$password = "pass";
$database = "test4";
$cxn = mysqli_connect($host,$user,$password,$database) or die ("Connection Error");

$query = "SELECT * FROM sample";
$result = mysqli_query($cxn, $query);
$field_row = mysqli_num_rows($result);
$fields_num = mysqli_num_fields($result);

echo "<h1>Table: $database </h1>";
echo " <table border='1' width='50%'><tr> ";
// printing table headers
for ($i=0; $i<$fields_num; $i++){
$field = mysqli_fetch_field($result);
echo "<td><b>{$field->name}</b></td> ";
}
echo "</tr>\n";
// printing table rows
while ($row = mysqli_fetch_row($result)){
echo "<tr>";
// $row is array... foreach(..)put every element
// of $row to $cell variable
 foreach ($row as $cell){
 echo " <td>$cell</td> ";
}
echo "</tr>\n";
}

1 个答案:

答案 0 :(得分:2)

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

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

如果你正在使用另一个汇编程序google:assembler directives [assembler name] cpu 这应该可以解决您的问题。