It work, It fucking works i can convert number to string

This commit is contained in:
PoliEcho 2025-03-17 08:24:27 +01:00
parent 4c3ffab97b
commit 50541c4666

View File

@ -1,14 +1,13 @@
SYS_WRITE equ 1 SYS_WRITE equ 1
SYS_BRK equ 12 SYS_BRK equ 12
SYS_EXIT equ 60 SYS_EXIT equ 60
STDOUT equ 1 STDOUT equ 1
ESC_CHAR equ 27 ESC_CHAR equ 27
ASCII_ZERO equ 48 ASCII_ZERO equ 48
section .bss section .bss
heap_ptr resp 1 heap_ptr resq 1 ; Changed 'resp' to 'resq'
section .data section .data
hello: db ESC_CHAR, "[10;15Hhello suckers! :)", 10, 0 hello: db ESC_CHAR, "[10;15Hhello suckers! :)", 10, 0
@ -19,25 +18,17 @@ section .text
global _start global _start
unsigned_int_to_acii: ; takes value stored in rdi unsigned_int_to_acii: ; takes value stored in rdi
push rdx
push r12 push r12
push r13 push r13
mov r12, rdi mov r12, rdi
mov rax,SYS_BRK
mov rdi,0
syscall
mov [heap_ptr], rax
mov r13, 0 mov r13, 0
mov rax, r12 mov rax, r12
mov rcx, 10 mov rcx, 10
.count_loop: .count_loop:
inc r13 inc r13
cmp rax, 10 cmp rax, 10
jl .loop_exit jl .loop_count_exit
xor rdx, rdx xor rdx, rdx
div rcx div rcx
push rdx push rdx
@ -45,42 +36,47 @@ section .text
.loop_count_exit: .loop_count_exit:
push rax push rax
mov rdi, [heap_ptr] mov rdi, [heap_ptr]
add rdi, r13 add rdi, r13
inc rdi inc rdi
mov rax, SYS_BRK mov rax, SYS_BRK
syscall syscall
mov rdi [heap_ptr] mov r14, rdi
mov rcx 0 mov rdi, [heap_ptr]
mov [heap_ptr], r14
mov rcx, 0
.store_loop: ; basicly for loop .store_loop: ; basicly for loop
cmp rcx, rdi cmp rcx, r13
jnl .loop_store_exit jnl .loop_store_exit
pop rax pop rax
add rax, ASCII_ZERO add rax, ASCII_ZERO
mov rdx, rdi
mov rdx rdi add rdx, rcx
add rdx rcx mov byte [rdx], al
mov byte rdx, rax
inc rcx inc rcx
jmp .store_loop jmp .store_loop
.loop_store_exit .loop_store_exit:
add rdi rcx
mov byte rdi, 0
mov rax, rdi
add rdi, rcx
mov byte [rdi], 0
mov rdx, rcx
pop r13
pop r12
ret; return pointer to string in rax and lenght in rdx
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
mov rsi, rdi mov rsi, rdi
mov rdx, 0 mov rdx, 0
.count_loop: .count_loop:
cmp byte [rsi+rdx], 0 cmp byte [rsi+rdx], 0
je .print je .print
@ -91,25 +87,32 @@ section .text
mov rax, SYS_WRITE mov rax, SYS_WRITE
mov rdi, STDOUT mov rdi, STDOUT
syscall syscall
pop rdx pop rdx
pop rsi pop rsi
ret ret
print_at_pos: print_at_pos: ; This function appears to be incomplete
_start: _start:
mov rdi, clear mov rdi, clear
call print_str call print_str
mov rdi, hello mov rdi, hello
call print_str call print_str
mov rdi, test mov rdi, test
call print_str call print_str
mov rax, SYS_BRK
mov rdi, 0
syscall
mov [heap_ptr], rax
mov rdi, 6969
call unsigned_int_to_acii
mov rdi, rax
call print_str
mov rax, SYS_EXIT mov rax, SYS_EXIT
mov rdi, 0 ; return code mov rdi, 0 ; return code
syscall syscall