Code
assembly
; sum3(a, b, c) -> a + b + c
; Args: rdi=a, rsi=b, rdx=c ; result in rax
section .text
global sum3
sum3:
mov rax, rdi
add rax, rsi
add rax, rdx
ret
; A non-leaf function that calls printf — must save rbx (callee-saved)
extern printf
fmt: db "n=%d", 10, 0
global show_n
show_n:
push rbx ; save callee-saved reg we will use
mov rbx, rdi ; keep arg across the printf call
sub rsp, 8 ; align rsp to 16 before 'call'
mov rdi, fmt
mov esi, ebx
xor eax, eax ; 0 vector args (variadic ABI)
call printf
add rsp, 8 ; restore rsp
mov rax, rbx ; return n
pop rbx ; restore rbx
ret