NASM-如何将8位寄存器移到完整的32位寄存器中? [英] NASM - How do you move an 8-bit register into a full 32-bit register?

查看:167
本文介绍了NASM-如何将8位寄存器移到完整的32位寄存器中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写NASM汇编代码,并且必须执行一些索引寻址.我已经将索引存储在$ al中,但是x86不允许您使用$ al作为索引寄存器,并且我已经在使用$ bl,因此我不能使用$ bx.因此,我需要将$ al中的字节放入32个但可注册的寄存器中,例如$ ecx,但是,当我尝试时,它会抛出操作码和操作数错误的无效组合.有什么办法吗?

I am writing NASM assembly code, and have to do some indexed addressing. I have the index stored in $al, but x86 won't let you use $al as an index register, and I'm already using $bl, so I cant use $bx. So I need to put the byte I have in $al into a 32-but register such as $ecx, however, when I try, it throws an invalid combination of opcode and operand error. Is there any way to do this?

    sub     al, 97                  ; char - 97

    push    ecx                     ; b/c al cant be used as indexing register
    mov     ecx, al                 ; move byte in al into ecx

    mov     bl, [table + ecx]       ; value_at(first_table_addr + char) -> bx

    pop     ecx

推荐答案

使用 MOVZX指令:

movzx ecx, al  ; move byte to doubleword, zero-extension

如果您希望将al中的值视为带符号,则还有MOVSX.

There's also MOVSX if you want the value in al to be treated as signed.

零扩展表示目标操作数的高位将被设置为零,而符号扩展表示目标操作数的高位将被设置为源操作数的符号.一些例子:

Zero-extention means the upper bits of the destination operand will be set to zero, while sign-extension means the upper bits of the destination operand will be set to the sign bit of the source operand. Some examples:

mov al,0x7F
movzx ebx,al   ; ebx = 0x0000007F
movsx ebx,al   ; ebx = 0x0000007F

mov al,0x80
movzx ebx,al   ; ebx = 0x00000080
movsx ebx,al   ; ebx = 0xFFFFFF80

这篇关于NASM-如何将8位寄存器移到完整的32位寄存器中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆