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