6

I have following code:

sub rsp, 40                 ; 00000028H
lea rcx, OFFSET FLAT:$SG4237
call    printf
xor eax, eax
add rsp, 40                 ; 00000028H
ret 0

Why there is xor eax, eax , instead of xor rax, rax?

J. Doe
  • 95
  • 1
  • 5

1 Answers1

12

In x64, any operation on a 32-bit register clears the top 32 bits of the corresponding 64-bit register too, so there's no need to use xor rax, rax which would necessitate an extra REX byte for encoding.

Igor Skochinsky
  • 36,553
  • 7
  • 65
  • 115