
If you specify one operand, it multiplies that by %rax, and splits the product across 2 registers. It puts the high-order 64 bits in %rdx and the low-order 64 bits in %rax.
By convention, %rax is used to store a function’s return value, if it exists and is no more than 64 bits long. (Larger return types like structs are returned using the stack.)
Do a cltq instruction (with no operands) to sign-extend it to all of rax. cltq stands for “convert long to quad” – a “longword”is 32 bits, a quadword” is 64.
Decomposing the %rax Register All of the x86’s 64-bit registers have 32-bit, 16-bit and 8-bit accessible internal structure. It varies slightly among the different registers. Example, only …
Registers summary 16 general-purpose 64-bit pointer/long-integer registers, many with stupid names: rax, rbx, rcx, rdx, rsi, rdi, rbp, rsp, r8, r9, r10, r11, r12, r13, r14, r15 sometimes used as …
Jump for control flow Jump immediately follows comparison/test. Together, they make a decision: "if %rax= %rcx, jump to label." label: cmpq %rax,%rcx je label ... ... Executed only if ... %rax≠ …
- [PDF]
Slide 1
Converted to ASM by compiler: leaq (%rdi,%rdi,2), %rax # t = x+x*2 salq $2, %rax # return t<<2