initial commit
This commit is contained in:
commit
4c3ffab97b
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
build
|
31
Makefile
Normal file
31
Makefile
Normal file
@ -0,0 +1,31 @@
|
||||
NASM = nasm
|
||||
LD = ld
|
||||
|
||||
NASM_FLAGS := -felf64
|
||||
LD_FLAGS := --strip-all
|
||||
|
||||
SRC_PATH := src
|
||||
OBJ_PATH := build/obj
|
||||
BIN_PATH := build/bin
|
||||
|
||||
SRC_FILES := $(wildcard $(SRC_PATH)/*.asm)
|
||||
OBJ_FILES := $(patsubst $(SRC_PATH)/%.asm,$(OBJ_PATH)/%.o,$(SRC_FILES))
|
||||
|
||||
all: make-build-dir $(BIN_PATH)/asm-game-of-life
|
||||
|
||||
make-build-dir:
|
||||
mkdir -p $(OBJ_PATH)
|
||||
mkdir -p $(BIN_PATH)
|
||||
|
||||
|
||||
$(BIN_PATH)/asm-game-of-life: $(OBJ_FILES)
|
||||
$(LD) $(LD_FLAGS) $^ -o $@
|
||||
|
||||
|
||||
$(OBJ_PATH)/%.o: $(SRC_PATH)/%.asm
|
||||
$(NASM) $(NASM_FLAGS) $< -o $@
|
||||
|
||||
clean:
|
||||
rm -fr build
|
||||
|
||||
|
115
src/main.asm
Normal file
115
src/main.asm
Normal file
@ -0,0 +1,115 @@
|
||||
SYS_WRITE equ 1
|
||||
SYS_BRK equ 12
|
||||
SYS_EXIT equ 60
|
||||
|
||||
STDOUT equ 1
|
||||
|
||||
ESC_CHAR equ 27
|
||||
ASCII_ZERO equ 48
|
||||
|
||||
section .bss
|
||||
heap_ptr resp 1
|
||||
|
||||
section .data
|
||||
hello: db ESC_CHAR, "[10;15Hhello suckers! :)", 10, 0
|
||||
test: db ESC_CHAR, "[20;25Hmore txt here", 10, 0
|
||||
clear: db ESC_CHAR, "[2J", 0
|
||||
|
||||
section .text
|
||||
global _start
|
||||
|
||||
unsigned_int_to_acii: ; takes value stored in rdi
|
||||
push rdx
|
||||
push r12
|
||||
push r13
|
||||
|
||||
mov r12, rdi
|
||||
|
||||
mov rax,SYS_BRK
|
||||
mov rdi,0
|
||||
syscall
|
||||
mov [heap_ptr], rax
|
||||
|
||||
mov r13, 0
|
||||
mov rax, r12
|
||||
mov rcx, 10
|
||||
.count_loop:
|
||||
inc r13
|
||||
cmp rax, 10
|
||||
jl .loop_exit
|
||||
|
||||
xor rdx, rdx
|
||||
div rcx
|
||||
push rdx
|
||||
jmp .count_loop
|
||||
|
||||
.loop_count_exit:
|
||||
push rax
|
||||
|
||||
mov rdi, [heap_ptr]
|
||||
add rdi, r13
|
||||
inc rdi
|
||||
mov rax, SYS_BRK
|
||||
syscall
|
||||
|
||||
mov rdi [heap_ptr]
|
||||
mov rcx 0
|
||||
.store_loop: ; basicly for loop
|
||||
cmp rcx, rdi
|
||||
jnl .loop_store_exit
|
||||
|
||||
pop rax
|
||||
add rax, ASCII_ZERO
|
||||
|
||||
mov rdx rdi
|
||||
add rdx rcx
|
||||
mov byte rdx, rax
|
||||
|
||||
inc rcx
|
||||
jmp .store_loop
|
||||
|
||||
.loop_store_exit
|
||||
add rdi rcx
|
||||
mov byte rdi, 0
|
||||
|
||||
|
||||
|
||||
|
||||
print_str: ; takes pointer to string in rdi and retuns in rax
|
||||
push rsi
|
||||
push rdx
|
||||
mov rsi, rdi
|
||||
|
||||
mov rdx, 0
|
||||
.count_loop:
|
||||
cmp byte [rsi+rdx], 0
|
||||
je .print
|
||||
inc rdx
|
||||
jmp .count_loop
|
||||
|
||||
.print:
|
||||
mov rax,SYS_WRITE
|
||||
mov rdi,STDOUT
|
||||
syscall
|
||||
|
||||
pop rdx
|
||||
pop rsi
|
||||
ret
|
||||
|
||||
print_at_pos:
|
||||
|
||||
|
||||
|
||||
_start:
|
||||
mov rdi,clear
|
||||
call print_str
|
||||
|
||||
mov rdi,hello
|
||||
call print_str
|
||||
|
||||
mov rdi,test
|
||||
call print_str
|
||||
|
||||
mov rax,SYS_EXIT
|
||||
mov rdi,0; return code
|
||||
syscall
|
Loading…
x
Reference in New Issue
Block a user