rename die to panic, add exit function

This commit is contained in:
janis 2025-10-16 19:16:12 +02:00
parent 7bc428caf3
commit 7b413d540c
Signed by: janis
SSH key fingerprint: SHA256:bB1qbbqmDXZNT0KKD5c2Dfjg53JGhj7B3CFcLIzSqq8

View file

@ -4,8 +4,8 @@
section .data section .data
hello_msg db "Hello, World!", 10 hello_msg db "Hello, World!", 10
hello_msg_len equ $ - hello_msg hello_msg_len equ $ - hello_msg
die_msg db "panic occured!", 10 panic_msg db "panic occured!", 10
die_msg_len equ $ - die_msg panic_msg_len equ $ - panic_msg
file_error_msg db "Could not open file: " file_error_msg db "Could not open file: "
file_error_msg_len equ $ - file_error_msg file_error_msg_len equ $ - file_error_msg
error_msg db "Error: " error_msg db "Error: "
@ -32,22 +32,27 @@ _start:
call fopen_read call fopen_read
mov rax, 42 mov rax, 42
; exit with success ; exit with success
mov rdi, 0 ; status: mov rdx, 0
mov rax, 60 ; syscall: exit call exit
syscall
.no_filename: .no_filename:
call die call panic
die: panic:
mov rdx, die_msg mov rdx, panic_msg
mov rcx, die_msg_len mov rcx, panic_msg_len
call eprint_str call eprint_str
; exit with error code 1 ; exit with error code 1
mov rax, 60 ; syscall: exit mov rax, 60 ; syscall: exit
mov rdi, 1 ; status: 1 mov rdi, 1 ; status: 1
syscall syscall
ret ; should never reach here
;; abort the program
;; rdx: status code
exit:
mov rax, 60 ; syscall: exit
mov rdi, rdx
syscall
;; ============================== ;; ==============================
;; Helper functions ;; Helper functions