SHL eax、ecx 的程序集 x86 错误

标签 assembly x86 cpu-registers instruction-set operands

我在 Assembly x86 类的代码中遇到这个编译错误,

A2070: invalid instruction operands

这条线是

shl eax, ecx

ecx 应该是循环的(减 1)并且此时永远不会大于 5,那么为什么我不能移动值呢?我需要将 eax 中的值乘以 2^n,n 是 ecx 中的值,左移。

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

如果我替换

shl eax, 5

然后就可以了 我只是不知道为什么 ecx 不工作。

最佳答案

移位指令don't accept a 32-bit register as their count operand .

您需要在 cl 中使用低位:

shl eax, cl

关于SHL eax、ecx 的程序集 x86 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49313418/

相关文章:

gcc - 当需要额外的堆栈对齐时,gcc 奇怪的堆栈操作是怎么回事?

assembly - 在除以零的中断处理程序中该怎么做?

x86 - 所有基于 Nehalem 和更高版本的 Xeon 处理器是否都具有集成内存 Controller (IMC)?

x86 - GDB 寄存器与处理器寄存器不同吗?

embedded - 内置 LED 不会打开 STM32F303RE Nucleo 板

c++ - 错误C2420:第一个操作数中的符号无效

assembly - 什么是好的 64 位 NASM 汇编引用?

c++ - 比较 Fortran 和 C++ 汇编程序的 int = floor(sqrt(...))

linux - 编程 NASM,入门指南?

assembly - 为什么我们在汇编中使用 sub esp, 4 而不是 push 一个寄存器?