Lesson 13 of 15

Function Arguments

The System V AMD64 Calling Convention

On Linux x86_64, the standard calling convention passes function arguments in registers:

ArgumentRegister
1strdi
2ndrsi
3rdrdx
4thrcx
5thr8
6thr9
Return valuerax

Stack Frame

Functions that call other functions should set up a stack frame:

my_function:
	push rbp           ; save old base pointer
	mov rbp, rsp       ; set up new frame
	; ... function body ...
	pop rbp            ; restore base pointer
	ret

Callee-Saved Registers

The callee must preserve: rbx, rbp, r12-r15. All other registers may be clobbered.

Your Task

Write a function add_three that:

  • Takes three arguments in rdi, rsi, rdx
  • Returns their sum in rax

Call it with (2, 3, 4) and print the result (9), then call it with (1, 5, 1) and print the result (7).

Print: "9\n7\n"

x86_64 runtime loading...
Loading...
Click "Run" to execute your code.