Lesson 12 of 15
Call & Return
Functions with CALL and RET
Functions in assembly are created with call and ret:
call my_function ; push return address, jump to my_function
; ... execution continues here after ret ...
my_function:
; function body
ret ; pop return address, jump back to caller
How It Works
call labelpushes the address of the next instruction onto the stack, then jumps tolabelretpops the return address from the stack and jumps to it
A Simple Function
; Function that prints a character stored in rbx
print_char:
push rbx
mov rax, 1
mov rdi, 1
mov rsi, rsp
mov rdx, 1
syscall
add rsp, 8
ret
Your Task
Write a print_newline function and a print_digit function:
print_digit: takes a digit (0-9) inrbx, converts to ASCII, and prints itprint_newline: prints a newline character
Use these functions to print "3\n7\n"
x86_64 runtime loading...
Loading...
Click "Run" to execute your code.