39 lines
599 B
NASM
39 lines
599 B
NASM
|
; 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
|