adventofcode2023/02/main.s
2023-12-02 22:17:42 -06:00

86 lines
1.3 KiB
ArmAsm

%define BUFF_LIM 32768
global _start
[bits 32]
[section .text]
%include "utils.s"
_start:
mov ebx, filename
call open_file
mov ecx, read_buff
mov edx, BUFF_LIM
call read_file
add eax, read_buff
mov [file_lim], eax
mov esi, read_buff
; just try until number lol
.get_id:
call dec_parse
test eax, eax
jz .get_id
; we don't need to save the id
; get another number lol
xor ebx, ebx ; B
xor edi, edi ; G
xor ebp, ebp ; R
.get_num:
call dec_parse
test eax, eax
jz .get_num
mov ecx, eax
; r g b
lodsb
cmp al, 'r'
je .r_chk
cmp al, 'g'
je .g_chk
.b_chk:
cmp ecx, ebx
cmovg ebx, ecx
jmp .next
.g_chk:
cmp ecx, edi
cmovg edi, ecx
jmp .next
.r_chk:
cmp ecx, ebp
cmovg ebp, ecx
.next:
xor edx, edx ; game over flag
; find one of , ; \n
lodsb
cmp al, ','
je .get_num ; next number
cmp al, ';'
je .get_num ; we don't care about rounds
cmp al, 10 ; \n
je .new_game
cmp esi, dword [file_lim] ; end of file
jge .new_game
jmp .next ; other char
.new_game:
mov eax, ebx ; B
mul edi ; G
mul ebp ; R
.game_done:
; add power to final value
add dword [final_value], eax
; checked earlier but... meh
cmp esi, dword [file_lim] ; end of file
jl .get_id ; new game
; we can print final value now
mov eax, [final_value]
call print_dec
jmp exit
[section .data]
file_lim: dd 0
final_value: dd 0
filename: db "input",0
[section .bss]
read_buff: resb BUFF_LIM