2

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.

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
Collin Hurst
  • 63
  • 10
  • 1
    It's not clear why you push/pop eax (and omit the ret?). Is this because you have omitted code for simplicity? And if you remove the push/pop/ret, there isn't much reason to do a call. Just put the shl into the loop. – David Wohlferd Mar 16 '18 at 07:44

1 Answers1

7

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
Simon Whitehead
  • 63,300
  • 9
  • 114
  • 138