created some basic string helper functions
This commit is contained in:
parent
aa86683b35
commit
c1a55fa3ff
1
.gitignore
vendored
1
.gitignore
vendored
@ -1 +1,2 @@
|
|||||||
.asm-lsp.toml
|
.asm-lsp.toml
|
||||||
|
build
|
||||||
|
16
src/main.asm
16
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
|
section .text
|
||||||
global _start
|
global _start
|
||||||
|
extern print_str
|
||||||
|
extern unsigned_int_to_ascii
|
||||||
|
|
||||||
|
_start:
|
||||||
|
|
||||||
|
40
src/str.asm
40
src/str.asm
@ -1,7 +1,10 @@
|
|||||||
SYS_WRITE equ 1
|
SYS_WRITE equ 1
|
||||||
STDOUT 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
|
print_str: ; takes pointer to string in rdi and retuns in rax
|
||||||
push rsi
|
push rsi
|
||||||
push rdx
|
push rdx
|
||||||
@ -22,3 +25,40 @@ print_str: ; takes pointer to string in rdi and retuns in rax
|
|||||||
pop rsi
|
pop rsi
|
||||||
ret
|
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
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user