Collin Hurst
Collin Hurst

Reputation: 63

Assembly x86 error with SHL eax, ecx

Im having trouble with this compile error in my code for an Assembly x86 class,

A2070: invalid instruction operands

the line is

shl eax, ecx

ecx should be looping (decreasing by 1) and never be greater than 5 at this moment, so why can't I shift the value? I need to multiply the value in eax by 2^n, n being the value in ecx, with shift left.

createArray PROC   
;saving 5 multiples of the value currently in eax into an array addres that 
is ;on the stack
    push ecx       
    push eax
    push esi
    push ebp
    mov ebp, esp
    mov ecx, 5
    mov esi, [ebp+24] ;address of array
    L1:
        call multiply   ;call multiply with two numbers eax, ecx
        pop eax
        mov [esi],eax
        add esi, 4

    Loop L1
....cont
createArray endp

multiply PROC
    shl eax, ecx ; this line right here
    push eax
multiply endp

if I substitute

shl eax, 5

then it works I just don't know why ecx doesn't work.

Upvotes: 2

Views: 1197

Answers (1)

Simon Whitehead
Simon Whitehead

Reputation: 65049

The shift instructions don't accept a 32-bit register as their count operand.

You'll want to use the lower bits in cl:

shl eax, cl

Upvotes: 7

Related Questions