adventofcode2023/13/main_part1.s
2023-12-13 04:17:13 -06:00

146 lines
1.9 KiB
ArmAsm

global _start
[bits 32]
[section .text]
%include "utils.s"
_start:
mov dword [start], file
jmp do_line_cont
do_line:
; line len
mov esi, edi ; start
mov ecx, 1024
mov al, 10 ; \n
repne scasb
mov eax, edi
sub eax, esi
mov [line_len], eax
mov [start], esi
jmp vert_loop
do_line_cont:
; get next input
mov al, '!'
mov ecx, 1024
mov edi, [start]
repne scasb
mov ecx, 1024
repe scasb
cmp byte [edi-1], '@'
je game_over
.skip_newline:
cmp byte [edi], 10
jne do_line
inc edi
jmp .skip_newline
vert_loop:
mov ebp, [line_len]
mov edx, 1 ; col num
mov esi, [start] ; first col
.check_cols:
cmp byte [esi+1], 10 ; \n
je .done
lea edi, [esi+1]
push esi
jmp .check_rows
.cont:
pop esi
inc esi
inc edx
jmp .check_cols
.potential_mirror:
inc edi
dec esi
cmp byte [edi], 10
je .mirror
cmp byte [esi], 10
je .mirror
; esi left col edi right col
.check_rows:
xor eax, eax ; row 0
.check_rows_l:
mov bl, [esi+eax]
mov bh, [edi+eax]
cmp bl, '!'
je .potential_mirror
cmp bh, bl
jne .cont
add eax, ebp
jmp .check_rows_l
.mirror:
mov eax, edx
call print_dec
call newline
add [final_value], eax
add esp, 4
jmp do_line_cont
.done:
horz_loop:
mov ebp, [line_len]
mov edx, 1 ; col num
mov esi, [start] ; first row
.check_rows:
cmp byte [esi+ebp], '!'
je .done
lea edi, [esi+ebp]
push esi
jmp .check_cols
.cont:
pop esi
add esi, ebp
inc edx
jmp .check_rows
.potential_mirror:
add edi, ebp
sub esi, ebp
cmp byte [edi], '!'
je .mirror
cmp byte [esi], '!'
je .mirror
; esi up row edi down row
.check_cols:
xor eax, eax ; row 0
.check_cols_l:
mov bl, [esi+eax]
mov bh, [edi+eax]
cmp bl, 10
je .potential_mirror
cmp bh, bl
jne .cont
inc eax
jmp .check_cols_l
.mirror:
mov eax, edx
call space
call print_dec
call newline
mov ebx, 100
mul ebx
add [final_value], eax
add esp, 4
.done:
jmp do_line_cont
game_over:
call newline
call newline
mov eax, [final_value]
call print_dec
call newline
jmp exit
[section .data]
final_value: dd 0
start: dd 0
line_len: dd 0
file: incbin "input"
.over:
[section .bss]