2010-05-11 127 views
3

請看下面的程序,錯誤是無效的有效地址計算,我已經提到,線,請告訴我,爲什麼它的無效的有效地址計算 這裏是程序
無效的有效地址計算

[org 0x100] 
jmp start 


array1: dw 10,15,20,25,30,35,40,45,50,55 
array2: dw 15,10,20,35,40,30,55,50,25,45 

start: mov bx,0 
    mov cx,0 
loop: mov ax,[array2+bx] 
     cmp ax,[array1+cx]//here is the error invalid effective address calculation 
     jne NextElementOfArray1 


NextElementOfArray2: add bx,2 
         cmp bx,20  
      je end 
         mov cx,0 
      jmp loop 


NextElementOfArray1: add cx,2   
         cmp cx,20  
      je NextElementOfArray2 
      jmp loop 
end: mov ax,0x4c00 
    int 0x21 
+0

cx分配在哪裏?你分配了ax和dx。 cx的價值是什麼? – Shaihi 2010-05-11 08:43:08

+0

我已經進行了更正,請現在檢查 – 2010-05-11 08:49:32

回答

9
start: mov bx,0 
     mov dx,0 ; <-- did you mean "mov cx, 0" ? 
loop: mov ax,[array2+bx] 
     cmp ax,[array1+cx] 

編輯:如果我沒記錯,cx寄存器不能用作索引。

Table 2-1. 16-Bit Addressing Forms with the ModR/M Byte

Effective Address Mod R/M Value of ModR/M Byte (in Hexadecimal) 

[BX+SI] 
[BX+DI] 
[BP+SI] 
[BP+DI] 
[SI] 
[DI] 
[BX] 
[BX+SI]+disp8 
[BX+DI]+disp8 
[BP+SI]+disp8 
[BP+DI]+disp8 
[SI]+disp8 
[DI]+disp8 
[BP]+disp8 
[BX]+disp8 
[BX+SI]+disp16 
[BX+DI]+disp16 
[BP+SI]+disp16 
[BP+DI]+disp16 
[SI]+disp16 
[DI]+disp16 
[BP]+disp16 
[BX]+disp16 
+0

ya ya我的意思是mov cx,0 – 2010-05-11 08:45:47

+0

我應該在這裏使用哪個註冊表 – 2010-05-11 08:53:02

+0

@Zia,我發佈了英特爾手冊中的有效索引列表。不要忘記下載並檢查出來。 – 2010-05-11 09:05:59

0

更容易記住以下公式(爲TASM)地址規範:

[BX|BP]+[SI|DI]+constant 

凡|表示OR(意味着BX和BP不能在相同的地址規範中)。常數可以是變量或數字常量。