362 lines
5.8 KiB
ArmAsm
362 lines
5.8 KiB
ArmAsm
|
global _start
|
||
|
[bits 32]
|
||
|
[section .text]
|
||
|
|
||
|
;%define LINE_LEN 11
|
||
|
;%define LINE_CNT 10
|
||
|
|
||
|
%define LINE_LEN 101
|
||
|
%define LINE_CNT 100
|
||
|
|
||
|
%define CYCLE_CNT 1000000000
|
||
|
|
||
|
%include "utils.s"
|
||
|
|
||
|
_start:
|
||
|
|
||
|
push CYCLE_CNT
|
||
|
fucking:
|
||
|
mov eax, [esp]
|
||
|
and eax, 0xfffff
|
||
|
jnz north
|
||
|
mov eax, [esp]
|
||
|
call print_dec
|
||
|
call newline
|
||
|
|
||
|
; north cycle
|
||
|
north:
|
||
|
; init next spots
|
||
|
mov edi, next_spot
|
||
|
mov eax, file
|
||
|
.init_spots:
|
||
|
stosd
|
||
|
inc eax
|
||
|
cmp eax, file+LINE_LEN
|
||
|
jb .init_spots
|
||
|
mov esi, file
|
||
|
; for chars in line
|
||
|
.do_stuff:
|
||
|
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 next spot to next line
|
||
|
lea eax, [esi+LINE_LEN-1]
|
||
|
mov [next_spot+ebx*4], eax
|
||
|
jmp .cont
|
||
|
.round_rock:
|
||
|
; move rock
|
||
|
mov byte [esi-1], '.'
|
||
|
mov edi, [next_spot+ebx*4]
|
||
|
mov byte [edi], 'O'
|
||
|
; move next spot to next line
|
||
|
add dword [next_spot+ebx*4], LINE_LEN
|
||
|
jmp .cont
|
||
|
.line_done:
|
||
|
cmp esi, file.over
|
||
|
jb .do_stuff
|
||
|
|
||
|
;mov esi, file
|
||
|
;mov ecx, file.over - file
|
||
|
;call print_string
|
||
|
;call newline
|
||
|
|
||
|
; west cycle
|
||
|
west:
|
||
|
; init next spots
|
||
|
mov edi, next_spot
|
||
|
mov eax, file ; start of first line
|
||
|
.init_spots:
|
||
|
stosd
|
||
|
add eax, LINE_LEN ; start of next line
|
||
|
cmp eax, file+(LINE_LEN*LINE_CNT)
|
||
|
jb .init_spots
|
||
|
mov esi, file ; start of first col
|
||
|
mov edx, esi ; save this whatever
|
||
|
; for chars in col
|
||
|
.do_stuff:
|
||
|
xor ebx, ebx ; line num
|
||
|
jmp .loop
|
||
|
.cont:
|
||
|
inc ebx ; line num
|
||
|
cmp esi, file.over
|
||
|
jae .line_done
|
||
|
.loop:
|
||
|
mov al, [esi]
|
||
|
add esi, LINE_LEN ; next line
|
||
|
cmp al, '#'
|
||
|
je .cube_rock
|
||
|
cmp al, 'O'
|
||
|
je .round_rock
|
||
|
; else .
|
||
|
jmp .cont
|
||
|
.cube_rock:
|
||
|
; move next spot to next column
|
||
|
lea eax, [esi-LINE_LEN+1]
|
||
|
mov [next_spot+ebx*4], eax
|
||
|
jmp .cont
|
||
|
.round_rock:
|
||
|
; move rock
|
||
|
mov byte [esi-LINE_LEN], '.'
|
||
|
mov edi, [next_spot+ebx*4]
|
||
|
mov byte [edi], 'O'
|
||
|
; move next spot to next column
|
||
|
inc dword [next_spot+ebx*4]
|
||
|
jmp .cont
|
||
|
.line_done:
|
||
|
inc edx ; next col
|
||
|
mov esi, edx
|
||
|
cmp esi, file+LINE_LEN
|
||
|
jb .do_stuff
|
||
|
|
||
|
;mov esi, file
|
||
|
;mov ecx, file.over - file
|
||
|
;call print_string
|
||
|
;call newline
|
||
|
|
||
|
; south cycle
|
||
|
south:
|
||
|
; init next spots
|
||
|
mov edi, next_spot
|
||
|
mov eax, file+((LINE_CNT-1)*LINE_LEN) ; start of final line
|
||
|
.init_spots:
|
||
|
stosd
|
||
|
inc eax
|
||
|
cmp eax, file+(LINE_CNT*LINE_LEN)
|
||
|
jb .init_spots
|
||
|
mov esi, file+((LINE_CNT-1)*LINE_LEN) ; start of final line
|
||
|
; for chars in line
|
||
|
.do_stuff:
|
||
|
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 next spot to previous line
|
||
|
lea eax, [esi-LINE_LEN-1]
|
||
|
mov [next_spot+ebx*4], eax
|
||
|
jmp .cont
|
||
|
.round_rock:
|
||
|
; move rock
|
||
|
mov byte [esi-1], '.'
|
||
|
mov edi, [next_spot+ebx*4]
|
||
|
mov byte [edi], 'O'
|
||
|
; move next spot to previous line
|
||
|
sub dword [next_spot+ebx*4], LINE_LEN
|
||
|
jmp .cont
|
||
|
.line_done:
|
||
|
sub esi, LINE_LEN*2
|
||
|
cmp esi, file
|
||
|
jae .do_stuff
|
||
|
|
||
|
;mov esi, file
|
||
|
;mov ecx, file.over - file
|
||
|
;call print_string
|
||
|
;call newline
|
||
|
|
||
|
; east cycle
|
||
|
east:
|
||
|
; init next spots
|
||
|
mov edi, next_spot
|
||
|
mov eax, file+LINE_LEN-2 ; end of first line
|
||
|
.init_spots:
|
||
|
stosd
|
||
|
add eax, LINE_LEN ; end of next line
|
||
|
cmp eax, file.over
|
||
|
jb .init_spots
|
||
|
mov esi, file+LINE_LEN-2 ; end of first col
|
||
|
mov edx, esi ; save this whatever
|
||
|
; for chars in col
|
||
|
.do_stuff:
|
||
|
xor ebx, ebx ; line num
|
||
|
jmp .loop
|
||
|
.cont:
|
||
|
inc ebx ; line num
|
||
|
cmp esi, file.over
|
||
|
jae .line_done
|
||
|
.loop:
|
||
|
mov al, [esi]
|
||
|
add esi, LINE_LEN ; next line
|
||
|
cmp al, '#'
|
||
|
je .cube_rock
|
||
|
cmp al, 'O'
|
||
|
je .round_rock
|
||
|
; else .
|
||
|
jmp .cont
|
||
|
.cube_rock:
|
||
|
; move next spot to previous column
|
||
|
lea eax, [esi-LINE_LEN-1]
|
||
|
mov [next_spot+ebx*4], eax
|
||
|
jmp .cont
|
||
|
.round_rock:
|
||
|
; move rock
|
||
|
mov byte [esi-LINE_LEN], '.'
|
||
|
mov edi, [next_spot+ebx*4]
|
||
|
mov byte [edi], 'O'
|
||
|
; move next spot to previous column
|
||
|
dec dword [next_spot+ebx*4]
|
||
|
jmp .cont
|
||
|
.line_done:
|
||
|
dec edx ; previous col
|
||
|
mov esi, edx
|
||
|
cmp esi, file
|
||
|
jae .do_stuff
|
||
|
|
||
|
;mov esi, file
|
||
|
;mov ecx, file.over - file
|
||
|
;call print_string
|
||
|
;call newline
|
||
|
|
||
|
mov dword [final_value], 0
|
||
|
int_calc_load:
|
||
|
xor ebx, ebx ; line num
|
||
|
mov edi, file+((LINE_CNT-1)*LINE_LEN) ; start of final line
|
||
|
.proc_line:
|
||
|
inc ebx
|
||
|
mov esi, edi
|
||
|
mov ecx, LINE_CNT ; skip \n
|
||
|
xor edx, edx ; O cnt
|
||
|
.add_stuff:
|
||
|
lodsb
|
||
|
cmp al, 'O'
|
||
|
jne .cont
|
||
|
inc edx
|
||
|
.cont:
|
||
|
loop .add_stuff
|
||
|
mov eax, edx
|
||
|
mul ebx
|
||
|
add [final_value], eax
|
||
|
sub edi, LINE_LEN
|
||
|
cmp edi, file
|
||
|
jae .proc_line
|
||
|
|
||
|
mov eax, [final_value]
|
||
|
mov esi, answer_bs
|
||
|
check_answers:
|
||
|
cmp esi, answer_bs.end
|
||
|
jb .w
|
||
|
mov esi, error_str
|
||
|
mov ecx, error_str.end - error_str
|
||
|
call print_string
|
||
|
jmp exit
|
||
|
.w:
|
||
|
cmp dword [esi], 0
|
||
|
je .new
|
||
|
cmp [esi], eax
|
||
|
je .found
|
||
|
.cont:
|
||
|
mov ebx, CYCLE_CNT
|
||
|
sub ebx, [esp]
|
||
|
mov edx, ebx
|
||
|
sub edx, 1000
|
||
|
cmp [esi+4], edx
|
||
|
jb .new
|
||
|
add esi, 16
|
||
|
jmp check_answers
|
||
|
.new:
|
||
|
mov [esi], eax
|
||
|
mov ebx, CYCLE_CNT
|
||
|
sub ebx, [esp]
|
||
|
mov [esi+4], ebx
|
||
|
mov dword [esi+8], 0 ; cycle
|
||
|
mov dword [esi+12], 1 ; seen times
|
||
|
jmp .whatever
|
||
|
.found:
|
||
|
mov ebx, CYCLE_CNT
|
||
|
sub ebx, [esp] ; found num
|
||
|
mov edx, ebx
|
||
|
sub edx, [esi+4] ; last found num
|
||
|
cmp dword [esi+8], 1
|
||
|
jbe .first_seen
|
||
|
cmp edx, [esi+8] ; last cycle
|
||
|
jne .cont
|
||
|
mov [esi+4], ebx
|
||
|
inc dword [esi+12] ; seen times
|
||
|
cmp dword [esi+12], 5
|
||
|
jl .whatever
|
||
|
mov eax, CYCLE_CNT-1
|
||
|
sub eax, dword [esi+4]
|
||
|
xor edx, edx
|
||
|
div dword [esi+8]
|
||
|
test edx, edx
|
||
|
jnz .whatever
|
||
|
mov dword [esp], 1
|
||
|
jmp .whatever
|
||
|
.first_seen:
|
||
|
mov [esi+4], ebx
|
||
|
mov [esi+8], edx
|
||
|
inc dword [esi+12] ; seen times
|
||
|
|
||
|
.whatever:
|
||
|
dec dword [esp]
|
||
|
jnz fucking
|
||
|
|
||
|
print_answer_cycles:
|
||
|
mov esi, answer_bs
|
||
|
.loop:
|
||
|
cmp dword [esi], 0
|
||
|
je game_over
|
||
|
cmp dword [esi+12], 5
|
||
|
jl .cont
|
||
|
mov eax, dword [esi]
|
||
|
call print_dec
|
||
|
call space
|
||
|
mov eax, dword [esi+4]
|
||
|
call print_dec
|
||
|
call space
|
||
|
mov eax, dword [esi+8]
|
||
|
call print_dec
|
||
|
call space
|
||
|
mov eax, dword [esi+12]
|
||
|
call print_dec
|
||
|
call space
|
||
|
cmp dword [esi+8], 1
|
||
|
jbe .zeroorone
|
||
|
mov eax, CYCLE_CNT-1
|
||
|
sub eax, dword [esi+4]
|
||
|
xor edx, edx
|
||
|
div dword [esi+8]
|
||
|
mov eax, edx
|
||
|
call print_dec ; one of these that gets printed as 0 is answer
|
||
|
.zeroorone:
|
||
|
call newline
|
||
|
.cont:
|
||
|
add esi, 16
|
||
|
jmp .loop
|
||
|
|
||
|
game_over:
|
||
|
jmp exit
|
||
|
|
||
|
[section .data]
|
||
|
final_value: dd 0
|
||
|
file: incbin "input"
|
||
|
.over:
|
||
|
error_str: db ":c too much super num"
|
||
|
.end:
|
||
|
|
||
|
[section .bss]
|
||
|
next_spot: resd 128
|
||
|
answer_bs: resd 1024 ; increase if failing ig
|
||
|
.end:
|