RAX Register
RAX is the x86-64 accumulator: return values, syscall numbers, the implicit operand of mul, div and string instructions, and what EAX, AX, AL and AH alias.
RAX is where answers come back. Integer and pointer return values land in it on every mainstream x86-64 ABI, system call numbers go in through it, and a long list of instructions use it without naming it. When you are lost in a function, the value of RAX after each call is the cheapest thing to follow.
Return values
| What is returned | Where it lands |
|---|---|
| Integer or pointer up to 64 bits | rax |
| 128-bit integer, or a small struct of two words | rdx:rax |
float / double | xmm0, not rax |
| Struct too big for registers | caller passes a hidden buffer pointer; the callee returns that pointer in rax |
Narrow types only define the low part. A function returning bool sets al and leaves the upper 56 bits holding whatever was there, which is why callers test al and not rax:
call is_licensed
test al, al
je .unregisteredPatch that branch, or patch the callee to mov al, 1; ret (b0 01 c3), and you have the oldest crack in the book.
Sub-registers and the zero-extension rule
mov rax, 0x1122334455667788
; eax = 0x55667788 low 32 bits
; ax = 0x7788 low 16 bits
; al = 0x88 low 8 bits
; ah = 0x77 bits 8 to 15Writing EAX zeroes the upper 32 bits of RAX. Writing AX, AL or AH leaves the rest untouched. That asymmetry is why compilers emit xor eax, eax (31 c0, two bytes) to clear the full register, and why mov eax, 1 is a complete 64-bit assignment.
Uses nobody spells out
RAX is an implicit operand in more instructions than any other register:
mulandimul(one-operand form) put the product inrdx:rax.divandidivdividerdx:raxand leave the quotient inrax.cdqesign-extendseaxintorax;cqosign-extendsraxintordxahead of a signed divide.lodsloads from[rsi]into it,stosstores it to[rdi],scascompares against it.rep stosbwithal = 0is an inlinedmemset.cmpxchgcompares against it, and writes the current value back into it on failure.cpuidtakes the leaf number ineax;rdtscreturns the timestamp inedx:eax. Both are staples of anti-VM and timing checks.syscalltakes the system call number inraxon Linux and ineaxon Windows (mov r10, rcx; mov eax, 0x55; syscallis the shape of everyntdllstub).
On Linux the kernel also returns through it: a value from -4095 to -1 is a negated errno, anything else is success.
The variadic count
On System V, a call to a variadic function sets al to the number of vector registers used for arguments. That is the reason for the xor eax, eax you see right before printf:
lea rdi, [rip+0xe8a] ; format string
mov esi, ebx
xor eax, eax ; no floating-point arguments
call printfIt is not a return value being cleared, and decompilers that show it as an extra argument are wrong.
Reverse-engineering notes
RAX is caller-saved everywhere. Nothing in it survives a call, so a value read from rax after a call came from that call.
Functions end with xor eax, eax (return 0), mov eax, 1, or or eax, 0xffffffff / mov eax, 0xffffffff (return -1). Reading those three patterns gets you a function's success and failure paths before you understand anything else about it.
Related: RDX, which pairs with it for wide multiply and divide, calling conventions, syscall, and the full register map.