diff --git a/.gitignore b/.gitignore index d964e87..c9cb564 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ .asm-lsp.toml +build diff --git a/src/main.asm b/src/main.asm index be56ef2..0b326c3 100644 --- a/src/main.asm +++ b/src/main.asm @@ -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: + diff --git a/src/str.asm b/src/str.asm index 90d76c5..902eaeb 100644 --- a/src/str.asm +++ b/src/str.asm @@ -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 +