Compare commits

..

No commits in common. "51ffd98872345add465ca205ced6d2a00a24af66" and "aa86683b3538c550c5c4be167c0eee4c77c0b7ec" have entirely different histories.

6 changed files with 6 additions and 141 deletions

2
.gitignore vendored
View File

@ -1,3 +1 @@
.asm-lsp.toml
build
src/*.o

View File

@ -1,38 +1,28 @@
NASM = nasm
LD = ld
NASM_FLAGS := -felf64 -Isrc
NASM_FLAGS := -felf64
LD_FLAGS := --strip-all
DEBUG_LD_FLAGS := -g
DEBUG_NASM_FLAGS := -g -F dwarf
SRC_PATH := src
OBJ_PATH := build/obj
BIN_PATH := build/bin
BIN_NAME := asm-game-of-life
SRC_FILES := $(wildcard $(SRC_PATH)/*.asm)
OBJ_FILES := $(patsubst $(SRC_PATH)/%.asm,$(OBJ_PATH)/%.o,$(SRC_FILES))
all: $(BIN_PATH)/$(BIN_NAME) | make-build-dir
debug: NASM_FLAGS += $(DEBUG_NASM_FLAGS)
debug: LD_FLAGS = $(DEBUG_LD_FLAGS)
debug: $(BIN_PATH)/$(BIN_NAME) | make-build-dir
all: make-build-dir $(BIN_PATH)/asm-game-of-life
make-build-dir:
mkdir -p $(OBJ_PATH)
mkdir -p $(BIN_PATH)
$(BIN_PATH)/$(BIN_NAME): $(OBJ_FILES) | make-build-dir
$(BIN_PATH)/asm-game-of-life: $(OBJ_FILES)
$(LD) $(LD_FLAGS) $^ -o $@
$(OBJ_PATH)/%.o: $(SRC_PATH)/%.asm | make-build-dir
$(OBJ_PATH)/%.o: $(SRC_PATH)/%.asm
$(NASM) $(NASM_FLAGS) $< -o $@
clean:

View File

@ -1,23 +0,0 @@
%include "symbols.asm"
section .bss
brk_pointer: RESQ 1
section .text
global init_alloc
init_alloc:; initialize allocator, optionaly return brk pointer in rax
mov rax, SYS_BRK
mov rdi, 0
syscall
mov [brk_pointer], rax
ret
global alloc
alloc:; Takes lenght of data in rdi and returns pointer in rax
mov rax, SYS_BRK
mov rcx, [brk_pointer]
push rcx
syscall; size already in rdi
mov [brk_pointer], rax
pop rax
ret

View File

@ -1,56 +1,3 @@
%include "symbols.asm"
section .bss
multipurpuse_buf: RESB 8
term_rows: RESW 1
term_cols: RESW 1
section .data
section .text
extern print_str
extern unsigned_int_to_ascii
extern init_alloc
extern alloc
global _start
_start:
; get terminal dimensions
mov rax, SYS_IOCTL
mov rdi, STDOUT
mov rsi, TIOCGWINSZ
lea rdx, [multipurpuse_buf]
syscall
mov word ax, [multipurpuse_buf]; rows are stored at offset 0
mov [term_rows], ax
mov word ax, [multipurpuse_buf+2]; cols are stored at offset 2
mov [term_cols], ax
; handle args
pop rcx; get argc (number of arguments)
cmp rcx, 1
jle .no_arguments_provided
; TODO hanndle arguments
.no_arguments_provided:
call init_alloc
mov ax, [term_rows]
dec ax; one less than terminal size for statusbar
mov cx, [term_cols]
mul rcx
mov rdi, rax
call alloc
mov r15, rax; stores pointer to gameboard array
mov rax, SYS_EXIT
mov rdi, 0 ; return code
syscall

View File

@ -1,8 +1,7 @@
%include "symbols.asm"
SYS_WRITE equ 1
STDOUT equ 1
section .text
global print_str
print_str: ; takes pointer to string in rdi and retuns in rax
push rsi
push rdx
@ -23,40 +22,3 @@ 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

View File

@ -1,9 +0,0 @@
SYS_EXIT equ 60
SYS_IOCTL equ 16
SYS_WRITE equ 1
SYS_BRK equ 12
STDOUT equ 1
TIOCGWINSZ equ 0x5413
ASCII_ZERO equ 48