Trying to use Shift-Left instruction for multiplication.
The SHL (shift left) instruction performs a logical left shift on the destination operand, filling the lowest bit with 0.
I don't understand how to use register or memory for N, because when I attempt to do so, I am told "invalid instruction operand"
- The user inputs a number N in the RequestNumber procedure (which returns
EAX). - The calculation I am attempting is: result = 1 * 2^N
My code:
mov ebx, 1
call RequestNumber ; returns eax
shl ebx, eax
mov result, ebx
The assignment I am working on requests to use the Shift to get result = 2^N
As far as I've seen, you can only use imm8 numbers with this register CL (tried using the lower ECX with the same result).
Question: How do I properly use the Shift instruction if I have to get N from the user?


clfor the shift count, and your CPU has the BMI2 instructions, you could useshlx. Larger code size though (5 bytes versus 2). - Nate Eldredge