Y
Hacker News
new
|
ask
|
show
|
jobs
by
besselheim
3291 days ago
MOV RAX, 1 is seven bytes: 48 C7 C0 01 00 00 00
1 comments
pcwalton
3291 days ago
The parent has a good point actually, because "mov eax,1" automatically zero-extends in 64-bit mode.
It's still one byte longer than the equivalent AArch64 instruction, though.
link
kccqzy
3291 days ago
Fine. If you are really into getting the shortest instruction, try "xorl %eax,%eax" then "incl %eax" which is four bytes (31 c0 ff c0).
link
gsg
3291 days ago
push $1/pop %eax (6a 01 58) is shorter, but perhaps not the best idea.
link
nayuki
3291 days ago
Actually, there is no 32-bit pop instruction in x86-64 mode. Your code won't work.
link
gsg
3290 days ago
You're right: it should be pushq $1/pop %rax (which is also three bytes, although there will be a prefix byte for registers r8 through r15).
link
It's still one byte longer than the equivalent AArch64 instruction, though.