A hardware register is a small, processor-resident storage location that holds values used during instruction execution. Assembly instructions operate on registers and memory locations rather than directly on C variables. section 13.5
Register and memory operations
In x86_64 assembly, `movq %rsp, %rbp` copies the stack-pointer value into the base-pointer register. Conversely, `movl $0, -16(%rbp)` stores zero in memory 16 bytes below the address held by `%rbp`. The register supplies an address; the instruction performs the memory access. section 13.5
Registers participate in several stages of a compiled function:
- Hold integer values available to the processor. section 13.5
- Carry function values, pointers, temporary results, and arguments during instruction execution. section 13.5
- Vary across assembly dialects because CPU, compiler, and operating-system details influence their names and use. section 13.5
Listing 13.4 An assembler version of the fgoto function
.type fgoto, @function
fgoto:
pushq %rbp # Save base pointer
movq %rsp, %rbp # Load stack pointer
subq $48, %rsp # Adjust stack pointer
movl %edi, -36(%rbp) # fgoto#0 => n
movl $0, -4(%rbp) # init j
movq $0, -16(%rbp) # init p
.L_AGAIN:
cmpq $0, -16(%rbp) # if (p)
je .L_ELSE
movq -16(%rbp), %rax # p ==> rax
movl (%rax), %edx # *p ==> edx
movq -24(%rbp), %rax # ( == q)?
cmpq -16(%rbp), %rax # (p == )?
jne .L_YES
movl $.L_STR_EQ, %eax # Yes
jmp .L_NO
.L_YES:
movl $.L_STR_NE, %eax # No
.L_NO:
movl -4(%rbp), %esi # j ==> printf#1
movl %edx, %ecx # *p ==> printf#3
movq %rax, %rdx # eq/ne ==> printf#2
movl $.L_STR_FRMT, %edi # frmt ==> printf#0
movl $0, %eax # clear eax
call printf
.L_ELSE:
movq -16(%rbp), %rax # p ==|
movq %rax, -24(%rbp) # ==> q
movl -4(%rbp), %eax # j ==|
movl %eax, -28(%rbp) # ==> cmp_lit
leaq -28(%rbp), %rax # &cmp_lit ==|
movq %rax, -16(%rbp) # ==> p
addl $1, -4(%rbp) # ++j
movl -4(%rbp), %eax # if (j
cmpl -36(%rbp), %eax # <= n)
jbe .L_AGAIN # goto AGAIN
leave # Rearange stack
ret # return statement
Inspect the annotated assembler listing to follow values moving between registers, stack memory, and function arguments. section 13.5



