Compare commits

..

No commits in common. "ca5b7af9b653e209e1fdcf1fbb538eca90c65249" and "4c3ffab97bd4884b902dcc845415bc32c16b93c6" have entirely different histories.

2 changed files with 74 additions and 91 deletions

2
.gitignore vendored
View File

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

View File

@ -1,132 +1,115 @@
SYS_WRITE equ 1
SYS_BRK equ 12
SYS_EXIT equ 60
SYS_WRITE equ 1 STDOUT equ 1
SYS_BRK equ 12
SYS_EXIT equ 60 ESC_CHAR equ 27
STDOUT equ 1 ASCII_ZERO equ 48
ESC_CHAR equ 27
ASCII_ZERO equ 48
section .bss section .bss
heap_ptr resq 1 ; Changed 'resp' to 'resq' heap_ptr resp 1
section .data section .data
hello: db ESC_CHAR, "[10;15Hhello suckers! :)", 10, 0 hello: db ESC_CHAR, "[10;15Hhello suckers! :)", 10, 0
test: db ESC_CHAR, "[20;25Hmore txt here", 10, 0 test: db ESC_CHAR, "[20;25Hmore txt here", 10, 0
to_s: db ESC_CHAR, "[", 0
tt_s: db ";25Htest here", 10, 0
clear: db ESC_CHAR, "[2J", 0 clear: db ESC_CHAR, "[2J", 0
section .text 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:
inc r13
cmp rax, 10
jl .loop_exit
.count_loop: xor rdx, rdx
inc r13 div rcx
cmp rax, 10 push rdx
jl .loop_count_exit jmp .count_loop
xor rdx, rdx
div rcx
push rdx
jmp .count_loop
.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 rcx 0
.store_loop: ; basicly for loop
cmp rcx, rdi
jnl .loop_store_exit
mov r14, rdi pop rax
mov rdi, [heap_ptr] add rax, ASCII_ZERO
mov [heap_ptr], r14
mov rcx, 0 mov rdx rdi
add rdx rcx
mov byte rdx, rax
inc rcx
jmp .store_loop
.store_loop: ; basicly for loop .loop_store_exit
cmp rcx, r13 add rdi rcx
jnl .loop_store_exit mov byte rdi, 0
pop rax
add rax, ASCII_ZERO
mov rdx, rdi
add rdx, rcx
mov byte [rdx], al
inc rcx
jmp .store_loop
.loop_store_exit: print_str: ; takes pointer to string in rdi and retuns in rax
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
push rsi push rsi
push rdx push rdx
mov rsi, rdi mov rsi, rdi
mov rdx, 0 mov rdx, 0
.count_loop:
cmp byte [rsi+rdx], 0
je .print
inc rdx
jmp .count_loop
.count_loop: .print:
cmp byte [rsi+rdx], 0 mov rax,SYS_WRITE
je .print mov rdi,STDOUT
inc rdx syscall
jmp .count_loop
pop rdx
pop rsi
ret
.print: print_at_pos:
mov rax, SYS_WRITE
mov rdi, STDOUT
syscall
pop rdx
pop rsi
ret
print_at_pos: ; This function appears to be incomplete
_start:
mov rdi, clear
call print_str
mov rdi, hello
call print_str
mov rdi, test
call print_str
mov rax, SYS_BRK
mov rdi, 0
syscall
mov [heap_ptr], rax
mov rdi, to_s
call print_str
mov rdi, 30
call unsigned_int_to_acii
mov rdi, rax _start:
mov rdi,clear
call print_str
mov rdi,hello
call print_str call print_str
mov rdi, tt_s mov rdi,test
call print_str call print_str
mov rdi, 7888 mov rax,SYS_EXIT
call unsigned_int_to_acii mov rdi,0; return code
mov rdi, rax
call print_str
mov rax, SYS_EXIT
mov rdi, 0 ; return code
syscall syscall