NASM - How do you move an 8-bit register into a full 32-bit register?

前端 未结 1 2083
忘掉有多难
忘掉有多难 2020-12-07 03:59

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 alread

相关标签:
1条回答
  • 2020-12-07 04:36

    Use the MOVZX instruction:

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

    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
    
    0 讨论(0)
提交回复
热议问题