Create grid.

This commit is contained in:
Afonso Clerigo Mendes de Sousa 2025-03-19 22:34:07 +00:00
parent 8900a1bac1
commit af6d36281b
2 changed files with 45 additions and 4 deletions

BIN
bin/main

Binary file not shown.

View File

@ -1,19 +1,60 @@
section .data
tile db "[ ]", 0
tile_len equ $ - tile
newline db 0xA, 0
newline_len equ $ - newline
section .bss
board resb 100
section .text
global _main
_main:
xor r10, r10 ; Clear r10 for use as a counter
mov rbx, 10 ; Set divisor to 10
; Lets create a 2D array of 10x10
; 0 = empty
; 1 = bomb
; 2 > number of bombs around
lea r8, [rel tile] ; Buffer address
mov r9, tile_len ; Length of the string
loop_start:
cmp r10, 100
jae loop_end
inc r10 ; Increment the counter
call print_String
mov rax, r10
xor rdx, rdx ; Clear rdx for division
div rbx ; Divide rax by rbx (unsigned division)
cmp r10, 0
je no_newline
cmp rdx, 0
jne no_newline
lea r8, [rel newline] ; Newline character
mov r9, newline_len ; Length of the newline
call print_String
lea r8, [rel tile] ; Buffer address
mov r9, tile_len ; Length of the string
no_newline:
jmp loop_start
loop_end:
mov rax, 0x2000001 ; syscall: exit
xor rdi, rdi ; status: 0
syscall
; Function to print a string
; Arguments:
; r8 - pointer to the string
; r9 - length of the string
print_String:
mov rax, 0x2000004 ; syscall: write
mov rdi, 1 ; file descriptor: stdout
mov rsi, r8 ; pointer to the string
mov rdx, r9 ; length of the string
syscall
ret