1

As per my understanding, MOVZX used for unsigned widening conversions, which convert smaller size (Memory | REG) to bigger size (Memory | REG) with zero-extension. It works fine when I do following conversions:

`movzx <reg16>, <op8>
movzx <reg32>, <op8>
movzx <reg32>, <op16>
movzx <reg64>, <op8>
movzx <reg64>, <op16>`

Note: Second operand can be either be REG or Memory.

But when I'm trying to perform below operation:

movzx <reg64>, <op32>

It fails. Why?

section .data
MSG1    dd 10000

section .text
global _start
_start:
    mov eax, dword[MSG1]
    movzx rbx, eax 
last:
    mov rax, 60
    xor rdi, 0
    syscall

$nasm -f elf64 sample.asm -g -l sample.lst

The error I am getting :

"sample.asm:8: error: invalid combination of opcode and operands"

MankPan
  • 79
  • 6
  • 3
    32 bit operations automatically zero extend to 64 bits so you don't need that form of `movzx`. You can just do `mov ebx, eax`. – Jester Jul 27 '19 at 10:14
  • 1
    Expanding on what @jester said the automatic zero extending (which only occurs in in 64-bit mode) when a destination register is 32-bits (ie eax, ebx, esi etc) also applies when the source and destination are the same. So the instruction `mov eax, eax` may appear to do nothing at first glance in 64-bit code but it too will zero extend the result through the entire 64-bit register RAX. If the upper 32-bits of RAX were non zero before `mov eax, eax` they will be zero after. – Michael Petch Jul 27 '19 at 12:23

0 Answers0