developer #1

Merged
AfonsoCMSousa merged 6 commits from developer into master 2025-03-25 21:28:28 +00:00
2 changed files with 74 additions and 33 deletions
Showing only changes of commit 17b693b71d - Show all commits

BIN
bin/main

Binary file not shown.

View File

@ -1,9 +1,24 @@
section .data section .data
tile db "[ ]", 0 tile db "[ ]", 0
tile_len equ $ - tile tile_len equ $ - tile
tile_emply db "[.]", 0
tile_flag db "[!]", 0
tile_mine db "[X]", 0
tile_near_by1 db "[1]", 0
tile_near_by2 db "[2]", 0
tile_near_by3 db "[3]", 0
tile_near_by4 db "[4]", 0
tile_near_by5 db "[5]", 0
tile_near_by6 db "[6]", 0
tile_near_by7 db "[7]", 0
tile_near_by8 db "[8]", 0
tile_near_by9 db "[9]", 0
newline db 0xA, 0 newline db 0xA, 0
newline_len equ $ - newline newline_len equ $ - newline
section .bss section .bss
board resb 100 board resb 100
@ -11,50 +26,76 @@ section .text
global _main global _main
_main: _main:
xor r10, r10 ; Clear r10 for use as a counter ; Fill the board with 0s and 1s
mov rbx, 10 ; Set divisor to 10 xor r10, r10 ; Counter
lea r11, [rel board] ; Load address of board
lea r8, [rel tile] ; Buffer address mov rcx, 100 ; Loop 100 times
mov r9, tile_len ; Length of the string fill_loop:
rdrand rax
and rax, 1
mov [r11 + r10], al ; Store at board[r10]
inc r10
loop fill_loop
loop_start:
cmp r10, 100
jae loop_end
inc r10 ; Increment the counter ; Print the board
xor r10, r10 ; Reset counter
print_loop:
lea r11, [rel board] ; Load address of board
; Determine which tile to print based on board[r10]
lea r8, [rel tile] ; Default tile
mov r9, tile_len
; Add logic here to select tile based on board[r10] if needed
cmp byte [r11 + r10], 0
je empty_tile
cmp byte [r11 + r10], 1
je mine_tile
; If nothign else, print the tile
jmp no_tile
no_tile:
lea r8, [rel tile]
jmp print_tile
empty_tile:
lea r8, [rel tile_emply]
jmp print_tile
mine_tile:
lea r8, [rel tile_mine]
jmp print_tile
print_tile:
mov r9, tile_len
call print_String call print_String
; Check if newline is needed (every 10th element)
mov rax, r10 mov rax, r10
xor rdx, rdx ; Clear rdx for division xor rdx, rdx
div rbx ; Divide rax by rbx (unsigned division) div rbx
cmp rdx, 9 ; After 0-9, print newline
cmp r10, 0
je no_newline
cmp rdx, 0
jne no_newline jne no_newline
lea r8, [rel newline] ; Newline character lea r8, [rel newline]
mov r9, newline_len ; Length of the newline mov r9, newline_len
call print_String 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 no_newline:
xor rdi, rdi ; status: 0 inc r10
cmp r10, 100
jb print_loop
; Exit
mov rax, 0x2000001
xor rdi, rdi
syscall syscall
; Function to print a string
; Arguments:
; r8 - pointer to the string
; r9 - length of the string
print_String: print_String:
mov rax, 0x2000004 ; syscall: write mov rax, 0x2000004
mov rdi, 1 ; file descriptor: stdout mov rdi, 1
mov rsi, r8 ; pointer to the string mov rsi, r8
mov rdx, r9 ; length of the string mov rdx, r9
syscall syscall
ret ret