adventofcode2023/02/main.s

86 lines
1.3 KiB
ArmAsm
Raw Normal View History

2023-12-02 03:17:55 -06:00
%define BUFF_LIM 32768
global _start
[bits 32]
[section .text]
2023-12-02 22:17:42 -06:00
%include "utils.s"
2023-12-02 03:17:55 -06:00
_start:
mov ebx, filename
2023-12-02 22:17:42 -06:00
call open_file
2023-12-02 03:17:55 -06:00
mov ecx, read_buff
mov edx, BUFF_LIM
2023-12-02 22:17:42 -06:00
call read_file
2023-12-02 03:17:55 -06:00
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
2023-12-02 20:41:34 -06:00
; we don't need to save the id
2023-12-02 03:17:55 -06:00
; get another number lol
2023-12-02 20:41:34 -06:00
xor ebx, ebx ; B
xor edi, edi ; G
xor ebp, ebp ; R
2023-12-02 03:17:55 -06:00
.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:
2023-12-02 20:41:34 -06:00
cmp ecx, ebx
cmovg ebx, ecx
2023-12-02 03:17:55 -06:00
jmp .next
.g_chk:
2023-12-02 20:41:34 -06:00
cmp ecx, edi
cmovg edi, ecx
2023-12-02 03:17:55 -06:00
jmp .next
.r_chk:
2023-12-02 20:41:34 -06:00
cmp ecx, ebp
cmovg ebp, ecx
2023-12-02 03:17:55 -06:00
.next:
xor edx, edx ; game over flag
; find one of , ; \n
lodsb
cmp al, ','
je .get_num ; next number
cmp al, ';'
2023-12-02 20:41:34 -06:00
je .get_num ; we don't care about rounds
2023-12-02 03:17:55 -06:00
cmp al, 10 ; \n
je .new_game
cmp esi, dword [file_lim] ; end of file
jge .new_game
jmp .next ; other char
.new_game:
2023-12-02 20:41:34 -06:00
mov eax, ebx ; B
mul edi ; G
mul ebp ; R
2023-12-02 03:17:55 -06:00
.game_done:
2023-12-02 20:41:34 -06:00
; add power to final value
2023-12-02 03:17:55 -06:00
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