From 2005adf25fbf8883486689db591d23941337c4e9 Mon Sep 17 00:00:00 2001 From: Kwarde Date: Tue, 24 Jun 2025 16:34:06 +0200 Subject: [PATCH] Use NL/EOS instead of 10/0, use constants.asm for global constants --- console.asm | 4 +-- constants.asm | 6 +++++ makefile | 6 +++-- tests.asm | 71 +++++++++++++++++++++++++++------------------------ 4 files changed, 49 insertions(+), 38 deletions(-) create mode 100644 constants.asm diff --git a/console.asm b/console.asm index 77a16f1..d508bca 100644 --- a/console.asm +++ b/console.asm @@ -1,7 +1,7 @@ +extern NL + extern strlen -section .rodata - NL db 10 section .text global print global puts diff --git a/constants.asm b/constants.asm new file mode 100644 index 0000000..334b36f --- /dev/null +++ b/constants.asm @@ -0,0 +1,6 @@ +section .rodata + global EOS + global NL + + EOS equ 0x0 + NL equ 0xA diff --git a/makefile b/makefile index 4ad9e74..134be9f 100644 --- a/makefile +++ b/makefile @@ -1,7 +1,9 @@ -tests: tests.o core.o console.o string.o - gcc tests.o core.o console.o string.o -o tests -no-pie -z noexecstack +tests: tests.o constants.o core.o console.o string.o + gcc tests.o constants.o core.o console.o string.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 + nasm constants.asm -f elf64 -l constants.lst -g -F dwarf core.o: core.asm nasm core.asm -f elf64 -l core.lst -g -F dwarf console.o: console.asm diff --git a/tests.asm b/tests.asm index 46a7121..d6e6cb3 100644 --- a/tests.asm +++ b/tests.asm @@ -1,5 +1,8 @@ extern printf +;constants.asm +extern EOS +extern NL ;core.asm extern min extern minu @@ -39,40 +42,40 @@ section .rodata num1 dq 13 num2 dq -25 num3 equ 60 - msgNums db "> num1: %d",10,"> num2: %d",10,"> num3: %d",10,0 - msgMin db "min(num1, num2): %d",10,0 - msgMin2 db "minu(num1, num3): %d",10,0 - msgMin3 db "min(num2, num3): %d",10,0 - msgMax db "max(num1, num2): %d",10,0 - msgMax2 db "maxu(num1, num3): %d",10,0 - msgMax3 db "max(num2, num3): %d",10,0 - msgPrint db "print() test",0 - msgPuts db " and puts() test",0 - str1 db "Hello, world!",0 - str2 db "Hello World!",0 - str3 db "Howdy environment!",0 - msgStrings db "> str1: %s",10,"> str2: %s",10,"> str3: %s",10,0 - msgStrlen db "strlen(str1): %d",10,0 - msgStrlen2 db "strlen(str3): %d",10,0 - msgIslower db "islower(str1[0]): %d",10,0 - msgIslower2 db "islower(str1[1]): %d",10,0 - msgIsupper db "isupper(str1[0]): %d",10,0 - msgIsupper2 db "isupper(str1[1]): %d",10,0 - msgStrcpy db "strcpy(strBuff, str1): %s",10,0 - msgStrlcpy db "strlcpy(strBuff2, str1, -1): (%d): %s",10,0 - msgStrlcpy2 db "strlcpy(strBuff2, str1, 0): (%d): %s",10,0 - msgStrlcpy3 db "strlcpy(strBuff2, str1, 5): (%d): %s",10,0 - msgStrcat db "strcat(strBuff, str3): %s",10,0 - msgStrlen3 db "strlen(strBuff): %d",10,0 - msgTolower db "tolower(str1[0]): %c",10,0 - msgTolower2 db "tolower(str1[1]): %c",10,0 - msgTolower3 db "tolower() for whole strBuff: %s",10,0 - msgToupper db "toupper(str1[0]): %c",10,0 - msgToupper2 db "toupper(str1[1]): %c",10,0 - msgToupper3 db "toupper() for whole strBuff: %s",10,0 - msgStrcmp db "strcmp(str1, str2): %d",10,0 - msgStrings2 db "Comparing...",10,"> str1: %s",10,"> strBuff: %s",10,0 - msgStrcmp2 db "strcmp(str1, strBuff): %d",10,0 + msgNums db "> num1: %d",NL,"> num2: %d",NL,"> num3: %d",NL,EOS + msgMin db "min(num1, num2): %d",NL,EOS + msgMin2 db "minu(num1, num3): %d",NL,EOS + msgMin3 db "min(num2, num3): %d",NL,EOS + msgMax db "max(num1, num2): %d",NL,EOS + msgMax2 db "maxu(num1, num3): %d",NL,EOS + msgMax3 db "max(num2, num3): %d",NL,EOS + msgPrint db "print() test",EOS + msgPuts db " and puts() test",EOS + str1 db "Hello, world!",EOS + str2 db "Hello World!",EOS + str3 db "Howdy environment!",EOS + msgStrings db "> str1: %s",NL,"> str2: %s",NL,"> str3: %s",NL,EOS + msgStrlen db "strlen(str1): %d",NL,EOS + msgStrlen2 db "strlen(str3): %d",NL,EOS + msgIslower db "islower(str1[0]): %d",NL,EOS + msgIslower2 db "islower(str1[1]): %d",NL,EOS + msgIsupper db "isupper(str1[0]): %d",NL,EOS + msgIsupper2 db "isupper(str1[1]): %d",NL,EOS + msgStrcpy db "strcpy(strBuff, str1): %s",NL,EOS + msgStrlcpy db "strlcpy(strBuff2, str1, -1): (%d): %s",NL,EOS + msgStrlcpy2 db "strlcpy(strBuff2, str1, 0): (%d): %s",NL,EOS + msgStrlcpy3 db "strlcpy(strBuff2, str1, 5): (%d): %s",NL,EOS + msgStrcat db "strcat(strBuff, str3): %s",NL,EOS + msgStrlen3 db "strlen(strBuff): %d",NL,EOS + msgTolower db "tolower(str1[0]): %c",NL,EOS + msgTolower2 db "tolower(str1[1]): %c",NL,EOS + msgTolower3 db "tolower() for whole strBuff: %s",NL,EOS + msgToupper db "toupper(str1[0]): %c",NL,EOS + msgToupper2 db "toupper(str1[1]): %c",NL,EOS + msgToupper3 db "toupper() for whole strBuff: %s",NL,EOS + msgStrcmp db "strcmp(str1, str2): %d",NL,EOS + msgStrings2 db "Comparing...",NL,"> str1: %s",NL,"> strBuff: %s",NL,EOS + msgStrcmp2 db "strcmp(str1, strBuff): %d",NL,EOS section .data section .bss strBuff resb 32