adventofcode2023/14/main_part1.s

75 lines
1.1 KiB
ArmAsm
Raw Normal View History

2023-12-14 14:11:15 -06:00
global _start
[bits 32]
[section .text]
%include "utils.s"
_start:
mov esi, file
xor ebp, ebp ; line num
; for chars in line
do_line:
xor ebx, ebx ; col num
jmp .loop
.cont:
inc ebx ; col num
.loop:
lodsb
cmp al, 10 ; \n
je line_done
cmp al, '#'
je .cube_rock
cmp al, 'O'
je .round_rock
; else .
jmp .cont
.cube_rock:
; move the next spot to after this
lea eax, [ebp+1]
mov [col_next_spot+ebx], al
jmp .cont
.round_rock:
; add to next spot line load
movzx eax, byte [col_next_spot+ebx]
inc byte [line_load_cnt+eax]
; increment next spot
inc byte [col_next_spot+ebx]
jmp .cont
line_done:
inc ebp ; line num
cmp esi, file.over
jb do_line
lea ecx, [ebp-1]
output_loads:
mov ebx, ebp
sub ebx, ecx
mov eax, ebx
call print_dec
call space
movzx eax, byte [ecx+line_load_cnt-1]
call print_dec
call space
mul ebx
call print_dec
call newline
add [final_value], eax
loop output_loads
game_over:
mov eax, [final_value]
call print_dec
call newline
jmp exit
[section .data]
line_len: dd 0
final_value: dd 0
file: incbin "input"
.over:
[section .bss]
col_next_spot: resb 128
line_load_cnt: resb 128