From 3e8bcdeb010043ca6f139bed09d9d642b8244da0 Mon Sep 17 00:00:00 2001 From: Kwarde Date: Wed, 25 Jun 2025 14:58:02 +0200 Subject: [PATCH] Get rid of gcc, adds exit() --- constants.asm | 2 ++ core.asm | 7 +++++++ makefile | 2 +- tests.asm | 8 +++++--- 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/constants.asm b/constants.asm index ddf2662..a0f55e5 100644 --- a/constants.asm +++ b/constants.asm @@ -3,6 +3,7 @@ section .rodata global NR_write global NR_open global NR_close + global NR_exit global EOS global NL @@ -12,6 +13,7 @@ section .rodata NR_write equ 1 NR_open equ 2 NR_close equ 3 + NR_exit equ 60 ;ascii EOS equ 0x0 diff --git a/core.asm b/core.asm index aaa9027..e3f482f 100644 --- a/core.asm +++ b/core.asm @@ -1,3 +1,4 @@ +extern NR_exit extern strclr section .text @@ -10,6 +11,7 @@ section .text global tolower global toupper global itoa + global exit ;----- min(int a, int b) -----; ; return value: lowest value @@ -176,3 +178,8 @@ itoa: pop rax leave ret +;----- exit(int exit_code) -----; +; returns: nothing +exit: + mov rax, NR_exit + syscall diff --git a/makefile b/makefile index 4f03c41..e89319f 100644 --- a/makefile +++ b/makefile @@ -1,5 +1,5 @@ tests: tests.o constants.o core.o console.o string.o file.o - gcc tests.o constants.o core.o console.o string.o file.o -o tests -no-pie -z noexecstack + ld tests.o constants.o core.o console.o string.o file.o -o tests -no-pie -z noexecstack tests.o: tests.asm nasm tests.asm -f elf64 -l tests.lst -g -F dwarf constants.o: constants.asm diff --git a/tests.asm b/tests.asm index 1d9b357..74fa95b 100644 --- a/tests.asm +++ b/tests.asm @@ -13,6 +13,7 @@ extern isupper extern tolower extern toupper extern itoa +extern exit ;console.asm extern print extern puts @@ -177,8 +178,8 @@ section .bss strBuff1 resb 32 strBuff2 resb 8 section .text - global main -main: + global _start +_start: push rbp mov rbp, rsp @@ -809,4 +810,5 @@ main: %ENDIF leave - ret + mov rdi, 0 + call exit