125 lines
1.9 KiB
ArmAsm
125 lines
1.9 KiB
ArmAsm
|
global _start
|
||
|
[bits 32]
|
||
|
[section .text]
|
||
|
|
||
|
%include "utils.s"
|
||
|
|
||
|
_start:
|
||
|
|
||
|
mov esi, file
|
||
|
parse_line:
|
||
|
; find first num
|
||
|
mov ebp, esi ; line start
|
||
|
.first_num:
|
||
|
mov edi, esi ; save before loc
|
||
|
call dec_parse
|
||
|
jc .first_num
|
||
|
; edi has pointer to just before numbers
|
||
|
mov ecx, edi
|
||
|
sub ecx, ebp
|
||
|
dec ecx ; space
|
||
|
xchg esi, ebp
|
||
|
mov [line_len], ecx
|
||
|
mov edi, line
|
||
|
rep movsb
|
||
|
xchg esi, ebp
|
||
|
mov dword [contiguous_broken+ 0], 0
|
||
|
mov dword [contiguous_broken+ 4], 0
|
||
|
mov dword [contiguous_broken+ 8], 0
|
||
|
mov dword [contiguous_broken+12], 0
|
||
|
mov edi, contiguous_broken
|
||
|
stosb
|
||
|
.next_num:
|
||
|
cmp byte [esi-1], 10 ; \n
|
||
|
je .newline
|
||
|
call dec_parse
|
||
|
jc .next_num
|
||
|
.got_num:
|
||
|
stosb
|
||
|
jmp .next_num
|
||
|
.newline:
|
||
|
push esi ; save input line
|
||
|
mov esi, line
|
||
|
mov ecx, [line_len]
|
||
|
xor ebx, ebx
|
||
|
count_qs:
|
||
|
lodsb
|
||
|
cmp al, '?'
|
||
|
jne .cont
|
||
|
stc
|
||
|
rcl ebx, 1
|
||
|
.cont:
|
||
|
loop count_qs
|
||
|
push ebx ; ? final setting
|
||
|
test_possibilities:
|
||
|
xor ebp, ebp ; ? settings
|
||
|
xor ebx, ebx ; poss counter
|
||
|
.next_poss:
|
||
|
mov edx, ebp
|
||
|
mov esi, line
|
||
|
mov ecx, [line_len]
|
||
|
xor eax, eax ; ah - curr broke run, al - lodsb
|
||
|
mov edi, contiguous_broken
|
||
|
.next_poss_loop:
|
||
|
lodsb
|
||
|
cmp al, '.'
|
||
|
je .working
|
||
|
cmp al, '#'
|
||
|
je .broke
|
||
|
; else ? - select based on edx
|
||
|
rcr edx, 1
|
||
|
jc .broke
|
||
|
.working:
|
||
|
cmp ah, 0
|
||
|
je .cont ; no broke
|
||
|
cmp [edi], ah
|
||
|
jne .fail_poss
|
||
|
inc edi
|
||
|
mov ah, 0
|
||
|
jmp .cont
|
||
|
.broke:
|
||
|
inc ah
|
||
|
.cont:
|
||
|
loop .next_poss_loop
|
||
|
cmp [edi], ah
|
||
|
jne .fail_poss
|
||
|
cmp byte [edi+1], 0
|
||
|
jne .fail_poss
|
||
|
inc ebx ; poss counter
|
||
|
mov eax, ebp
|
||
|
;call print_dec
|
||
|
;call space
|
||
|
.fail_poss:
|
||
|
.next_poss_cont:
|
||
|
inc ebp ; ? settings
|
||
|
cmp ebp, [esp] ; cmp to final
|
||
|
jbe .next_poss
|
||
|
;call newline
|
||
|
mov eax, ebx
|
||
|
call print_dec
|
||
|
call newline
|
||
|
add [final_value], ebx
|
||
|
add esp, 4
|
||
|
pop esi
|
||
|
cmp esi, file.over-1
|
||
|
jb parse_line
|
||
|
call newline
|
||
|
|
||
|
game_over:
|
||
|
mov eax, [final_value]
|
||
|
call print_dec
|
||
|
call newline
|
||
|
jmp exit
|
||
|
|
||
|
[section .data]
|
||
|
final_value: dd 0
|
||
|
line_len: dd 0
|
||
|
file: incbin "input"
|
||
|
.over:
|
||
|
nl_str: db "new line!"
|
||
|
.over:
|
||
|
|
||
|
[section .bss]
|
||
|
contiguous_broken: resb 16
|
||
|
line: resb 256
|