【问题标题】:Assembly x86 error with SHL eax, ecx使用 SHL eax、ecx 组装 x86 错误
【发布时间】:2018-08-25 02:07:20
【问题描述】:

在我的 Assembly x86 类代码中遇到此编译错误问题,

A2070:指令操作数无效

线是

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 不起作用。

【问题讨论】:

  • 不清楚为什么要推送/弹出 eax(并省略 ret?)。这是因为您为了简单而省略了代码吗?如果你删除了 push/pop/ret,就没有太多理由打电话了。只需将 shl 放入循环中即可。

标签: assembly x86 cpu-registers instruction-set operands


【解决方案1】:

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

您需要使用cl 中的低位:

shl eax, cl

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-15
    • 1970-01-01
    • 2016-02-09
    • 2023-03-29
    • 1970-01-01
    • 2017-04-05
    相关资源
    最近更新 更多