global _start [bits 32] [section .text] %include "utils.s" _start: mov esi, file ; goto end of move string skip_move: lodsb cmp al, 'L' jge skip_move ; put pairs in memory xor ebp, ebp ; state ; s0: IDX s1: L s2: R ; get the next thing get_next_id: cmp esi, file.over ; input over jae got_ids lodsb cmp al, 'A' jl get_next_id cmp al, 'Z' jg get_next_id ; we have first char sub al, 'A' movzx ebx, al ; id lodsb ; id += next * 26 sub al, 'A' movzx eax, al mov ecx, 26 mul ecx add ebx, eax lodsb ; id += next * 26^2 sub al, 'A' movzx eax, al mov ecx, 26*26 mul ecx add ebx, eax ; case based on state cmp ebp, 0 je .idx cmp ebp, 1 je .left ; right mov [pairs+edi*8+4], ebx ; right xor ebp, ebp ; reset state jmp get_next_id .left: mov [pairs+edi*8], ebx ; left inc ebp ; progress state jmp get_next_id .idx: mov edi, ebx ; curr_id inc ebp ; progress state jmp get_next_id got_ids: mov esi, file mov ebx, 0 ; curr idx ; walk move string find_move_end: lodsb cmp al, 'L' je .left cmp al, 'R' je .right mov esi, file jmp find_move_end .right: mov ebx, [pairs+ebx*8+4] ; right jmp check_ZZZ .left: mov ebx, [pairs+ebx*8] ; left check_ZZZ: inc dword [final_value] cmp ebx, 17575 ; ZZZ jne find_move_end got_ZZZ: game_over: mov eax, [final_value] call print_dec jmp exit [section .data] final_value: dd 0 file_lim: dd file.over - file file: incbin "input" .over: [section .bss] pairs: resd 100000 ; idk we only need a few 10,000