sfl-examples/slide-examples/assembly/ex20.asm

39 lines
599 B
NASM
Raw Normal View History

2023-12-14 14:12:51 +01:00
; CFG example
bits 64
SECTION .data
; empty
SECTION .text
add_two_numbers:
push rbp
mov rbp, rsp
mov rax, rdi
add rax, rsi
leave
ret
global _start
_start:
mov rdi, 20 ; first parameter
mov rsi, 30 ; second parameter
test rdi, rdi
js negative
test rsi, rsi
js negative
call add_two_numbers
jmp return
negative:
mov rax, -1
return:
; sys_exit(42)
mov rax,60 ; system call number (sys_exit)
mov rdi,42 ; system call return value
syscall