由于操作码和操作数无效组合,因此无法向右移动

use*_*317 2 x86 assembly nasm

section .data
shiftrightvalue db 4                     ; initialize shiftrightvalue to 4

section .bss

section .text
    global _start
    _start:
        mov ebx, 1111_1111b             ; copy 255 into ebx
        shr ebx, [shiftrightvalue]      ; shift the number in ebx 4 bits to the right to return the number 15 with the exit system call. ebx serves as the exit return value

    mov eax, 1                          ; specify linux system exit call
    int 80h                             ; execute the sys_call
Run Code Online (Sandbox Code Playgroud)

但是,如果我要组装,则会出现以下错误:

error: invalid combination of opcode and operands
Run Code Online (Sandbox Code Playgroud)

它指的是shr ebx [shiftrightvalue]行。如果我删除方括号,它的工作原理,尽管在我看来这也不是真正的“好”代码,因为如果删除方括号,则会收到以下消息:

relocation truncated to fit: R_386_8 against `.data'
Run Code Online (Sandbox Code Playgroud)

但是,如果我执行“ echo $?” 我得到15。我在这里做错什么或这里发生了什么?我只想将值右移4位,据我所知,我需要使用方括号[]来获取shiftrightvalue的值4,因为否则我只会得到shiftrightvalue的地址,而这不是我所需要的想。

Mic*_*ael 5

该指令SHR r32, m8不存在。如果要移位可变量,则需要使用CL寄存器,如下所示:

mov cl,[shiftrightvalue]
shr ebx,cl
Run Code Online (Sandbox Code Playgroud)

  • _“不知道在哪里看” _。[this](http://www.intel.com/content/www/us/en/processors/architectures-software-developer-manuals.html)是规范参考(第2卷是您最感兴趣的参考)在)。 (3认同)