2016-12-09 30 views
-1

我有一個問題,我的循環,它包含的代碼很長,它給了我錯誤jump destination too far : by 3 byte(s)。當刪除:跳轉目的地太遠:通過3個字節

mov edx,offset str1 
call writestring 

這部分低於主PROC,它沒有給出錯誤。但是我需要這個字符串用戶輸入一個負數來給出一條消息。我怎麼能夠?

INCLUDE Irvine32.inc 

.data 

    money  dword 200,100,50,20,10,5,1 
    str1  byte  "Enter the amounts for each value of money : ",0 
    str2  byte  "The sum of your moneys are:",0 
    total  dword 0 
    buffer  dword 1000 dup(0),0  
    str3  byte  "Do not enter neg number ",0 

.code 
main PROC 
    mov edx,offset str1 
    call writestring 
    call crlf 
    mov ecx,lengthof money 
    mov esi,0 
    mov edi,0 

start1: 
    jmp continue 
    don: 
    push ecx 


    mov edx,ecx 
    mov edx,0 

    mov edx,7 
    sub edx,ecx 
    mov ecx,edx 
    mov edi,0 
    mov esi,0 
     start2: 

      mov eax,money[esi] 
      call writedec 
      mov ebx,eax 
      mov al,'x' 
      call writechar 
      mov eax,buffer[edi] 
      call writedec 
      call crlf 
      add esi,4 
      add edi,4 

     loop start2 

    pop ecx 
    continue: 

    ;************************************************** 
    mov edx,0 
    mov eax,money[esi] 
    call writedec 
    mov ebx,eax 
    mov al,'x' 
    call writechar 
    call readint 
    ;*************************************************** 

    sub eax,0 
    js don 
    mov buffer[edi],eax 
    ;************************* 
    mul ebx 
    add total,eax  ;we add each the multiplication to total. 
    add esi,4   ;increases the index by 4.(because of dword type) 
    add edi,4 


loop start1 

    mov edx,offset str2 
    call writestring 
    mov eax, total 
    call writedec 

    exit 
main ENDP 
END main 
+0

該錯誤指的是什麼指令? – duskwuff

+0

mov edx,offset str1 call writestring – zahit

+1

你的代碼是你永遠不應該使用LOOP指令的一個很好的例子。 –

回答

1

loop的範圍有限。從下一條指令開始測量的指令流中,它只能跳到先前的127個字節或128個字節。

爲了解決這個問題,你可以做如下的事情。基於不具備的條件跳轉

label1: 

<lots of code> 

loop tmp1 
jmp tmp2 
tmp1: 
    jmp label1 
tmp2: 

或者使用不同的結構:

而不是

label1: 

<lots of code> 

loop label1 

如果標籤是遙不可及,你可以做這樣的事情範圍限制。

+0

非常感謝。那麼錯誤取決於跳轉指令的類型,例如js?或者我只需要放標籤? – zahit

+0

'js'和其他條件跳轉_used_在早期x86模型上具有相同的限制,但現在永遠有兩種變體,一種是有符號的32位分支範圍。大多數彙編程序只是從助記符中自動選擇正確的跳轉大小。 –

+3

爲什麼不直接顯示'dec ecx/jnz label1'作爲替代方案,而不是使用LOOP和JMP這種可怕的難讀結構?順便說一句,JCC rel32至少早在386被支持,所以你永遠不需要在32位代碼中避免它。 –