209 lines
3.1 KiB
ArmAsm
209 lines
3.1 KiB
ArmAsm
|
global _start
|
||
|
[bits 32]
|
||
|
[section .text]
|
||
|
|
||
|
%include "utils.s"
|
||
|
|
||
|
_start:
|
||
|
|
||
|
; find line length
|
||
|
mov edi, file
|
||
|
mov ecx, file_lim - file
|
||
|
mov al, 10 ; \n
|
||
|
repne scasb
|
||
|
mov eax, edi
|
||
|
sub eax, file
|
||
|
mov [line_len], eax
|
||
|
|
||
|
call print_dec
|
||
|
call newline
|
||
|
|
||
|
; find S
|
||
|
mov edi, file
|
||
|
mov ecx, file_lim - file
|
||
|
mov al, 'S' ; \n
|
||
|
repne scasb
|
||
|
mov eax, edi
|
||
|
sub eax, file
|
||
|
dec eax
|
||
|
mov [s_idx], eax
|
||
|
mov ebx, [line_len]
|
||
|
div ebx
|
||
|
mov [s_line], eax
|
||
|
call print_dec
|
||
|
call space
|
||
|
mov [s_col], edx
|
||
|
mov eax, edx
|
||
|
call print_dec
|
||
|
call newline
|
||
|
|
||
|
; walk the loop
|
||
|
mov esi, file
|
||
|
add esi, [s_idx]
|
||
|
mov edx, esi ; last loc
|
||
|
mov ebx, [line_len]
|
||
|
; downs
|
||
|
lea edi, [esi+ebx]
|
||
|
cmp byte [edi], '|'
|
||
|
je walking_loop
|
||
|
cmp byte [edi], 'J'
|
||
|
je walking_loop
|
||
|
cmp byte [edi], 'L'
|
||
|
je walking_loop
|
||
|
; ups
|
||
|
neg ebx
|
||
|
lea edi, [esi+ebx]
|
||
|
cmp byte [edi], '|'
|
||
|
je walking_loop
|
||
|
cmp byte [edi], 'F'
|
||
|
je walking_loop
|
||
|
cmp byte [edi], '7'
|
||
|
je walking_loop
|
||
|
; lefts
|
||
|
lea edi, [esi-1]
|
||
|
cmp byte [edi], '-'
|
||
|
je walking_loop
|
||
|
cmp byte [edi], 'L'
|
||
|
je walking_loop
|
||
|
cmp byte [edi], 'F'
|
||
|
je walking_loop
|
||
|
; rights
|
||
|
lea edi, [esi+1]
|
||
|
cmp byte [edi], '-'
|
||
|
je walking_loop
|
||
|
cmp byte [edi], 'J'
|
||
|
je walking_loop
|
||
|
cmp byte [edi], '7'
|
||
|
je walking_loop
|
||
|
jmp fucked_up
|
||
|
|
||
|
; | - 7 J L F
|
||
|
walking_loop:
|
||
|
pushad
|
||
|
xor edx, edx
|
||
|
mov eax, edi
|
||
|
sub eax, file
|
||
|
mov ebx, [line_len]
|
||
|
div ebx
|
||
|
call print_dec
|
||
|
call space
|
||
|
mov eax, edx
|
||
|
call print_dec
|
||
|
call newline
|
||
|
popad
|
||
|
inc dword [final_value]
|
||
|
cmp byte [edi], 'S'
|
||
|
je done_walking
|
||
|
c_pipe:
|
||
|
cmp byte [edi], '|'
|
||
|
jne c_hyphen
|
||
|
mov eax, edi
|
||
|
add eax, [line_len]
|
||
|
cmp eax, edx ; last loc
|
||
|
je .other_dir
|
||
|
mov edx, edi ; last loc = loc
|
||
|
mov edi, eax
|
||
|
jmp walking_loop
|
||
|
.other_dir:
|
||
|
mov edx, edi ; last loc = loc
|
||
|
sub edi, [line_len]
|
||
|
jmp walking_loop
|
||
|
c_hyphen:
|
||
|
cmp byte [edi], '-'
|
||
|
jne c_7
|
||
|
mov eax, edi
|
||
|
add eax, 1
|
||
|
cmp eax, edx ; last loc
|
||
|
je .other_dir
|
||
|
mov edx, edi ; last loc = loc
|
||
|
mov edi, eax
|
||
|
jmp walking_loop
|
||
|
.other_dir:
|
||
|
mov edx, edi ; last loc = loc
|
||
|
sub edi, 1
|
||
|
jmp walking_loop
|
||
|
c_7:
|
||
|
cmp byte [edi], '7'
|
||
|
jne c_J
|
||
|
mov eax, edi
|
||
|
add eax, [line_len] ; down
|
||
|
cmp eax, edx ; last loc
|
||
|
je .other_dir
|
||
|
mov edx, edi ; last loc = loc
|
||
|
mov edi, eax
|
||
|
jmp walking_loop
|
||
|
.other_dir:
|
||
|
mov edx, edi ; last loc = loc
|
||
|
sub edi, 1 ; left
|
||
|
jmp walking_loop
|
||
|
c_J:
|
||
|
cmp byte [edi], 'J'
|
||
|
jne c_L
|
||
|
mov eax, edi
|
||
|
sub eax, [line_len] ; up
|
||
|
cmp eax, edx ; last loc
|
||
|
je .other_dir
|
||
|
mov edx, edi ; last loc = loc
|
||
|
mov edi, eax
|
||
|
jmp walking_loop
|
||
|
.other_dir:
|
||
|
mov edx, edi ; last loc = loc
|
||
|
sub edi, 1 ; left
|
||
|
jmp walking_loop
|
||
|
c_L:
|
||
|
cmp byte [edi], 'L'
|
||
|
jne c_F
|
||
|
mov eax, edi
|
||
|
sub eax, [line_len] ; up
|
||
|
cmp eax, edx ; last loc
|
||
|
je .other_dir
|
||
|
mov edx, edi ; last loc = loc
|
||
|
mov edi, eax
|
||
|
jmp walking_loop
|
||
|
.other_dir:
|
||
|
mov edx, edi ; last loc = loc
|
||
|
add edi, 1 ; right
|
||
|
jmp walking_loop
|
||
|
c_F:
|
||
|
cmp byte [edi], 'F'
|
||
|
jne fucked_up
|
||
|
mov eax, edi
|
||
|
add eax, [line_len] ; down
|
||
|
cmp eax, edx ; last loc
|
||
|
je .other_dir
|
||
|
mov edx, edi ; last loc = loc
|
||
|
mov edi, eax
|
||
|
jmp walking_loop
|
||
|
.other_dir:
|
||
|
mov edx, edi ; last loc = loc
|
||
|
add edi, 1 ; right
|
||
|
jmp walking_loop
|
||
|
|
||
|
done_walking:
|
||
|
mov eax, [final_value]
|
||
|
inc eax
|
||
|
shr eax, 1
|
||
|
mov [final_value], eax
|
||
|
|
||
|
game_over:
|
||
|
mov eax, [final_value]
|
||
|
call print_dec
|
||
|
jmp exit
|
||
|
|
||
|
fucked_up:
|
||
|
mov eax, 999999999
|
||
|
call print_dec
|
||
|
jmp exit
|
||
|
|
||
|
[section .data]
|
||
|
line_len: dd 0
|
||
|
s_idx: dd 0
|
||
|
s_line: dd 0
|
||
|
s_col: dd 0
|
||
|
final_value: dd 0
|
||
|
file_lim: dd file.over - file
|
||
|
file: incbin "input"
|
||
|
.over:
|
||
|
|
||
|
[section .bss]
|