created some basic string helper functions

This commit is contained in:
PoliEcho 2025-07-07 13:42:53 +02:00
parent aa86683b35
commit c1a55fa3ff
3 changed files with 57 additions and 0 deletions

1
.gitignore vendored
View File

@ -1 +1,2 @@
.asm-lsp.toml
build

View File

@ -1,3 +1,19 @@
SYS_EXIT equ 60
SYS_IOCTL equ 16
STDOUT equ 1
TIOCGWINSZ equ 0x5413
section .bss
str_buf: resb 4
section .data
section .text
global _start
extern print_str
extern unsigned_int_to_ascii
_start:

View File

@ -1,7 +1,10 @@
SYS_WRITE equ 1
STDOUT equ 1
ASCII_ZERO equ 48
section .text
global print_str
print_str: ; takes pointer to string in rdi and retuns in rax
push rsi
push rdx
@ -22,3 +25,40 @@ print_str: ; takes pointer to string in rdi and retuns in rax
pop rsi
ret
global unsigned_int_to_ascii
unsigned_int_to_ascii: ; takes pointer to array in rdi and value stored in rsi DOES NOT BOUNDS CHECK
mov r11, 0
mov rcx, 10
mov rax, rsi
.count_loop:
inc r11
cmp rax, 10
jl .loop_count_exit
xor rdx, rdx
div rcx
push rdx
jmp .count_loop
.loop_count_exit:
push rax
mov rcx, 0
.store_loop: ; basicly for loop
cmp rcx, r11
jnl .loop_store_exit
pop rax
add rax, ASCII_ZERO
mov byte [rdi + rcx], al
inc rcx
jmp .store_loop
.loop_store_exit:
mov rax, r11
ret