adventofcode2023/05/main_part1.s

196 lines
3.2 KiB
ArmAsm
Raw Normal View History

2023-12-05 02:57:57 -06:00
%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
; skip until :
; loop until :
; get next number
; save in seeds@seedcnt
; increment seedcnt
; end
; do 7 times
; loop until :
; get next number
; save in DEST
; get next number
; save in SRC
; get next number
; save in RNG
; for i in 0 to seedcnt
; if seeds_changed@i then continue
; if seeds@i < SRC then continue
; tmp := seeds@i - SRC
; if tmp >= RNG then continue
; seeds@i := tmp + DST
; seeds_changed@i := 1
; end
; end
; seeds_changed@all := 0
; end
; tmp := seeds@0
; for i in 1 to seedcnt
; if seeds@i < tmp then tmp := seedcnt
; end
; output tmp
; skip until :
mov esi, read_buff
skip_to_nums:
lodsb
cmp al, ':'
jne skip_to_nums
; loop until :
; get next number
; save in seeds@seedcnt
; increment seedcnt
; end
inc esi
xor ebx, ebx ; seedcnt
get_seeds:
cmp byte [esi-1], ':'
je .got_seeds
call dec_parse
jc get_seeds
; save number
mov [seeds+ebx*4], eax
inc ebx
jmp get_seeds
.got_seeds:
mov [seedcnt], ebx
inc esi ; don't retrigger : check
; do 7 times
; ...
; end
mov ecx, 7
process_maps:
push ecx
; loop until :
; ...
; end
map_chk:
; get next number
; save in DEST
; get next number
; save in SRC
; get next number
; save in RNG
.get_dest:
cmp byte [esi-1], ':' ; make sure we aren't passing into new map
je .map_done
call dec_parse
jc .get_dest
mov ebx, eax ; dest
.get_src:
call dec_parse
jc .get_src
mov ecx, eax ; src
.get_rng:
call dec_parse
jc .get_rng
mov edx, eax ; rng
; for i in 0 to seedcnt
; if seeds_changed@i then continue
; if seeds@i < SRC then continue
; tmp := seeds@i - SRC
; if tmp >= RNG then continue
; seeds@i := tmp + DST
; seeds_changed@i := 1
; end
xor eax, eax ; i
.check_line:
cmp byte [seeds_changed+eax], 1
je .cont_check_line
cmp [seeds+eax*4], ecx ; src
jb .cont_check_line
mov edi, [seeds+eax*4]
sub edi, ecx ; tmp -= src
cmp edi, edx ; rng
jae .cont_check_line
add edi, ebx ; dest
mov [seeds+eax*4], edi
mov byte [seeds_changed+eax], 1
.cont_check_line:
inc eax
cmp eax, [seedcnt]
jb .check_line
jmp map_chk
.map_done:
; seeds_changed@all := 0
xor eax, eax
mov edi, seeds_changed
mov ecx, [seedcnt]
rep stosb
xor ebx, ebx
.print_dbg:
mov eax, [seeds+ebx*4]
call print_dec
call space
inc ebx
cmp ebx, [seedcnt]
jb .print_dbg
call newline
; process_maps loop
inc esi ; skip ':'
pop ecx
dec ecx
test ecx, ecx
jnz process_maps
; tmp := seeds@0
; for i in 1 to seedcnt
; if tmp > seeds@i then tmp := seedcnt
; end
xor eax, eax ; i
mov ebx, [seeds+eax*4] ; tmp
find_smallest:
inc eax
cmp eax, [seedcnt]
jae .done
cmp ebx, [seeds+eax*4]
cmovae ebx, [seeds+eax*4]
jmp find_smallest
.done:
; output tmp
mov eax, ebx
call print_dec
game_over:
jmp exit
[section .data]
file_lim: dd 0
final_value: dd 0
filename: db "input",0
seedcnt: dd 0
[section .bss]
seeds: resd 64
seeds_changed: resb 64
;seedsoil: resd 64*3
;soilfert: resd 64*3
;fertwater: resd 64*3
;waterlight: resd 64*3
;lighttemp: resd 64*3
;temphumid: resd 64*3
;humidloc: resd 64*3
read_buff: resb BUFF_LIM