Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.5k views
in Technique[技术] by (71.8m points)

assembly - invalid effective address calculation

Please look at the following program, the error is invalid effective address calculation and i have mentioned that line please tell me why its invalid effective address calculation here is the program

[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
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
start:  mov bx,0
        mov dx,0 ; <-- did you mean "mov cx, 0" ?
loop:   mov ax,[array2+bx]
        cmp ax,[array1+cx]

Edit: If I recall correctly, cx register can not be used as an index.

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...