Compare commits

..

22 Commits

Author SHA1 Message Date
Lucia Ceionia
7a9bd95804 day 20 part 2 im tired 2023-12-23 03:29:03 -06:00
Lucia Ceionia
9f5df0a65c day 20 part 1 2023-12-23 02:56:15 -06:00
Lucia Ceionia
2598b444f8 day 19 part 2 2023-12-20 01:40:44 -06:00
Lucia Ceionia
d59671e54c day 19 part 1 2023-12-19 21:20:26 -06:00
Lucia Ceionia
0785e7ccd0 day 18 part 2 2023-12-18 14:04:47 -06:00
Lucia Ceionia
5db47a3fcc day 18 part 1 2023-12-18 12:51:44 -06:00
Lucia Ceionia
3362719e79 day 17 part 2 (almost, it's wrong) 2023-12-17 21:23:54 -06:00
Lucia Ceionia
d1478ac425 day 17 part 1 (hellishly slow) 2023-12-17 19:45:57 -06:00
Lucia Ceionia
ae34c01c77 skip printing for speed 2023-12-16 19:30:47 -06:00
Lucia Ceionia
83f5ba9fae day 16 part 2 2023-12-16 19:26:15 -06:00
Lucia Ceionia
45fc62c759 day 16 part 1 2023-12-16 18:41:45 -06:00
Lucia Ceionia
9ecb520b5c day 15 part1&2 2023-12-15 01:58:12 -06:00
Lucia Ceionia
5b6a60a62a make it faster 2023-12-14 14:30:56 -06:00
Lucia Ceionia
7a619a48c3 day 14 part 1&2 2023-12-14 14:11:15 -06:00
Lucia Ceionia
900602889b day 13 part 1&2 2023-12-13 04:17:13 -06:00
Lucia Ceionia
400b90c50e day 12 part 1&2 2023-12-12 09:36:26 -06:00
Lucia Ceionia
dd65bf8a56 day 11 part 1&2 2023-12-11 03:28:34 -06:00
Lucia Ceionia
fa4a9b3efd day 10 parts 1&2 2023-12-10 04:45:09 -06:00
Lucia Ceionia
fa953385d9 day 9 parts 1&2 2023-12-10 01:13:51 -06:00
Lucia Ceionia
327a6eb4c6 day 8 parts 1 & 2 2023-12-08 11:10:36 -06:00
Lucia Ceionia
43d12dae95 day 7 part 2 2023-12-07 02:48:10 -06:00
Lucia Ceionia
b71d3da003 day 7 part 1 2023-12-07 01:21:29 -06:00
88 changed files with 18026 additions and 0 deletions

3
07/Makefile Normal file
View File

@@ -0,0 +1,3 @@
all:
nasm -g -felf32 main.s && ld -melf_i386 -g main.o

1000
07/input Normal file

File diff suppressed because it is too large Load Diff

5
07/input_test Normal file
View File

@@ -0,0 +1,5 @@
32T3K 765
T55J5 684
KK677 28
KTJJT 220
QQQJA 483

376
07/main.s Normal file
View File

@@ -0,0 +1,376 @@
global _start
[bits 32]
[section .text]
%include "utils.s"
; for h in hands
; ; score hands
; tmp := 0
; counts[15] := [0; 15]
; joker_values := [0; 5]
; for c in h
; if c > '9'
; if c = 'T' then value := 10
; elif c = 'J' then
; value := 1
; joker_values[char_idx] := 1
; end
; elif c = 'Q' then value := 11
; elif c = 'K' then value := 12
; elif c = 'A' then value := 13
; else
; value := c - '0'
; end
; tmp := (tmp * 14) + value
; put in counts
; end
; ; joker bs
; orig_val := tmp
; best_score := orig_val
; loop
; fake_counts := counts
; tmp := orig_val
; for j in joker_values where j != 0
; fake_counts[j] += 1
; end
;
; ; check hand type
; has_five := 0
; has_four := 0
; has_three := 0
; has_two := 0
; for n in fake_counts
; if n = 5 then inc has_five
; if n = 4 then inc has_four
; if n = 3 then inc has_three
; if n = 2 then inc has_two
; end
; if has_five then tmp := tmp + 60,000,000
; elif has_four then tmp := tmp + 50,000,000
; elif has_three and has_two then tmp := tmp + 40,000,000
; elif has_three then tmp := tmp + 30,000,000
; elif has_two = 2 then tmp := tmp + 20,000,000
; elif has_two = 1 then tmp := tmp + 10,000,000
; if tmp > best_score then best_score := tmp
;
; last_joker_carried := 1
; i := 0
; loop
; if joker_values[i] + 1 = 14 then
; joker_values[i] = 2
; else
; joker_values[i] += 1
; last_joker_carried := 0
; end
; .cont:
; inc i
; if i = 5 then break
; if !last_joker_carried then break
; end
; if last_joker_carried then break
; end
; ; store in array
; stosd best_score -> hand_array
; stosd bid -> hand_array
; end
;
; bubble sort hand_array
;
; calc total
; rank := 1
; for (_, bid) in hand_array
; final_value += rank * bid
; rank += 1
; end
;
; done
_start:
mov esi, file
mov edi, hand_array
; for l in lines
; ...
; end
for_in_lines:
; check for end
cmp esi, file.over
jae for_in_lines_end
; score hand
; tmp := 0
xor ebp, ebp ; tmp
; counts[15] := [0; 15]
push edi
mov edi, counts
mov ecx, 15
xor eax, eax
rep stosb
pop edi
; zero joker_values
mov dword [joker_values], 0
mov dword [joker_values+4], 0
get_hand_score:
; do 5 times
; ...
; end
mov ecx, 5
xor ebx, ebx ; char value
push edi ; save edi
xor edi, edi ; idx
.next_char:
lodsb
; if c > '9'
cmp al, '9'
jle .is_num
mov edx, 10
cmp al, 'T'
cmove ebx, edx
cmp al, 'J'
jne .not_joker
mov ebx, 1
mov byte [joker_values+edi], 1
jmp .add_to_tmp_skip_counts
.not_joker:
mov edx, 11
cmp al, 'Q'
cmove ebx, edx
mov edx, 12
cmp al, 'K'
cmove ebx, edx
mov edx, 13
cmp al, 'A'
cmove ebx, edx
jmp .add_to_tmp
.is_num:
; else val := c - '0'
sub al, '0'
movzx ebx, al
; end
.add_to_tmp:
; put in counts
inc byte [counts+ebx]
.add_to_tmp_skip_counts:
; tmp *= 14
; tmp += score
mov eax, ebp
mov edx, 14
mul edx
add eax, ebx
mov ebp, eax
inc edi ; idx
loop .next_char
pop edi ; restore edi
; joker bs
joker_bs:
push ebp ; best_score (esp + 4)
push ebp ; orig_val (esp)
; loop .. end
joker_loop:
; fake_counts := counts
; tmp := orig_val
mov eax, [counts+0]
mov [fake_counts+0], eax
mov eax, [counts+4]
mov [fake_counts+4], eax
mov eax, [counts+8]
mov [fake_counts+8], eax
mov eax, [counts+12]
mov [fake_counts+12], eax
mov ebp, [esp] ; tmp := orig_val
; for j in joker_values where j != 0
; fake_counts[j] += 1
; end
push esi
mov ecx, 5
mov esi, joker_values
xor eax, eax
add_fake_counts:
lodsb
inc byte [fake_counts+eax]
.cont:
loop add_fake_counts
mov byte [fake_counts], 0 ; idx 0 is always 0
pop esi
; check hand type
mov byte [has_five], 0
mov byte [has_four], 0
mov byte [has_three], 0
mov byte [has_two], 0
; for n in fake_counts
mov ecx, 15
push esi ; save line
mov esi, fake_counts
check_counts:
lodsb
cmp al, 5
jne .check_4
inc byte [has_five]
.check_4:
cmp al, 4
jne .check_3
inc byte [has_four]
.check_3:
cmp al, 3
jne .check_2
inc byte [has_three]
.check_2:
cmp al, 2
jne .check_cont
inc byte [has_two]
.check_cont:
loop check_counts
; end
pop esi ; restore line
cmp byte [has_five], 0
je .maybe_four
add ebp, 60000000
jmp .save
.maybe_four:
cmp byte [has_four], 0
je .maybe_three
add ebp, 50000000
jmp .save
.maybe_three:
cmp byte [has_three], 0
je .maybe_twos
add ebp, 30000000
.maybe_twos:
mov cl, byte [has_two]
cmp cl, 0
je .save
mov eax, 10000000/2
shl eax, cl
add ebp, eax
.save:
; if tmp > best_score then best_score := tmp
cmp ebp, [esp+4] ; best_score
jbe .not_better
mov [esp+4], ebp
.not_better:
mov edx, 1 ; last_joker_carried := 1
xor ecx, ecx ; i := 0
; loop..end
increment_jokers:
; if joker_values[i] + 1 = 14 then
; joker_values[i] = 2
; else
; joker_values[i] += 1
; last_joker_carried := 0
; end
cmp byte [joker_values+ecx], 0
je .cont
cmp byte [joker_values+ecx], 13
jne .else
mov byte [joker_values+ecx], 2
jmp .cont
.else:
inc byte [joker_values+ecx]
xor edx, edx
.cont:
inc ecx ; i += 1
; if i = 5 then break
; if !last_joker_carried then break
cmp ecx, 5
je increment_jokers_end
test edx, edx
jz increment_jokers_end
jmp increment_jokers
increment_jokers_end:
; if last_joker_carried then break
test edx, edx
jnz joker_bs_end
joker_loop_end:
jmp joker_loop
joker_bs_end:
pop eax ; orig_val (discard)
pop eax ; best_score
real_save:
; store best_score & bid in array
stosd
inc esi ; skip space
call dec_parse ; bid
stosd
for_in_lines_cont:
jmp for_in_lines
for_in_lines_end:
; bubble sort hand_array
bubble_sort:
; get length (array is null terminated)
mov esi, hand_array
xor eax, eax
get_len:
cmp dword [esi+eax*8], 0
je .done
inc eax
jmp get_len
.done:
mov ebp, eax ; n
do_sort:
xor edx, edx ; newn
mov ecx, 1 ; i
.inner:
mov eax, [esi+ecx*8-8] ; A[i-1]
cmp eax, [esi+ecx*8] ; A[i]
jbe .inner_cont
; swap elements
xchg eax, [esi+ecx*8]
mov [esi+ecx*8-8], eax
mov eax, [esi+ecx*8-4] ; A[i-1] bid
xchg eax, [esi+ecx*8+4] ; A[i] bid
mov [esi+ecx*8-4], eax
mov edx, ecx ; newn
.inner_cont:
inc ecx
cmp ecx, ebp
jb .inner
mov ebp, edx ; n := newn
cmp ebp, 1
ja do_sort ; until n <= 1
done_sort:
; calc total
; rank := 1
mov ebx, 1
mov esi, hand_array
calc_total:
lodsd ; _
lodsd ; bid
test eax, eax
jz calc_total_done
mul ebx
add [final_value], eax
inc ebx
jmp calc_total
calc_total_done:
game_over:
mov eax, [final_value]
call print_dec
jmp exit
[section .data]
final_value: dd 0
joker_values: times 8 db 0 ; we only use 5 but this makes zeroing easier
counts: times 16 db 0 ; only use 14 or 13 but whatever
fake_counts: times 16 db 0
has_five: db 0
has_four: db 0
has_three: db 0
has_two: db 0
file_lim: dd file.over - file
file: incbin "input"
.over:
[section .bss]
hand_array: resd 4096

254
07/main_part1.s Normal file
View File

@@ -0,0 +1,254 @@
global _start
[bits 32]
[section .text]
%include "utils.s"
; for h in hands
; ; score hands
; tmp := 0
; counts[15] := [0; 15]
; for c in h
; if c > '9'
; if c = 'T' then score := 10
; elif c = 'J' then score := 11
; elif c = 'Q' then score := 12
; elif c = 'K' then score := 13
; elif c = 'A' then score := 14
; else
; score := c - '0'
; end
; tmp := (tmp * 14) + score
; put in counts
; end
; ; check hand type
; has_five := 0
; has_four := 0
; has_three := 0
; has_two := 0
; for n in counts
; if n = 5 then inc has_five
; if n = 4 then inc has_four
; if n = 3 then inc has_three
; if n = 2 then inc has_two
; end
; if has_five then tmp := tmp + 60,000,000
; elif has_four then tmp := tmp + 50,000,000
; elif has_three and has_two then tmp := tmp + 40,000,000
; elif has_three then tmp := tmp + 30,000,000
; elif has_two = 2 then tmp := tmp + 20,000,000
; elif has_two = 1 then tmp := tmp + 10,000,000
; ; store tmp in array
; stosd tmp -> hand_array
; stosd bid -> hand_array
; end
;
; bubble sort hand_array
;
; calc total
; rank := 1
; for (_, bid) in hand_array
; final_value += rank * bid
; rank += 1
; end
;
; done
_start:
mov esi, file
mov edi, hand_array
; for l in lines
; ...
; end
for_in_lines:
; check for end
cmp esi, file.over
jae for_in_lines_end
; score hand
; tmp := 0
xor ebp, ebp ; tmp
; counts[15] := [0; 15]
push edi
mov edi, counts
mov ecx, 15
xor eax, eax
rep stosb
pop edi
get_hand_score:
; do 5 times
; ...
; end
mov ecx, 5
xor ebx, ebx ; char value
.next_char:
lodsb
; if c > '9'
cmp al, '9'
jle .is_num
mov edx, 10
cmp al, 'T'
cmove ebx, edx
mov edx, 11
cmp al, 'J'
cmove ebx, edx
mov edx, 12
cmp al, 'Q'
cmove ebx, edx
mov edx, 13
cmp al, 'K'
cmove ebx, edx
mov edx, 14
cmp al, 'A'
cmove ebx, edx
jmp .add_to_tmp
.is_num:
; else val := c - '0'
sub al, '0'
movzx ebx, al
; end
.add_to_tmp:
; tmp *= 14
; tmp += score
mov eax, ebp
mov edx, 14
mul edx
add eax, ebx
mov ebp, eax
; put in counts
inc byte [counts+ebx]
loop .next_char
; check hand type
mov byte [has_five], 0
mov byte [has_four], 0
mov byte [has_three], 0
mov byte [has_two], 0
; for n in counts
mov ecx, 15
push esi ; save line
mov esi, counts
check_counts:
lodsb
cmp al, 5
jne .check_4
inc byte [has_five]
.check_4:
cmp al, 4
jne .check_3
inc byte [has_four]
.check_3:
cmp al, 3
jne .check_2
inc byte [has_three]
.check_2:
cmp al, 2
jne .check_cont
inc byte [has_two]
.check_cont:
loop check_counts
; end
pop esi ; restore line
cmp byte [has_five], 0
je .maybe_four
add ebp, 60000000
jmp .save
.maybe_four:
cmp byte [has_four], 0
je .maybe_three
add ebp, 50000000
jmp .save
.maybe_three:
cmp byte [has_three], 0
je .maybe_twos
add ebp, 30000000
.maybe_twos:
mov cl, byte [has_two]
cmp cl, 0
je .save
mov eax, 10000000/2
shl eax, cl
add ebp, eax
.save:
; store tmp & bid in array
mov eax, ebp
stosd
inc esi ; skip space
call dec_parse ; bid
stosd
for_in_lines_cont:
jmp for_in_lines
for_in_lines_end:
; bubble sort hand_array
bubble_sort:
; get length (array is null terminated)
mov esi, hand_array
xor eax, eax
get_len:
cmp dword [esi+eax*8], 0
je .done
inc eax
jmp get_len
.done:
mov ebp, eax ; n
do_sort:
xor edx, edx ; newn
mov ecx, 1 ; i
.inner:
mov eax, [esi+ecx*8-8] ; A[i-1]
cmp eax, [esi+ecx*8] ; A[i]
jbe .inner_cont
; swap elements
xchg eax, [esi+ecx*8]
mov [esi+ecx*8-8], eax
mov eax, [esi+ecx*8-4] ; A[i-1] bid
xchg eax, [esi+ecx*8+4] ; A[i] bid
mov [esi+ecx*8-4], eax
mov edx, ecx ; newn
.inner_cont:
inc ecx
cmp ecx, ebp
jb .inner
mov ebp, edx ; n := newn
cmp ebp, 1
ja do_sort ; until n <= 1
done_sort:
; calc total
; rank := 1
mov ebx, 1
mov esi, hand_array
calc_total:
lodsd ; _
lodsd ; bid
test eax, eax
jz calc_total_done
mul ebx
add [final_value], eax
inc ebx
jmp calc_total
calc_total_done:
game_over:
mov eax, [final_value]
call print_dec
jmp exit
[section .data]
final_value: dd 0
counts: times 15 db 0
has_five: db 0
has_four: db 0
has_three: db 0
has_two: db 0
file_lim: dd file.over - file
file: incbin "input"
.over:
[section .bss]
hand_array: resd 4096

146
07/utils.s Normal file
View File

@@ -0,0 +1,146 @@
; call # val val2
; int $0x80 eax eax edx -
;
; arg1 arg2 arg3 arg4 arg5 arg6 arg7
; ebx ecx edx esi edi ebp -
exit:
mov eax, 1 ; exit
int 0x80
; filename in EBX
; return handle in EBX
; read only
open_file:
push eax
push ecx
mov eax, 5 ; open
xor ecx, ecx ; read only
int 0x80
mov ebx, eax
pop ecx
pop eax
ret
; file handle in EBX
; buffer in ECX
; count of bytes to read in EDX
; return bytes actually read in EAX
; exits on error
read_file:
mov eax, 3 ; read
int 0x80
test eax, eax
js .err
ret
.err:
mov eax, 4 ; write
mov ebx, 1 ; stdout
mov ecx, .err_str
mov edx, 21
int 0x80
jmp exit
.err_str: db `Could not read file.\n`
; string input in ESI
; value in EAX
; CF set if none, clear if some
; ESI set past checked area
dec_parse:
push ebx
push edx
push edi
xor eax, eax
xor edi, edi
mov ebx, 10 ; base
lodsb
sub al, '0'
js .no_input
cmp al, 9
jle .got_char
.no_input:
stc ; set CF
jmp .done
.loop:
xor eax,eax
lodsb
sub al, '0'
js .dec_done
cmp al, 9
jg .dec_done
.got_char:
xchg edi,eax
mul ebx
add edi,eax
jmp .loop
.dec_done:
clc ; clear CF
.done:
mov eax,edi
pop edi
pop edx
pop ebx
ret
; modifies no regs
newline:
pushad
push 10
mov eax, 4 ; write
mov ebx, 1 ; stdout
mov ecx, esp ; string
mov edx, 1 ; length
int 0x80
add esp, 4
popad
ret
; modifies no regs
space:
pushad
push 9
mov eax, 4 ; write
mov ebx, 1 ; stdout
mov ecx, esp ; string
mov edx, 1 ; length
int 0x80
add esp, 4
popad
ret
; input in EAX, all regs unmodified
print_dec:
pushad ; save regs
; max 4294967296 is 10 chars
; round to nearest 32-bit boundary
sub esp, 12
; string in ECX, length in EDX
lea ecx, [esp+11] ; last possible byte
; check for 0
test eax, eax
jz .zero
mov ebx, 10 ; base 10
xor esi, esi ; counter
.div_shit:
xor edx, edx
; divide
div ebx
dec ecx ; next char
inc esi
; store
add dl, '0'
mov byte [ecx], dl
; check if done
test eax, eax
jnz .div_shit ; continue
mov edx, esi ; counter in edx
jmp .write
.zero:
mov byte [ecx], '0'
mov edx, 1 ; length
.write:
mov eax, 4 ; write
mov ebx, 1 ; stdout
int 0x80
add esp, 12 ; restore stack
popad ; restore regs
ret

3
08/Makefile Normal file
View File

@@ -0,0 +1,3 @@
all:
nasm -g -felf32 main.s && ld -melf_i386 -g main.o

732
08/input Normal file
View File

@@ -0,0 +1,732 @@
LLLLLLLRRRLRRRLRLRLRLRRLLRRRLRLLRRRLLRRLRRLRRLRLRRLRLRRRLRRLRLRRRLRRLRRLRLRRLLRLLRLRRRLRRLRLLLLRRLLLLRLRLRLRRRLRLRLLLRLRRRLRRRLRRRLRLRRLRRRLRLLLRLLRRLRRRLRRLRRLRRLRLRRRLRLRLRLLRRRLRRRLRRLRRRLLLRRLRRLRRRLRLRRRLRRRLRLRRLRRRLRLRRLRLRRLRRRLRLRRLRLLRRRLLRLRRLRRRLLLRLRRLRRRR
DGK = (KVQ, XHR)
KTC = (TVB, MTH)
CGR = (VVK, BKP)
LCG = (FQC, KHX)
PSZ = (FSF, QSM)
FBJ = (FHP, SPX)
KJD = (NRQ, VDH)
NCM = (JPJ, KNG)
TXH = (HNK, VHQ)
NND = (TRC, DFM)
JQN = (CNX, XLD)
RHB = (CDG, GBT)
JBN = (PXV, GVN)
DFC = (JRN, TXH)
TXG = (CHT, VBL)
XXQ = (JDC, JGV)
SVF = (FVD, LHQ)
FVK = (LCG, RNB)
XKT = (MPF, XJJ)
MHB = (JSJ, VQM)
FVC = (HXF, VVN)
JJR = (VNS, SLM)
RMT = (GDS, XHP)
CHT = (PXS, VLF)
SFJ = (XGC, LPM)
BJL = (XDN, VXN)
PQK = (NHS, DVB)
PDB = (JPQ, TVJ)
RGL = (DNN, NCN)
KRN = (SBL, PHL)
MTF = (PJL, KQR)
BTL = (CCF, LDP)
NLV = (CPM, HVL)
GCQ = (QMF, JVH)
KVH = (VKD, PQG)
RLB = (GSS, JVP)
QRB = (TNL, DKN)
JFV = (RDR, NSB)
BFC = (LGH, XLX)
HGQ = (SLM, VNS)
FQC = (VFQ, BXC)
DDS = (XHR, KVQ)
VQV = (SFT, BFQ)
XFD = (HVV, FLH)
TVP = (XQF, KSS)
GBH = (NPX, LDB)
KHL = (MGS, MMD)
NPX = (BJL, SFF)
VMG = (DHX, GVC)
RTJ = (XRF, BPK)
TLM = (NCG, QBB)
LXS = (TVB, MTH)
XNM = (QFL, KQK)
KQR = (QRD, JBN)
JQD = (DNN, NCN)
QCF = (MXL, MXL)
QMH = (NKG, SDJ)
NKK = (MCB, RLB)
MPJ = (BTL, JTF)
TLS = (VPJ, LMD)
XJB = (LML, TKZ)
HGF = (HBF, QHB)
KNJ = (QKM, XLR)
XCF = (QCJ, HTN)
HFS = (NKC, JFV)
QLS = (QBB, NCG)
QFL = (NXQ, QBN)
MTH = (FLN, LQR)
VND = (KMM, MQH)
NQQ = (VVH, NDL)
BTV = (QSM, FSF)
SLT = (NRQ, VDH)
NKG = (TBV, XCV)
SLM = (LBN, HPK)
CMQ = (KKS, VBH)
JTF = (LDP, CCF)
VFC = (GKH, KPS)
KCC = (JVM, MTF)
KFP = (MVX, NMX)
NQF = (QSK, KCC)
GGC = (VBV, TJR)
QQS = (NKK, NQC)
LXK = (FXC, QBC)
DVQ = (TFF, LKB)
PBL = (BGQ, FHQ)
KHV = (BVJ, XSD)
LDB = (SFF, BJL)
RJG = (LJB, CJM)
RCX = (QTB, PPL)
FLH = (HSX, KVX)
XTV = (HST, VCC)
GDC = (CMH, NCT)
RDP = (FKR, GHJ)
NXM = (PVV, KRX)
SCQ = (MFN, GRB)
MRT = (XGT, VLK)
DHJ = (XHP, GDS)
XFL = (TJK, QMH)
XQF = (CCQ, RPH)
CLV = (CKD, CCD)
CMT = (NCD, XDM)
NCT = (SXG, CLF)
JSS = (GMJ, LJC)
TLQ = (CRC, DXQ)
DMJ = (HHB, DRV)
JBH = (FVC, HDX)
QXK = (QSB, JBH)
DQN = (QMD, GDN)
SDH = (PRH, BCX)
QSB = (HDX, FVC)
MTP = (VVG, SPN)
CTM = (MFG, GGJ)
HND = (MNV, TXG)
MJS = (DMJ, QQG)
JNL = (LKB, TFF)
QLL = (FKM, HNH)
PNM = (PQR, NRL)
VSF = (LPM, XGC)
QBC = (QQS, MVF)
BFM = (FBP, BQJ)
KNG = (RTJ, CXN)
VFQ = (HFS, LBS)
LKB = (QVB, TXF)
KQD = (CDJ, CDJ)
ZZZ = (DHJ, RMT)
XKX = (HVP, NJF)
GSL = (QMS, DHM)
PNT = (CDJ, GJZ)
KBN = (CMQ, JBG)
DNX = (SFM, GFJ)
NMX = (XRR, LKL)
VPJ = (PSK, GQL)
XQD = (QCF, QCF)
HRM = (RHB, XXJ)
LCL = (MRT, FMB)
DRG = (RNB, LCG)
BKP = (QLL, MMQ)
FSF = (SLR, XGV)
KHX = (BXC, VFQ)
SXG = (NHL, KGK)
MJD = (TDH, RFP)
NRL = (CSG, MPT)
FBP = (QGC, GXH)
HDT = (LHQ, FVD)
BMP = (RMG, JXM)
NCN = (SLT, KJD)
NXQ = (JPP, QQL)
NGV = (HNJ, VVQ)
NPN = (MXL, NJK)
FVD = (XBQ, NKF)
GQM = (QCG, GGC)
QBP = (XML, HND)
VQT = (BTL, JTF)
HKP = (CMH, NCT)
JHP = (NDL, VVH)
FRL = (SHD, FNH)
FLN = (NVL, HGF)
MXH = (QSD, KKR)
BGL = (XCX, RFC)
RSQ = (MKH, TLS)
VML = (RJM, CXK)
XHP = (MJS, DNP)
GRV = (XRN, TVQ)
GKH = (BCF, VSD)
SPH = (MVX, NMX)
TLD = (LFR, GFQ)
LML = (QKS, NND)
PKT = (VXC, CMF)
LLQ = (THT, GRV)
CKD = (SPB, QDV)
KRM = (JQV, JNG)
RNS = (HJJ, MLV)
FKR = (FKK, BHN)
XNH = (SCQ, KLF)
GDN = (LBL, FHT)
CRB = (NHQ, QRB)
JKQ = (DPT, KBN)
NJF = (RJG, NGF)
NRT = (NSK, CSL)
LJR = (VTT, HCQ)
HLK = (DFC, DPV)
PQR = (MPT, CSG)
DNF = (NJF, HVP)
MPV = (HJD, XSF)
TBV = (XTJ, SVH)
LKX = (XFJ, HBM)
KTP = (CGR, RVR)
HVL = (BJH, QXK)
GJD = (XJJ, MPF)
HLC = (VVQ, HNJ)
JTX = (NCD, XDM)
CSG = (MFF, RKT)
PCH = (PGJ, GQM)
SFF = (VXN, XDN)
TCF = (KNG, JPJ)
LDP = (XFD, SBS)
XCR = (GJD, XKT)
QBM = (GFB, LRH)
CLP = (RJM, CXK)
MTT = (HST, VCC)
TQL = (BPM, GGT)
LFR = (HNF, RDP)
JHN = (CMT, JTX)
XCX = (CHG, CHG)
XGT = (HLK, QJF)
TQS = (TKL, MNF)
KFL = (HGQ, JJR)
LHQ = (XBQ, NKF)
CCQ = (DBP, HHC)
TKL = (VDN, PBP)
LBX = (BXM, SDH)
XLX = (NGJ, LHJ)
GVN = (BPG, TNK)
CCX = (HCQ, VTT)
KQK = (QBN, NXQ)
NQC = (MCB, RLB)
MPF = (DFT, SBG)
BNH = (MLV, HJJ)
CJM = (LBH, TNM)
CND = (VKB, PGQ)
HXM = (GMJ, LJC)
TKZ = (NND, QKS)
RKT = (LNQ, KFL)
GXH = (RQP, LBX)
TFF = (QVB, TXF)
LNK = (FDC, MXH)
KPK = (BNH, RNS)
QQG = (HHB, DRV)
MFP = (PQK, NBF)
VVK = (QLL, MMQ)
GFB = (RHN, LCN)
PPD = (QCJ, HTN)
FXV = (BPM, GGT)
KSS = (CCQ, RPH)
KCM = (LTB, PCH)
RHN = (FXV, TQL)
LFV = (DDJ, NQF)
JKG = (BGQ, FHQ)
MBS = (RQJ, LDQ)
HHC = (NGV, HLC)
CCD = (QDV, SPB)
RFM = (FTB, HSB)
QCG = (VBV, TJR)
GRH = (LXK, LGQ)
CDJ = (QQJ, BFC)
THT = (TVQ, XRN)
QRD = (PXV, GVN)
VHQ = (SXV, GJL)
MLV = (VRM, MCP)
XRR = (CLV, PBJ)
NMS = (DGK, DDS)
JPS = (JKT, KHL)
DJJ = (QMS, DHM)
MFG = (TLQ, VQD)
GPQ = (SHL, BNR)
QVB = (GDC, HKP)
LNN = (CMF, VXC)
VBQ = (LNN, PKT)
MMS = (SVV, HRM)
BGJ = (HXM, JSS)
QCK = (JSJ, VQM)
PKB = (XNH, JQH)
BCF = (TQR, TLL)
JRN = (VHQ, HNK)
SHL = (DMK, JBX)
LRG = (NSK, CSL)
NJV = (FJH, TXC)
GHQ = (FSB, HFX)
LHN = (TLS, MKH)
HBF = (BMP, GLM)
DTP = (DVQ, JNL)
FXR = (FTB, HSB)
PDS = (XLD, CNX)
SXV = (CPC, JNF)
QMF = (GGF, JDP)
JVP = (GPC, DNX)
RMG = (HRF, PKB)
LRH = (LCN, RHN)
HVP = (RJG, NGF)
TRC = (VKX, RQL)
PJL = (QRD, JBN)
HNK = (GJL, SXV)
CHM = (NBF, PQK)
PGH = (KMM, MQH)
SDN = (MFP, CHM)
DMK = (VRP, NNX)
MRR = (NGK, SMQ)
QDV = (NDM, JPT)
PGJ = (QCG, GGC)
BVJ = (NLV, HBR)
PGQ = (BGK, GBH)
LKL = (CLV, PBJ)
FDC = (KKR, QSD)
JDP = (PDB, PTX)
NJJ = (HSJ, GRH)
TVJ = (HDT, SVF)
NJK = (RBV, ZZZ)
HHN = (DPP, TLD)
QMS = (BLS, TQS)
QVR = (CVB, BNJ)
FFQ = (RMJ, HGZ)
LGQ = (QBC, FXC)
JPP = (RSG, KTG)
DPV = (TXH, JRN)
HBR = (CPM, HVL)
NSK = (JQN, PDS)
SBS = (HVV, FLH)
BFQ = (VBQ, JPB)
LBN = (LXJ, CCR)
RBD = (KRM, PNX)
NQX = (LML, LML)
XSA = (QKS, NND)
NDB = (HFX, FSB)
QMD = (LBL, FHT)
XTJ = (JDT, JDT)
GLH = (SHL, BNR)
FXC = (MVF, QQS)
HSX = (NFN, LVG)
JNF = (JJH, FNR)
CXK = (SPC, TVP)
GGF = (PDB, PTX)
XBQ = (QNX, JCQ)
LJC = (SFJ, VSF)
MMD = (XLK, CND)
HFG = (JKT, KHL)
NHQ = (TNL, DKN)
JVM = (KQR, PJL)
CGH = (RTC, VFC)
HNF = (GHJ, FKR)
TMF = (NMS, GJH)
NGJ = (NXM, BDB)
MRM = (JKQ, MPS)
QTC = (JSS, HXM)
TNM = (JFF, QXR)
DHK = (LJR, CCX)
XSB = (MRR, CXC)
XRN = (XDP, QBP)
XCV = (XTJ, SVH)
VVA = (QSM, FSF)
NKC = (RDR, NSB)
MXL = (RBV, RBV)
PTX = (TVJ, JPQ)
VRL = (NQX, XJB)
RQK = (MPS, JKQ)
PBJ = (CKD, CCD)
VRP = (DQN, QLC)
KLF = (MFN, GRB)
XXJ = (GBT, CDG)
HST = (QHV, MMS)
SFT = (JPB, VBQ)
NRR = (LCL, MQR)
CSL = (JQN, PDS)
LHJ = (BDB, NXM)
TXK = (DHK, KLC)
CDK = (XCX, XCX)
FHT = (NGQ, JHN)
QQJ = (LGH, XLX)
BQJ = (GXH, QGC)
TTA = (QKM, XLR)
TVB = (FLN, LQR)
PPL = (FRL, NCX)
SPS = (XFJ, HBM)
SVH = (JDT, VRL)
QBB = (PXG, MTP)
JSJ = (VVB, NRR)
KKS = (RGL, JQD)
JDT = (NQX, NQX)
GKQ = (LLT, JRH)
VVH = (BPT, KRN)
JCQ = (CRB, PBS)
QXR = (BTV, PSZ)
VQR = (RCX, KKP)
QSM = (SLR, XGV)
JKD = (JDC, JGV)
XLD = (LFS, QVR)
TJK = (NKG, SDJ)
PVV = (HDK, VQV)
BDB = (PVV, KRX)
MPS = (KBN, DPT)
FHP = (PPD, XCF)
HTN = (KCM, PXC)
GHJ = (BHN, FKK)
JCC = (LQM, KVH)
LQR = (HGF, NVL)
LGM = (DDJ, NQF)
NJN = (QCF, NPN)
PRH = (DFF, DFF)
XDM = (FBJ, PJM)
HFN = (KRS, XSB)
GLM = (JXM, RMG)
RQP = (BXM, SDH)
BPG = (QJT, KTP)
JPB = (LNN, PKT)
DKN = (CJD, BGR)
CDG = (GSL, DJJ)
XDN = (CGM, VMG)
NQP = (SKT, JCC)
DNP = (QQG, DMJ)
NNX = (DQN, QLC)
FTB = (JFL, VJJ)
FHQ = (SMJ, XFK)
GGT = (KPK, LNT)
NGF = (LJB, CJM)
QFX = (KCN, TMF)
NKF = (JCQ, QNX)
DBP = (NGV, HLC)
RBV = (RMT, DHJ)
NML = (MBV, VCG)
KXJ = (MXH, FDC)
GFQ = (RDP, HNF)
SHD = (CMG, CTM)
GTX = (LNK, KXJ)
HXF = (KTC, LXS)
CMM = (NQP, SBR)
SDJ = (TBV, XCV)
CHG = (RMJ, RMJ)
DPT = (CMQ, JBG)
BGR = (RLM, NML)
THM = (XQD, NJN)
HJJ = (MCP, VRM)
NRQ = (JHR, GCQ)
KKR = (HSN, NJJ)
KVX = (LVG, NFN)
LTT = (TLD, DPP)
NVL = (QHB, HBF)
CXN = (XRF, BPK)
KLC = (CCX, LJR)
JDC = (DNF, XKX)
MGS = (XLK, CND)
RLM = (VCG, MBV)
VDN = (NMQ, TPR)
HSB = (JFL, VJJ)
HDS = (KLC, DHK)
XSD = (NLV, HBR)
HJD = (NJQ, PBQ)
CGM = (DHX, GVC)
LDQ = (PBL, JKG)
RDR = (XHQ, MGQ)
GPC = (GFJ, SFM)
NQT = (KRS, XSB)
TDH = (RBD, XLP)
QJF = (DFC, DPV)
VNS = (HPK, LBN)
QSD = (NJJ, HSN)
JHR = (QMF, JVH)
SMQ = (FXR, RFM)
CMG = (MFG, GGJ)
NKQ = (VFC, RTC)
VXC = (LHN, RSQ)
DHX = (LCT, XNM)
TCX = (NQT, HFN)
DRV = (TFN, QBM)
JPT = (GQX, XCR)
HRF = (JQH, XNH)
MCS = (BGJ, QTC)
PQG = (NCM, TCF)
XHR = (PJK, VPN)
MLX = (PGH, VND)
MKH = (VPJ, LMD)
TJR = (VQT, MPJ)
VLF = (GLG, QFX)
JNG = (KLR, MPV)
HDK = (BFQ, SFT)
HFX = (MLX, SPL)
BXC = (HFS, LBS)
CCT = (GTX, HPT)
VLK = (HLK, QJF)
NCD = (PJM, FBJ)
VGT = (JNL, DVQ)
LMD = (PSK, GQL)
KRX = (HDK, VQV)
QNX = (CRB, PBS)
NJQ = (GHQ, NDB)
TNV = (FBP, BQJ)
GNR = (XQD, NJN)
KKP = (QTB, PPL)
DBX = (KCQ, CPS)
VRM = (TLM, QLS)
LVG = (BRP, NJV)
NHL = (SPS, LKX)
MNV = (VBL, CHT)
PJK = (HHN, LTT)
VBH = (JQD, RGL)
GRB = (NKQ, CGH)
SKT = (KVH, LQM)
TPR = (RXR, KHV)
VVB = (LCL, MQR)
VKX = (MRM, RQK)
LTB = (PGJ, GQM)
QCJ = (KCM, PXC)
BGQ = (SMJ, SMJ)
RCV = (NQQ, JHP)
DHM = (TQS, BLS)
KRS = (CXC, MRR)
JFL = (BLT, PNM)
TXC = (NRT, LRG)
MVX = (LKL, XRR)
QSK = (JVM, MTF)
BGK = (LDB, NPX)
GJZ = (BFC, QQJ)
PXC = (LTB, PCH)
HMQ = (BGJ, QTC)
RXR = (BVJ, XSD)
BXM = (PRH, BCX)
FJH = (LRG, NRT)
GJH = (DGK, DDS)
BPT = (SBL, PHL)
RQL = (RQK, MRM)
SJB = (RQJ, LDQ)
NFN = (NJV, BRP)
MND = (NQQ, JHP)
NMQ = (KHV, RXR)
XGV = (TXK, HDS)
SPC = (KSS, XQF)
RMJ = (SMR, QRS)
CNX = (LFS, QVR)
KLR = (HJD, XSF)
XLP = (KRM, PNX)
LPM = (CMM, PHF)
FNR = (CCT, VTP)
NGQ = (CMT, JTX)
CCR = (BFM, TNV)
LCN = (FXV, TQL)
HVV = (HSX, KVX)
FSB = (MLX, SPL)
GGJ = (TLQ, VQD)
NHS = (DRG, FVK)
RQJ = (PBL, JKG)
VCC = (MMS, QHV)
HDX = (VVN, HXF)
VQM = (NRR, VVB)
TFN = (GFB, LRH)
QRS = (VQR, MDS)
HBM = (VTQ, SDN)
CCF = (SBS, XFD)
VCG = (HMQ, MCS)
NBF = (DVB, NHS)
DVB = (FVK, DRG)
PGB = (TDH, RFP)
XRF = (KFP, SPH)
KMM = (PDJ, GQN)
KTG = (GGQ, HNR)
BJH = (JBH, QSB)
JJH = (CCT, VTP)
LBH = (JFF, JFF)
GLG = (TMF, KCN)
TQR = (THM, GNR)
MQH = (GQN, PDJ)
MQR = (FMB, MRT)
FNH = (CTM, CMG)
SMR = (VQR, MDS)
GDS = (DNP, MJS)
LCT = (KQK, QFL)
VKB = (GBH, BGK)
VTQ = (CHM, MFP)
TNK = (QJT, KTP)
HNJ = (VVS, GCX)
JKT = (MMD, MGS)
PBP = (TPR, NMQ)
CPS = (KNJ, RFZ)
RNB = (KHX, FQC)
CMF = (LHN, RSQ)
HPK = (CCR, LXJ)
MFN = (NKQ, CGH)
HHB = (QBM, TFN)
DDJ = (QSK, KCC)
DFM = (RQL, VKX)
FKM = (GKQ, VJG)
HSJ = (LGQ, LXK)
HPT = (KXJ, LNK)
BNR = (JBX, DMK)
GJL = (CPC, JNF)
DFF = (KCQ, KCQ)
MCB = (GSS, JVP)
CPC = (JJH, FNR)
XLR = (MJK, DSM)
SBG = (JDG, XFL)
XSF = (NJQ, PBQ)
NGK = (RFM, FXR)
HSN = (GRH, HSJ)
LQM = (PQG, VKD)
VXN = (VMG, CGM)
PSK = (VGT, DTP)
JQH = (KLF, SCQ)
RJM = (SPC, TVP)
VSD = (TLL, TQR)
KCN = (GJH, NMS)
QHB = (GLM, BMP)
FMB = (VLK, XGT)
GBT = (DJJ, GSL)
LGH = (NGJ, LHJ)
SLR = (HDS, TXK)
VVQ = (GCX, VVS)
MDS = (RCX, KKP)
KVQ = (VPN, PJK)
CLF = (NHL, KGK)
XFK = (KQD, PNT)
CJD = (NML, RLM)
MCP = (TLM, QLS)
SPL = (PGH, VND)
GSS = (GPC, DNX)
RPH = (DBP, HHC)
HNR = (XXQ, JKD)
VBV = (VQT, MPJ)
PHF = (NQP, SBR)
BRP = (FJH, TXC)
AAA = (RMT, DHJ)
PBQ = (GHQ, NDB)
PXG = (VVG, SPN)
PNX = (JQV, JNG)
XHQ = (SJB, MBS)
VBL = (VLF, PXS)
VVG = (MTT, XTV)
PXS = (GLG, QFX)
MMQ = (FKM, HNH)
PHG = (HFN, NQT)
MFF = (KFL, LNQ)
PJM = (FHP, SPX)
SMJ = (KQD, KQD)
XGC = (CMM, PHF)
PDJ = (QCK, MHB)
SPN = (MTT, XTV)
BPK = (KFP, SPH)
MVF = (NQC, NKK)
LJB = (LBH, LBH)
GQN = (QCK, MHB)
NCG = (MTP, PXG)
GQL = (VGT, DTP)
NCX = (FNH, SHD)
HGZ = (QRS, SMR)
GMJ = (VSF, SFJ)
RFP = (XLP, RBD)
TXF = (GDC, HKP)
NBA = (SMR, QRS)
QTB = (FRL, NCX)
QLC = (GDN, QMD)
QHV = (SVV, HRM)
XTM = (GRV, THT)
VPN = (HHN, LTT)
RFZ = (XLR, QKM)
CMH = (SXG, CLF)
GFJ = (TCX, PHG)
VTT = (LGM, LFV)
RTC = (GKH, KPS)
XFJ = (VTQ, SDN)
GCX = (PGB, MJD)
MJK = (CLP, VML)
QQL = (RSG, KTG)
NSB = (XHQ, MGQ)
HCQ = (LGM, LFV)
GQX = (GJD, XKT)
RVR = (VVK, BKP)
JBG = (KKS, VBH)
JFF = (BTV, BTV)
BPM = (LNT, KPK)
LNQ = (JJR, HGQ)
FKK = (GLH, GPQ)
SBL = (CDK, BGL)
LNT = (BNH, RNS)
JRH = (JPS, HFG)
VVS = (MJD, PGB)
DPP = (LFR, GFQ)
MNF = (PBP, VDN)
QKM = (DSM, MJK)
JPJ = (CXN, RTJ)
QGC = (RQP, LBX)
CVB = (MND, RCV)
RFC = (CHG, FFQ)
KPS = (BCF, VSD)
XML = (MNV, TXG)
JVH = (JDP, GGF)
CRC = (XTM, LLQ)
VJG = (JRH, LLT)
SPB = (JPT, NDM)
JGV = (XKX, DNF)
GGQ = (XXQ, JKD)
XLK = (PGQ, VKB)
JBX = (NNX, VRP)
RSG = (HNR, GGQ)
GVC = (LCT, XNM)
XDP = (XML, HND)
CXC = (SMQ, NGK)
PXV = (TNK, BPG)
NDM = (XCR, GQX)
CPM = (BJH, QXK)
KGK = (LKX, SPS)
BLT = (NRL, PQR)
BHN = (GLH, GPQ)
BLS = (TKL, MNF)
PHL = (CDK, BGL)
BCX = (DFF, DBX)
HNH = (GKQ, VJG)
VKD = (NCM, TCF)
DSM = (VML, CLP)
DNN = (SLT, KJD)
SBR = (SKT, JCC)
TNL = (BGR, CJD)
DFT = (XFL, JDG)
MPT = (RKT, MFF)
TVQ = (XDP, QBP)
LLT = (JPS, HFG)
DXQ = (XTM, LLQ)
SFM = (PHG, TCX)
BNJ = (MND, RCV)
PBS = (NHQ, QRB)
JXM = (HRF, PKB)
VTP = (HPT, GTX)
SVV = (XXJ, RHB)
MHA = (QQJ, BFC)
MBV = (HMQ, MCS)
VJJ = (BLT, PNM)
QJT = (RVR, CGR)
VVN = (LXS, KTC)
QKS = (TRC, DFM)
MGQ = (MBS, SJB)
NDL = (BPT, KRN)
JPQ = (SVF, HDT)
VDH = (JHR, GCQ)
KCQ = (KNJ, KNJ)
XJJ = (DFT, SBG)
JQV = (MPV, KLR)
VQD = (DXQ, CRC)
JDG = (TJK, QMH)
SPX = (XCF, PPD)
LXJ = (TNV, BFM)
LBL = (NGQ, JHN)
QBN = (QQL, JPP)
LFS = (CVB, BNJ)
LBS = (JFV, NKC)
TLL = (THM, GNR)

5
08/input_test Normal file
View File

@@ -0,0 +1,5 @@
LLR
AAA = (BBB, BBB)
BBB = (AAA, ZZZ)
ZZZ = (ZZZ, ZZZ)

10
08/input_test2 Normal file
View File

@@ -0,0 +1,10 @@
LR
DGA = (DGB, XXX)
DGB = (XXX, DGZ)
DGZ = (DGB, XXX)
EHA = (EHB, XXX)
EHB = (EHC, EHC)
EHC = (EHZ, EHZ)
EHZ = (EHB, EHB)
XXX = (XXX, XXX)

207
08/main.s Normal file
View File

@@ -0,0 +1,207 @@
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
cmp eax, 0 ; last is A
jne .d
.idx_a:
mov eax, [used_starts]
mov [curr_ids+eax*4], ebx
inc dword [used_starts]
.d:
inc ebp ; progress state
jmp get_next_id
got_ids:
; set what done is
mov ecx, [used_starts]
mov edi, full_cycled
mov al, 1
rep stosb
mov edx, file
; walk move string
find_move_end:
mov esi, edx ; restore
lodsb
cmp al, 'L'
je .left
cmp al, 'R'
je .right
mov edx, file
jmp find_move_end
.right:
mov edx, esi ; save
mov esi, curr_ids
mov edi, curr_ids
mov ecx, [used_starts]
.right_l:
lodsd
mov eax, [pairs+eax*8+4] ; right
stosd
loop .right_l
jmp check_ZZZ
.left:
mov edx, esi ; save
mov esi, curr_ids
mov edi, curr_ids
mov ecx, [used_starts]
.left_l:
lodsd
mov eax, [pairs+eax*8] ; left
stosd
loop .left_l
check_ZZZ:
; find cycles - i'm sure this is an awful way of doing this
inc dword [final_value]
mov esi, curr_ids
xor ecx, ecx
.zzz_l:
lodsd
cmp eax, 16900
jle .zzz_l_cont ; not Z
; check if this Z and string position in cycles
mov edi, ecx
shl edi, 10 ; *1024
add edi, cycles
.check_cycles:
mov ebx, [edi] ; Z
test ebx, ebx
jz .new_cycle
cmp ebx, eax
jne .check_cycles_cont
cmp edx, [edi+4] ; str pos & cycle str pos
jne .check_cycles_cont
; match, increment count
inc dword [edi+8]
mov byte [starts_cycled+ecx], 1
jmp .zzz_l_cont
.check_cycles_cont:
add edi, 16
jmp .check_cycles
.new_cycle:
mov [edi], eax ; Z
mov [edi+4], edx ; str pos
mov dword [edi+8], 1 ; count
mov eax, [final_value]
mov dword [edi+12], eax ; cycle len
.zzz_l_cont:
inc ecx
cmp ecx, [used_starts]
jl .zzz_l
.cont:
; check if we've seen everything cycle
mov ebx, [starts_cycled]
cmp ebx, [full_cycled]
jne find_move_end
mov ebx, [starts_cycled+4]
cmp ebx, [full_cycled+4]
jne find_move_end
; done, print cycles
xor ecx, ecx
print_cycles:
mov esi, ecx
shl esi, 10 ; *1024
add esi, cycles
.l:
lodsd ; Z
mov ebx, eax
test eax, eax
jz .cont
mov eax, ecx ; Start Num
call print_dec
call space
mov eax, ebx
call print_dec
call space
lodsd ; str pos (skip print)
call print_dec
call space
lodsd ; count
call print_dec
call space
lodsd ; cycle len
call print_dec
call newline
jmp .l
.cont:
inc ecx
cmp ecx, [used_starts]
jl print_cycles
.done:
call newline
; lol go use an online calculator for lcm
game_over:
mov eax, [final_value]
call print_dec
jmp exit
[section .data]
final_value: dd 0
used_starts: dd 0
starts_cycled: dq 0
full_cycled: dq 0
file_lim: dd file.over - file
file: incbin "input"
.over:
[section .bss]
curr_ids: resd 8
cycles: resb 1024*16
pairs: resd 131072

97
08/main_part1.s Normal file
View File

@@ -0,0 +1,97 @@
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

146
08/utils.s Normal file
View File

@@ -0,0 +1,146 @@
; call # val val2
; int $0x80 eax eax edx -
;
; arg1 arg2 arg3 arg4 arg5 arg6 arg7
; ebx ecx edx esi edi ebp -
exit:
mov eax, 1 ; exit
int 0x80
; filename in EBX
; return handle in EBX
; read only
open_file:
push eax
push ecx
mov eax, 5 ; open
xor ecx, ecx ; read only
int 0x80
mov ebx, eax
pop ecx
pop eax
ret
; file handle in EBX
; buffer in ECX
; count of bytes to read in EDX
; return bytes actually read in EAX
; exits on error
read_file:
mov eax, 3 ; read
int 0x80
test eax, eax
js .err
ret
.err:
mov eax, 4 ; write
mov ebx, 1 ; stdout
mov ecx, .err_str
mov edx, 21
int 0x80
jmp exit
.err_str: db `Could not read file.\n`
; string input in ESI
; value in EAX
; CF set if none, clear if some
; ESI set past checked area
dec_parse:
push ebx
push edx
push edi
xor eax, eax
xor edi, edi
mov ebx, 10 ; base
lodsb
sub al, '0'
js .no_input
cmp al, 9
jle .got_char
.no_input:
stc ; set CF
jmp .done
.loop:
xor eax,eax
lodsb
sub al, '0'
js .dec_done
cmp al, 9
jg .dec_done
.got_char:
xchg edi,eax
mul ebx
add edi,eax
jmp .loop
.dec_done:
clc ; clear CF
.done:
mov eax,edi
pop edi
pop edx
pop ebx
ret
; modifies no regs
newline:
pushad
push 10
mov eax, 4 ; write
mov ebx, 1 ; stdout
mov ecx, esp ; string
mov edx, 1 ; length
int 0x80
add esp, 4
popad
ret
; modifies no regs
space:
pushad
push 9
mov eax, 4 ; write
mov ebx, 1 ; stdout
mov ecx, esp ; string
mov edx, 1 ; length
int 0x80
add esp, 4
popad
ret
; input in EAX, all regs unmodified
print_dec:
pushad ; save regs
; max 4294967296 is 10 chars
; round to nearest 32-bit boundary
sub esp, 12
; string in ECX, length in EDX
lea ecx, [esp+11] ; last possible byte
; check for 0
test eax, eax
jz .zero
mov ebx, 10 ; base 10
xor esi, esi ; counter
.div_shit:
xor edx, edx
; divide
div ebx
dec ecx ; next char
inc esi
; store
add dl, '0'
mov byte [ecx], dl
; check if done
test eax, eax
jnz .div_shit ; continue
mov edx, esi ; counter in edx
jmp .write
.zero:
mov byte [ecx], '0'
mov edx, 1 ; length
.write:
mov eax, 4 ; write
mov ebx, 1 ; stdout
int 0x80
add esp, 12 ; restore stack
popad ; restore regs
ret

3
09/Makefile Normal file
View File

@@ -0,0 +1,3 @@
all:
nasm -g -felf32 main.s && ld -melf_i386 -g main.o

200
09/input Normal file
View File

@@ -0,0 +1,200 @@
10 20 37 71 136 258 493 972 2001 4255 9116 19216 39257 77191 145854 265159 464964 788742 1298191 2078933 3247462
28 53 92 163 312 639 1336 2734 5353 9946 17525 29354 46891 71658 105015 147811 199882 259363 321778 378869 417122
10 18 38 85 184 373 706 1256 2118 3412 5286 7919 11524 16351 22690 30874 41282 54342 70534 90393 114512
13 28 45 59 57 23 -46 -115 -83 238 1123 2895 5825 9945 14744 18713 18701 9040 -19607 -81725 -198807
9 5 1 -3 -7 -11 -15 -19 -23 -27 -31 -35 -39 -43 -47 -51 -55 -59 -63 -67 -71
26 53 100 185 338 598 1021 1712 2894 5027 8990 16339 29654 52988 92431 156802 258482 414401 647192 986525 1470634
-4 -3 6 21 48 113 274 633 1348 2645 4830 8301 13560 21225 32042 46897 66828 93037 126902 169989 224064
-1 6 26 68 147 297 599 1238 2613 5546 11682 24255 49539 99573 197307 386506 751211 1454366 2814050 5451042 10566571
2 9 29 70 152 319 651 1276 2382 4229 7161 11618 18148 27419 40231 57528 80410 110145 148181 196158 255920
15 31 62 122 234 426 729 1198 1998 3624 7357 16097 35759 77469 160854 318783 603985 1098045 1923360 3258724 5359304
3 4 -4 -16 -18 27 213 757 2116 5181 11581 24137 47513 89118 160320 278040 466801 761314 1209690 1877374 2851904
15 27 41 61 100 186 371 743 1441 2673 4737 8045 13150 20776 31851 47543 69299 98887 138441 190509 258104
21 29 33 34 38 64 171 522 1518 4057 10016 23160 50945 108288 225665 466447 963131 1990517 4108079 8426882 17092752
-7 -5 2 14 31 53 80 112 149 191 238 290 347 409 476 548 625 707 794 886 983
10 17 27 56 134 313 694 1483 3095 6345 12801 25432 49772 95968 182400 342397 637759 1188072 2236418 4295587 8463149
16 26 36 46 56 66 76 86 96 106 116 126 136 146 156 166 176 186 196 206 216
22 32 38 47 92 253 688 1684 3744 7738 15173 28689 52972 96396 173887 311842 556735 991041 1764922 3162971 5748235
10 20 37 70 137 283 611 1333 2870 6079 12774 26866 56747 120143 253858 533128 1109490 2283314 4639099 9290554 18311365
13 15 18 37 104 283 699 1588 3387 6912 13742 27077 53633 107690 219414 451350 930029 1904693 3853286 7668565 14976442
11 32 72 156 326 653 1254 2309 4071 6863 11062 17095 25560 37842 58254 100287 202979 470554 1162628 2889018 7011602
13 22 47 109 238 475 888 1618 2992 5779 11726 24597 52051 108836 221945 438576 837959 1548356 2770801 4811421 8124460
25 46 86 154 255 397 609 970 1649 2956 5404 9782 17239 29379 48367 77046 119065 179018 262594 376738 529823
18 27 36 45 54 63 72 81 90 99 108 117 126 135 144 153 162 171 180 189 198
-5 -6 0 20 66 157 314 553 892 1400 2324 4324 8811 18299 36524 67821 114849 173174 220416 196588 -29152
4 3 2 1 0 -1 -2 -3 -4 -5 -6 -7 -8 -9 -10 -11 -12 -13 -14 -15 -16
7 22 56 133 292 603 1198 2319 4389 8129 14795 26724 48601 90277 172780 340808 688379 1411160 2912394 6014571 12374722
11 15 21 27 46 129 409 1190 3131 7622 17519 38503 81470 166580 329955 634616 1188227 2171761 3885569 6822835 11785430
12 14 25 56 118 222 379 600 896 1278 1757 2344 3050 3886 4863 5992 7284 8750 10401 12248 14302
-4 3 24 64 128 221 348 514 724 983 1296 1668 2104 2609 3188 3846 4588 5419 6344 7368 8496
12 20 21 22 45 128 336 807 1868 4276 9692 21622 47322 101659 214780 446844 915248 1843016 3641675 7048442 13346399
-5 10 50 128 271 527 974 1750 3140 5775 11022 21689 43277 86280 170677 335205 657045 1293576 2569118 5149622 10382351
7 17 56 145 325 674 1334 2562 4822 8938 16348 29563 53093 95469 173831 324424 626309 1253519 2585836 5435109 11489697
3 15 55 133 252 421 679 1127 1970 3591 6720 12824 24925 49143 97346 191350 369125 693399 1262877 2225967 3796386
9 19 42 86 170 328 625 1195 2311 4497 8692 16476 30368 54206 93619 156601 254197 401311 617646 928786 1367430
11 8 15 39 82 147 265 563 1406 3673 9274 22088 49607 105714 215210 420942 794677 1453222 2581713 4466493 7540576
13 25 60 142 312 634 1201 2141 3623 5863 9130 13752 20122 28704 40039 54751 73553 97253 126760 163090 207372
1 21 57 109 187 319 553 951 1573 2457 3621 5159 7620 13150 28536 72642 193269 502929 1250405 2956629 6661117
8 18 41 89 189 388 758 1401 2454 4094 6543 10073 15011 21744 30724 42473 57588 76746 100709 130329 166553
5 11 20 30 38 47 94 314 1059 3095 7904 18122 38148 74963 139202 246526 419345 688947 1098092 1704134 2582738
-1 3 22 66 155 331 675 1326 2510 4617 8422 15649 30253 61086 127078 266782 555205 1132403 2250514 4348928 8171371
-4 -2 22 82 187 346 595 1054 2020 4106 8451 17059 33400 63594 118963 221791 418320 807190 1598984 3235088 6614221
9 22 33 37 44 99 313 926 2436 5853 13200 28533 60068 124593 256341 524077 1062567 2128324 4195503 8117873 15400320
3 18 55 125 238 405 638 947 1349 1939 3136 6317 15199 38537 95011 221698 488630 1024559 2065280 4049948 7820703
8 19 48 98 180 324 600 1170 2414 5212 11523 25479 55303 116480 236856 465039 885489 1648974 3039687 5628017 10614711
11 11 20 52 134 316 697 1475 3027 6023 11576 21428 38170 65492 108457 173791 270179 408555 602372 867836 1224086
22 42 67 102 173 352 807 1899 4367 9671 20601 42320 84138 162616 307259 571364 1052956 1934724 3558159 6556542 12085011
-4 -10 -17 -23 -19 32 226 754 1950 4391 9151 18410 36763 73771 148554 297553 586992 1132060 2125415 3878295 6878313
6 22 55 123 258 511 969 1803 3369 6386 12216 23268 43543 79353 140352 241358 406296 677422 1136557 1951553 3472424
7 16 25 34 43 52 61 70 79 88 97 106 115 124 133 142 151 160 169 178 187
-2 9 30 61 102 153 214 285 366 457 558 669 790 921 1062 1213 1374 1545 1726 1917 2118
9 22 53 115 233 444 802 1412 2547 4947 10459 23252 51931 112979 236076 471979 903797 1662660 2948961 5060545 8429429
-2 5 13 32 102 304 771 1700 3358 6058 10048 15209 20419 22461 14525 -15185 -83286 -206365 -385589 -570762 -587760
4 22 49 93 172 319 591 1085 1975 3616 6831 13631 28857 63639 142229 314805 680422 1426610 2895445 5690561 10845906
26 44 64 87 118 165 252 470 1101 2877 7490 18561 43416 96222 203359 412496 808058 1538356 2864986 5255597 9560768
15 19 20 17 9 -5 -26 -55 -93 -141 -200 -271 -355 -453 -566 -695 -841 -1005 -1188 -1391 -1615
6 8 15 27 44 66 93 125 162 204 251 303 360 422 489 561 638 720 807 899 996
-7 0 33 109 246 465 796 1288 2023 3134 4827 7407 11308 17127 25662 37954 55333 79468 112421 156705 215346
5 8 12 9 -9 -48 -102 -126 15 626 2294 6033 13461 27006 50136 87606 145713 232548 358232 535121 777963
15 33 70 143 279 516 904 1506 2399 3675 5442 7825 10967 15030 20196 26668 34671 44453 56286 70467 87319
16 30 61 122 232 418 710 1132 1700 2459 3638 6093 12383 29173 72363 177741 422644 969084 2147691 4617244 9660542
7 32 68 127 237 444 814 1435 2419 3904 6056 9071 13177 18636 25746 34843 46303 60544 78028 99263 124805
3 7 18 40 67 92 136 311 947 2838 7697 18956 43105 91835 185335 357193 661467 1182625 2049204 3452208 5669455
25 44 65 99 177 365 789 1670 3369 6442 11705 20309 33825 54339 84557 127920 188729 272280 385009 534647 730385
19 26 31 46 102 256 602 1285 2509 4524 7573 11775 16914 22110 25414 23633 13518 -2249 5102 148485 777449
15 16 13 14 42 143 399 954 2069 4233 8369 16197 30897 58483 111035 214682 428973 891784 1918347 4209978 9277526
13 20 20 21 47 157 480 1283 3104 6997 14951 30560 60036 113672 207877 367920 631535 1053554 1711750 2714087 4207589
15 29 58 105 176 297 542 1073 2208 4560 9342 19048 38969 80502 168149 353813 745089 1559867 3229842 6594307 13259578
22 48 101 193 341 580 985 1718 3129 5953 11658 23012 44950 85835 159220 286231 498704 843222 1386211 2220267 3471899
17 43 84 150 266 493 964 1937 3876 7604 14642 27966 53588 103601 201621 391904 753799 1423597 2626220 4719522 8254194
3 8 15 25 42 73 128 220 365 582 893 1323 1900 2655 3622 4838 6343 8180 10395 13037 16158
0 4 13 36 107 306 786 1820 3910 8047 16280 32843 66199 132483 260953 502177 939780 1706630 3006335 5140830 8544627
17 31 52 89 164 317 613 1155 2114 3805 6884 12838 25117 51549 109127 232908 491671 1014203 2031684 3943695 7417954
0 12 47 126 277 535 942 1547 2406 3582 5145 7172 9747 12961 16912 21705 27452 34272 42291 51642 62465
24 28 36 69 160 357 738 1451 2795 5371 10378 20257 40197 81697 170733 365567 793490 1722634 3695420 7765381 15900254
15 29 46 65 85 116 195 406 914 2047 4502 9816 21336 46048 97789 202573 407017 791161 1487342 2707211 4779479
-8 -8 11 63 162 322 557 881 1308 1852 2527 3347 4326 5478 6817 8357 10112 12096 14323 16807 19562
2 15 44 97 202 427 917 1969 4181 8742 17987 36448 72841 143834 281192 545212 1049548 2005985 3802966 7139347 13245732
20 40 70 115 180 270 390 545 740 980 1270 1615 2020 2490 3030 3645 4340 5120 5990 6955 8020
17 34 63 115 211 381 662 1102 1796 3008 5476 11072 24124 53941 119465 257567 537379 1084294 2118965 4018897 7413169
21 27 33 39 45 51 57 63 69 75 81 87 93 99 105 111 117 123 129 135 141
24 51 101 179 288 430 608 833 1151 1727 3056 6413 14699 33885 75332 159512 322466 628597 1198855 2275141 4364978
-4 -5 -8 -16 -25 -22 23 181 625 1782 4704 11929 29352 70027 161429 358584 766698 1578565 3134200 6012926 11171653
23 52 96 166 280 474 835 1562 3062 6107 12130 23838 46483 90373 175539 339916 652961 1237334 2302124 4192126 7458882
9 34 74 145 277 521 975 1849 3602 7201 14572 29335 57938 111328 207319 373837 653239 1107916 1827398 2937181 4609491
3 12 32 72 163 375 843 1805 3666 7121 13388 24604 44408 78687 136500 231653 387061 648502 1124596 2090896 4236081
9 18 28 44 80 159 313 583 1019 1680 2634 3958 5738 8069 11055 14809 19453 25118 31944 40080 49684
11 7 -4 -26 -63 -119 -198 -304 -441 -613 -824 -1078 -1379 -1731 -2138 -2604 -3133 -3729 -4396 -5138 -5959
4 -1 5 47 169 441 977 1989 3928 7803 15823 32575 67033 135789 268007 512725 949268 1701687 2958305 4997631 8222097
23 40 81 164 307 524 817 1162 1488 1660 1511 1035 964 4118 18149 60609 167669 408312 906429 1873974 3659193
6 21 41 66 96 131 171 216 266 321 381 446 516 591 671 756 846 941 1041 1146 1256
6 12 31 73 149 281 522 989 1914 3722 7156 13492 24927 45285 81275 144656 255822 449520 783661 1352483 2305681
24 50 98 177 293 443 619 852 1355 2873 7429 19789 50192 119274 266804 567130 1156623 2282814 4392942 8294246 15445454
16 33 50 60 67 115 334 1019 2771 6753 15172 32234 66103 132923 264851 525427 1037598 2032417 3929906 7467776 13898495
16 42 79 127 186 256 337 429 532 646 771 907 1054 1212 1381 1561 1752 1954 2167 2391 2626
1 19 47 92 174 329 612 1100 1895 3127 4957 7580 11228 16173 22730 31260 42173 55931 73051 94108 119738
19 47 99 179 283 403 541 749 1221 2466 5598 12825 28378 60532 126285 262133 548051 1158840 2470367 5273260 11192757
8 27 65 145 302 583 1047 1765 2820 4307 6333 9017 12490 16895 22387 29133 37312 47115 58745 72417 88358
5 12 20 23 7 -39 -89 -18 489 2054 5742 13205 26819 49795 86241 141148 220269 329856 476216 665043 900479
5 0 -5 -10 -15 -20 -25 -30 -35 -40 -45 -50 -55 -60 -65 -70 -75 -80 -85 -90 -95
11 21 33 64 139 295 591 1124 2051 3617 6189 10296 16675 26323 40555 61068 90011 130061 184505 257328 353307
13 38 84 164 296 503 813 1259 1879 2716 3818 5238 7034 9269 12011 15333 19313 24034 29584 36056 43548
22 34 46 58 70 82 94 106 118 130 142 154 166 178 190 202 214 226 238 250 262
-7 -15 -14 22 139 406 918 1803 3246 5560 9359 15921 27870 50355 92961 172652 318119 575987 1019424 1759792 2962085
2 13 30 53 82 117 158 205 258 317 382 453 530 613 702 797 898 1005 1118 1237 1362
6 6 1 0 26 115 324 767 1719 3872 8903 20631 47207 105007 225192 464270 920452 1758146 3243589 5795386 10054616
13 34 67 112 169 238 319 412 517 634 763 904 1057 1222 1399 1588 1789 2002 2227 2464 2713
7 17 32 56 110 241 546 1240 2827 6492 14946 34166 76844 169001 362308 756457 1538847 3053479 5918108 11219488 20832434
18 40 84 171 344 680 1314 2490 4654 8604 15712 28233 49716 85532 143534 234864 374922 584512 891180 1330759 1949136
4 13 26 54 124 283 606 1212 2302 4257 7882 14972 29534 60259 125242 260546 535056 1075237 2104970 4007674 7420520
0 12 35 77 163 350 760 1659 3624 7855 16705 34518 68883 132431 245322 438590 758536 1272382 2075423 3299939 5126155
9 4 11 45 124 269 504 856 1355 2034 2929 4079 5526 7315 9494 12114 15229 18896 23175 28129 33824
15 24 39 67 126 267 602 1352 2953 6292 13185 27255 55430 110392 214551 406675 753543 1371592 2468747 4426635 7961898
4 2 0 -2 -4 -6 -8 -10 -12 -14 -16 -18 -20 -22 -24 -26 -28 -30 -32 -34 -36
26 47 84 156 301 596 1196 2405 4805 9500 18596 36156 70078 135716 262733 507871 978412 1874633 3565304 6719300 12530091
12 24 54 110 200 332 514 754 1060 1440 1902 2454 3104 3860 4730 5722 6844 8104 9510 11070 12792
12 28 56 101 169 267 403 586 826 1134 1522 2003 2591 3301 4149 5152 6328 7696 9276 11089 13157
26 52 85 120 152 176 187 180 150 92 1 -128 -300 -520 -793 -1124 -1518 -1980 -2515 -3128 -3824
10 11 8 0 -6 25 199 766 2230 5506 12142 24639 46926 85082 148445 251311 415506 674213 1077556 1700586 2654482
13 34 70 139 269 498 874 1455 2309 3514 5158 7339 10165 13754 18234 23743 30429 38450 47974 59179 72253
-1 9 35 79 133 188 257 412 835 1883 4167 8645 16729 30406 52373 86186 136423 208861 310667 450603 639245
17 41 74 122 199 327 536 864 1357 2069 3062 4406 6179 8467 11364 14972 19401 24769 31202 38834 47807
9 21 48 101 216 477 1048 2227 4562 9109 17963 35253 68859 133181 253365 471467 855111 1509269 2591858 4333909 7065114
12 23 35 43 42 27 -7 -65 -152 -273 -433 -637 -890 -1197 -1563 -1993 -2492 -3065 -3717 -4453 -5278
4 27 78 174 340 626 1138 2085 3844 7045 12678 22224 37812 62404 100010 155935 237060 352159 512254 731010 1025172
4 13 33 84 210 495 1090 2263 4498 8699 16620 31771 61284 119630 235790 466776 922862 1814771 3542949 6869036 13249340
8 26 59 113 190 287 395 498 572 584 491 239 -238 -1019 -2197 -3880 -6192 -9274 -13285 -18403 -24826
-4 -4 -6 -7 8 74 268 757 1878 4240 8802 16809 29338 45989 61923 62014 10540 -164690 -591588 -1463327 -2996076
17 35 75 159 330 661 1269 2347 4236 7573 13583 24661 45568 85944 165612 325670 651297 1317646 2679888 5444771 10986614
8 -2 -14 -16 13 102 287 607 1096 1773 2643 3768 5613 10260 24999 71777 209912 586780 1543972 3827672 8985725
7 20 44 95 205 420 797 1413 2418 4193 7728 15447 32933 72430 159738 347326 738365 1529174 3081576 6042235 11533609
26 39 57 85 129 200 336 656 1465 3434 7888 17274 36026 72463 143365 285005 578508 1204697 2555819 5451107 11533191
13 23 46 100 220 466 952 1924 3923 8072 16530 33168 64554 121421 221041 391634 681829 1182870 2081976 3788119 7217192
8 11 23 55 118 223 381 603 900 1283 1763 2351 3058 3895 4873 6003 7296 8763 10415 12263 14318
11 10 8 11 38 144 467 1318 3345 7830 17249 36378 74510 149815 297604 585376 1139263 2189254 4145086 7722105 14148550
14 31 65 122 215 371 647 1163 2167 4173 8268 16793 34833 73459 156777 337172 727776 1569946 3369277 7160753 15008435
3 -1 -3 7 44 140 368 882 1988 4274 8838 17656 34129 63877 116032 205914 361679 641582 1177435 2278540 4667900
22 36 50 64 78 92 106 120 134 148 162 176 190 204 218 232 246 260 274 288 302
21 41 69 102 149 248 496 1113 2570 5824 12727 26725 54076 106085 203462 385178 726643 1376443 2628377 5057688 9769271
5 6 22 82 242 602 1340 2789 5609 11145 22109 43772 85890 165603 311535 569326 1009005 1735416 2905408 4761994 7710738
-4 -1 11 43 116 278 635 1401 2989 6204 12670 25736 52271 105985 213212 422472 819602 1550821 2856781 5121465 8940734
1 17 53 124 251 466 819 1396 2371 4129 7511 14246 27649 53678 102457 190386 342973 598537 1012945 1665560 2666591
5 3 7 34 110 265 529 928 1485 2248 3394 5503 10195 21572 49525 117419 279897 663345 1555197 3594368 8162992
-3 0 9 44 154 430 1025 2202 4457 8817 17521 35497 73406 153605 321269 664205 1346701 2665206 5136873 9636170 17600042
26 36 40 34 26 45 141 382 865 1779 3612 7712 17628 42003 100292 233247 520944 1112098 2269468 4437210 8336970
11 22 48 104 213 415 797 1559 3131 6356 12754 24882 46805 84693 147559 248153 404027 638786 983540 1478572 2175237
3 -2 2 27 85 187 342 556 831 1164 1546 1961 2385 2785 3118 3330 3355 3114 2514 1447 -211
7 25 46 76 146 338 823 1924 4245 8950 18334 36901 73252 143189 274559 514495 939859 1671855 2895958 4888498 8051446
11 23 43 88 196 447 998 2154 4523 9340 19093 38643 77100 150798 287804 534499 964883 1693381 2892063 4813338 7819340
28 43 55 67 91 152 298 618 1281 2635 5444 11390 24026 50442 104017 208809 406434 766779 1404685 2505957 4367877
16 20 32 73 188 451 975 1947 3724 7055 13547 26593 53172 107293 216507 434016 860656 1683594 3242022 6134261 11384820
0 9 27 51 91 193 474 1179 2781 6159 12904 25827 49806 93284 171184 311119 567389 1053195 2014554 3997163 8214564
9 4 -4 -15 -28 -43 -55 -35 106 576 1795 4541 10179 21017 40850 75773 135367 234388 395118 650569 1048766
12 16 12 -1 -12 20 195 716 1960 4606 9889 20130 39850 78077 153037 301569 597876 1190624 2375630 4736161 9408360
17 32 55 86 125 172 227 290 361 440 527 622 725 836 955 1082 1217 1360 1511 1670 1837
11 32 76 159 308 575 1062 1968 3678 6923 13049 24442 45165 81872 145073 250833 422997 696042 1118666 1758233 2706202
24 29 36 62 142 335 742 1545 3076 5935 11208 20908 38898 72785 137634 262883 504592 966185 1832204 3421354 6267350
24 40 70 124 206 308 399 407 207 -337 -1167 -1462 1623 15403 55992 155459 373042 811978 1643872 3142928 5732796
7 19 38 66 100 127 119 28 -219 -725 -1628 -3106 -5382 -8729 -13475 -20008 -28781 -40317 -55214 -74150 -97888
11 16 21 41 118 330 795 1665 3115 5354 8722 13992 23069 40361 75173 145540 284055 546816 1028571 1892639 3437572
3 3 -2 -12 -27 -47 -72 -102 -137 -177 -222 -272 -327 -387 -452 -522 -597 -677 -762 -852 -947
4 -3 -11 -4 45 183 495 1134 2380 4781 9514 19292 40529 88215 196295 438677 969908 2100949 4435671 9109592 18196677
16 23 43 83 144 225 340 564 1146 2762 7029 17462 41130 91354 191890 383153 731164 1340041 2369007 4055053 6742572
9 37 82 143 223 349 600 1135 2224 4314 8207 15490 29468 57117 113263 229863 476947 1009231 2166432 4680165 10082197
23 28 24 8 -13 -7 99 437 1237 2931 6400 13489 27984 57361 115840 229729 446943 854290 1609180 2997634 5538965
18 30 46 76 135 243 425 711 1136 1740 2568 3670 5101 6921 9195 11993 15390 19466 24306 30000 36643
-6 -3 6 20 44 109 307 843 2116 4861 10416 21237 41910 81180 156069 300223 580630 1130545 2213210 4343166 8513688
-2 10 33 60 92 154 317 735 1719 3884 8419 17551 35329 69021 131897 249438 474097 920744 1849917 3856561 8281901
9 34 84 174 323 554 894 1374 2029 2898 4024 5454 7239 9434 12098 15294 19089 23554 28764 34798 41739
14 32 61 103 160 234 327 441 578 740 929 1147 1396 1678 1995 2349 2742 3176 3653 4175 4744
1 12 37 94 219 471 941 1779 3279 6110 11868 24276 51611 111333 238484 500277 1020477 2018768 3872391 7210026 13051283
-7 -12 -14 -8 20 105 331 900 2294 5618 13252 29979 64789 133581 262991 495559 896407 1561528 2627678 4283714 6783026
11 9 21 68 173 357 638 1040 1619 2508 3970 6421 10335 15858 21823 23655 9363 -47589 -200285 -547702 -1264783
17 37 80 150 242 344 442 535 687 1172 2806 7616 20106 49634 114991 253483 539149 1118923 2282576 4593514 9124730
15 31 44 57 81 135 246 449 787 1311 2080 3161 4629 6567 9066 12225 16151 20959 26772 33721 41945
2 9 31 93 230 487 919 1591 2578 3965 5847 8329 11526 15563 20575 26707 34114 42961 53423 65685 79942
11 27 70 153 298 547 990 1825 3465 6707 12978 24673 45600 81547 140986 235929 382951 604395 929774 1397385 2056150
13 15 24 45 96 229 574 1420 3353 7486 15856 32157 63182 121779 233032 447242 866998 1702750 3384409 6779726 13609905
16 33 62 112 196 346 646 1291 2686 5616 11552 23221 45683 88364 168851 319849 601648 1123903 2082686 3821866 6932202
2 12 35 83 176 349 671 1291 2536 5091 10290 20539 39876 74648 134250 231825 384766 614790 947269 1409403 2026704
18 36 63 104 176 311 572 1103 2243 4745 10154 21413 43783 86182 163069 297022 522184 888778 1468921 2363998 3713890
10 13 11 4 6 60 256 752 1798 3763 7165 12704 21298 34122 52650 78700 114482 162649 226351 309292 415790
2 5 13 46 139 350 779 1613 3219 6320 12325 23978 46703 91450 180668 360614 726382 1472666 2997362 6114810 12496419
5 3 -7 -16 -4 62 236 614 1396 3052 6707 14932 33227 72632 154177 316480 629191 1218157 2315097 4358776 8202246
17 27 34 35 23 -9 -47 4 448 2037 6408 16914 40280 89988 193197 404630 833640 1695246 3403399 6737208 13132694
19 26 41 72 124 210 370 696 1360 2641 4946 8819 14931 24043 36933 54277 76473 103396 134071 166250 195878
20 40 80 161 326 665 1364 2797 5693 11429 22534 43559 82610 154115 283904 518588 942764 1710019 3097257 5596451 10062858
9 3 -9 -32 -60 -50 125 769 2548 6845 16420 36621 77610 158483 314918 613299 1176493 2230289 4186508 7792707 14407912
21 27 27 18 0 -17 -3 105 419 1119 2475 4872 8838 15075 24493 38247 57777 84851 121611 170622 234924
-1 14 56 151 337 672 1249 2217 3807 6362 10370 16499 25633 38908 57747 83893 119439 166854 229004 309167 411041
-4 8 34 72 119 171 223 269 302 314 296 238 129 -43 -291 -629 -1072 -1636 -2338 -3196 -4229
3 14 39 86 168 306 546 999 1920 3868 8040 16959 35853 75373 156928 323138 658121 1326054 2642273 5199676 10084758
17 29 40 59 116 282 693 1585 3355 6669 12642 23117 41070 71166 120487 199447 322901 511445 792892 1203895 1791672
-4 -5 -6 -1 37 176 562 1488 3524 7755 16191 32431 62700 117479 214198 382001 670632 1167335 2028724 3539411 6216491
-4 -7 -10 -13 -16 -19 -22 -25 -28 -31 -34 -37 -40 -43 -46 -49 -52 -55 -58 -61 -64
7 34 90 185 334 580 1028 1886 3516 6512 11838 21069 36776 63087 106474 176971 290626 475802 790737 1371275 2553159
3 10 24 47 81 128 190 269 367 486 628 795 989 1212 1466 1753 2075 2434 2832 3271 3753
-4 -4 2 23 83 237 596 1361 2866 5630 10418 18311 30785 49799 77892 118289 175016 253024 358322 498119 680975
1 15 40 90 198 421 845 1590 2815 4723 7566 11650 17340 25065 35323 48686 65805 87415 114340 147498 187906
1 7 20 34 47 84 234 705 1910 4608 10140 20830 40680 76597 140576 253559 452135 799885 1406060 2455466 4254981
8 31 64 116 217 422 807 1458 2462 3920 6016 9193 14507 24253 42983 79065 146964 270461 487064 853906 1455469

98
09/main.s Normal file
View File

@@ -0,0 +1,98 @@
global _start
[bits 32]
[section .text]
%include "utils.s"
_start:
; read in sequence
read_seq:
mov byte [seq_len], 0
mov esi, [char_ptr]
mov edi, sequence_orig
.l:
call sign_dec_parse
stosd
inc byte [seq_len]
cmp byte [esi-1], 10 ; \n
je seq_over
jmp .l
seq_over:
mov [char_ptr], esi
; reverse sequence
movzx ecx, byte [seq_len]
mov eax, ecx
dec eax
lea esi, [sequence_orig+eax*4]
mov edi, sequence
reverse:
std ; set direction flag
lodsd
cld ; clear direction flag
stosd
loop reverse
cld
; calc differences
mov byte [depth], 1
calc_diff:
lea esi, [sequence+4] ; i=1
mov ebx, [sequence] ; last, i=0
mov edi, sequence
xor edx, edx ; all zero flag
movzx ecx, byte [seq_len]
dec ecx
push dword [sequence+ecx*4]
.l:
lodsd ; curr
mov ebp, eax ; save curr
sub eax, ebx ; curr - last
setnz dh ; dl = 1 if not zero
add dl, dh
stosd ; save in new seq
mov ebx, ebp ; last = curr
loop .l
test edx, edx
jz .all_zeros
; we need another layer
inc byte [depth]
dec byte [seq_len]
jmp calc_diff
.all_zeros:
xor ebx, ebx ; start diff is 0
movzx ecx, byte [depth]
.predict_l:
pop eax ; curr
add eax, ebx ; curr += last diff
mov ebx, eax ; last diff = curr
loop .predict_l
call print_sign_dec
call space
call space
add [final_value], eax
mov eax, [final_value]
call print_sign_dec
call newline
cmp dword [char_ptr], file.over-1
jb read_seq
game_over:
mov eax, [final_value]
call print_sign_dec
jmp exit
[section .data]
final_value: dd 0
file_lim: dd file.over - file
dd 0
file: incbin "input"
.over:
char_ptr: dd file
seq_len: db 0
depth: db 0
[section .bss]
sequence: resd 32
sequence_orig: resd 32

83
09/main_part1.s Normal file
View File

@@ -0,0 +1,83 @@
global _start
[bits 32]
[section .text]
%include "utils.s"
_start:
; read in sequence
read_seq:
mov byte [seq_len], 0
mov esi, [char_ptr]
mov edi, sequence
.l:
call sign_dec_parse
stosd
inc byte [seq_len]
cmp byte [esi-1], 10 ; \n
je seq_over
jmp .l
seq_over:
mov [char_ptr], esi
; calc differences
mov byte [depth], 1
calc_diff:
lea esi, [sequence+4] ; i=1
mov ebx, [sequence] ; last, i=0
mov edi, sequence
xor edx, edx ; all zero flag
movzx ecx, byte [seq_len]
dec ecx
push dword [sequence+ecx*4]
.l:
lodsd ; curr
mov ebp, eax ; save curr
sub eax, ebx ; curr - last
setnz dh ; dl = 1 if not zero
add dl, dh
stosd ; save in new seq
mov ebx, ebp ; last = curr
loop .l
test edx, edx
jz .all_zeros
; we need another layer
inc byte [depth]
dec byte [seq_len]
jmp calc_diff
.all_zeros:
xor ebx, ebx ; start diff is 0
movzx ecx, byte [depth]
.predict_l:
pop eax ; curr
add eax, ebx ; curr += last diff
mov ebx, eax ; last diff = curr
loop .predict_l
call print_sign_dec
call space
call space
add [final_value], eax
mov eax, [final_value]
call print_sign_dec
call newline
cmp dword [char_ptr], file.over-1
jb read_seq
game_over:
mov eax, [final_value]
call print_sign_dec
jmp exit
[section .data]
final_value: dd 0
file_lim: dd file.over - file
dd 0
file: incbin "input"
.over:
char_ptr: dd file
seq_len: db 0
depth: db 0
[section .bss]
sequence: resd 32

247
09/utils.s Normal file
View File

@@ -0,0 +1,247 @@
; call # val val2
; int $0x80 eax eax edx -
;
; arg1 arg2 arg3 arg4 arg5 arg6 arg7
; ebx ecx edx esi edi ebp -
exit:
mov eax, 1 ; exit
int 0x80
; filename in EBX
; return handle in EBX
; read only
open_file:
push eax
push ecx
mov eax, 5 ; open
xor ecx, ecx ; read only
int 0x80
mov ebx, eax
pop ecx
pop eax
ret
; file handle in EBX
; buffer in ECX
; count of bytes to read in EDX
; return bytes actually read in EAX
; exits on error
read_file:
mov eax, 3 ; read
int 0x80
test eax, eax
js .err
ret
.err:
mov eax, 4 ; write
mov ebx, 1 ; stdout
mov ecx, .err_str
mov edx, 21
int 0x80
jmp exit
.err_str: db `Could not read file.\n`
; string input in ESI
; value in EAX
; CF set if none, clear if some
; ESI set past checked area
dec_parse:
push ebx
push edx
push edi
xor eax, eax
xor edi, edi
mov ebx, 10 ; base
lodsb
sub al, '0'
js .no_input
cmp al, 9
jle .got_char
.no_input:
stc ; set CF
jmp .done
.loop:
xor eax,eax
lodsb
sub al, '0'
js .dec_done
cmp al, 9
jg .dec_done
.got_char:
xchg edi,eax
mul ebx
add edi,eax
jmp .loop
.dec_done:
clc ; clear CF
.done:
mov eax,edi
pop edi
pop edx
pop ebx
ret
; string input in ESI
; value in EAX
; CF set if none, clear if some
; ESI set past checked area
sign_dec_parse:
push ebx
push ecx
push edx
push edi
xor eax, eax
xor edi, edi
xor ecx, ecx ; neg flag
mov ebx, 10 ; base
cmp byte [esi], '-'
jne .no_minus
inc esi
mov cl, 1
.no_minus:
lodsb
sub al, '0'
js .no_input
cmp al, 9
jle .got_char
.no_input:
stc ; set CF
jmp .done
.loop:
xor eax,eax
lodsb
sub al, '0'
js .dec_done
cmp al, 9
jg .dec_done
.got_char:
xchg edi,eax
mul ebx
add edi,eax
jmp .loop
.dec_done:
test ecx, ecx
jz .not_neg
neg edi
.not_neg:
clc ; clear CF
.done:
mov eax,edi
pop edi
pop edx
pop ecx
pop ebx
ret
; modifies no regs
newline:
pushad
push 10
mov eax, 4 ; write
mov ebx, 1 ; stdout
mov ecx, esp ; string
mov edx, 1 ; length
int 0x80
add esp, 4
popad
ret
; modifies no regs
space:
pushad
push 9
mov eax, 4 ; write
mov ebx, 1 ; stdout
mov ecx, esp ; string
mov edx, 1 ; length
int 0x80
add esp, 4
popad
ret
; input in EAX, all regs unmodified
print_dec:
pushad ; save regs
; max 4294967296 is 10 chars
; round to nearest 32-bit boundary
sub esp, 12
; string in ECX, length in EDX
lea ecx, [esp+11] ; last possible byte
; check for 0
test eax, eax
jz .zero
mov ebx, 10 ; base 10
xor esi, esi ; counter
.div_shit:
xor edx, edx
; divide
div ebx
dec ecx ; next char
inc esi
; store
add dl, '0'
mov byte [ecx], dl
; check if done
test eax, eax
jnz .div_shit ; continue
mov edx, esi ; counter in edx
jmp .write
.zero:
mov byte [ecx], '0'
mov edx, 1 ; length
.write:
mov eax, 4 ; write
mov ebx, 1 ; stdout
int 0x80
add esp, 12 ; restore stack
popad ; restore regs
ret
; input in EAX, all regs unmodified
print_sign_dec:
pushad ; save regs
; range -2147483648 to 2147483647 is 11 chars
; round to nearest 32-bit boundary
sub esp, 12
; string in ECX, length in EDX
lea ecx, [esp+11] ; last possible byte
; check for 0, negative
xor ebp, ebp
test eax, eax
jz .zero
jns .positive
neg eax
mov ebp, 1
.positive:
mov ebx, 10 ; base 10
xor esi, esi ; counter
.div_shit:
xor edx, edx
; divide
div ebx
dec ecx ; next char
inc esi
; store
add dl, '0'
mov byte [ecx], dl
; check if done
test eax, eax
jnz .div_shit ; continue
mov edx, esi ; counter in edx
jmp .write
.zero:
mov byte [ecx], '0'
mov edx, 1 ; length
.write:
test ebp, ebp
jz .no_minus
dec ecx
inc edx
mov byte [ecx], '-'
.no_minus:
mov eax, 4 ; write
mov ebx, 1 ; stdout
int 0x80
add esp, 12 ; restore stack
popad ; restore regs
ret

3
10/Makefile Normal file
View File

@@ -0,0 +1,3 @@
all:
nasm -g -felf32 main.s && ld -melf_i386 -g main.o

140
10/input Normal file
View File

@@ -0,0 +1,140 @@
J.7--J-.LL77FJ-F7FLJ-7.|FFF.F7FL-7F-7.L-FF77.-F-L7.F-L--7FL7..LF|J.7FF7.FLJ.-7-F7F-J77F77.|7.777FJ7FL7F-|.FFJ7|-|7FL-.LL7F77.|J7.|JJ-7-7|-|7
J.|.FJ|FJ.-|LJ|L7FJ|.F.7-|J7L-J|L7|..-JF-JL77-|F|JL||.|L|J7L.|F7J-F-77--L|.-JF7F|JJ-|J||F7-77.|||L-FJ7J-|--7.F|7|LF|F--JF-F.LJ|.F|L|.|||7JL|
|.|-JJFJL|LJ.FLJ-|-FJL-|L|||.|-F-F7-F7|7|F-|L-FF.|.-7FJ.|7F.F-|-7--JL..FLF-J|LLLJJ..J.LL.|L.-.L--J|L||JF|J||F-|L|LL|JJ.L7J.77L|-L|7--L7|||.|
F-J..FL--F--L7LJ7L||.|.|FFL|-F-FJ.LFJ77FJJ.L7.-J|-7L-J.F|||-FLF--.L-J7F7F-7||-|J||.FL|.F--.FLJLL-L7.LL-FJ.FLJ.|-7-7..LF-J|-J7.|FJJ|7.7.LL7.|
||F77F7--|LJ|F|F7-J7F-F-.|JF.|-7LJF77|J||.|-JFL-F-|.L..FJFJ7J.|F|.L7.FLJ7L|---J-F7|77|FJ7F-FF|L|LF-LJ7--J.L.L7JF-7L|-FL7LF7L7.F-|-F--L-|7F.7
|---J7.|LJJFF-LJLF|--7|.LLFLF-7J.LLJLL-7.--7J-JF|7|-7L---J--.FFFF7L|-LJ.--77LF.|FL7--J-JL|.||--L7J7|LL7|.777.|.LJ|.|LF7F-JL7.F|7J7|-|.7FJ|7|
JLJLF|-LF7FL--L-FF|.LJ7-||..|LL7|7F7-LFJ-J-|LLF77LJ7|FLLJ7L7L7-F7-F--7-L7.LF7LFF7L7-F|J7FJ7|JFL7|.L-7|||F|-J-J7|.J7LFLJJL-7|F|LJ.FJ---J-7L7|
LF..LJ.LLF|J-7F-LJ|L7.|.|FL7.J|FJF7J7JL|L7.L7J|L77F7L|.F7|-J.F-JL7L7FJJ|-77F7F7||F7F77F77L|..|.F7J.L7-J-FJ||FLF|7.7|LL.-.7||.L7|LF7FL7-|7.-|
-77-L-|7|.L-7|F|JFJJ-F|-|J-F7|FF77J|77FFF77FF7|FJ7|7LL7|F|7LLL--7|FJL7.L-JL|LJ||LJ|||F7J..LF7FF7J|-||-.L|-F|--F.LFF|-.|FF--L7JFJ.|-|-77-J|-F
.-J7LFLJJ7..-L7FF7J|7FJ.L|-F-|L-JL7.LFF7||F-J||L-7J-.FFFFJ||.|F7|||F-JFFL7-L-7|L7FJ|||L777JF7FJ|F|77|-J.7.F7L7J77||JL-JF-.L7L-LJ.7L|J.-JJJJ.
77LL.7LLJL7-7JLJ||.7F7-7LL-7LF7L-FF--7F7||L-7LJF-JLL-F7JLF7F7FJLJ||L--777L-F-J|FJL-JLJFJ|FFJLJFJJ||F7-7FF-7J.|---F|-F|F-J7.L7F|LFJ7L-LJ|...F
J7..L.F||J..|7JL-F-LL|-7-7|F-J|--LL7FJ||||F7L-7L77FLFJ|F-JLJ|L--7LJF--J-77J|F7|L--7F-7||7FL-7FJLFLJ-F7-FJFJF77FL-.|J||L.F77LF|L-7F--|LJ|7-|J
||J.LFLJ--FJL|7F|L-JL|7|JLLL7FJJ.|L|L7|LJLJ|7FJFJ7F7L7|L--7FJF7F|F-J-|JLL7.LJ|L7F7||.LJ-F7F-JL7F7|.F|FFL7L7-F7J--LL--JJ.|JL7|L-7JL7-7JFFJ7.J
FL777L|.L7J|JJLJJ-F-7FJF7-JJ||F7-FFJFJL-7F-JFJFJF7||J|L7F7||FJ|FJ|F-7F7J7.F77|FJ|LJL7F7FJ|L7F-J|L77-FF-7|FJFJ|J|.||..|.LFJ.L77.F7F7J|.FJFFJ.
JJFL7LJ.F|FL-7.7J.7LF7-F77.F|||L-7L7|F7L|L7FJFJFJ||L7|FJ|||LJFJL7||FJ||F7FJL7|L7L-7FJ||L7|FJL-7L7|F7FL7LJL7|FJJ-FFJ7.F7-L7..LL|J|7|.|.F7---J
FFJ.LJF-FFJLL|-F----7J|||7FFJ||F-JFJ||L7|FJL7L7L7LJFJ|L-J||F7L-7|||L7|||LJF-JL7|F-J|FJL7||L7F-JFJLJ|F7L-7FJ||F77F7JL-|LFJF--7|LJ|L7FF-L|-|LL
JJF7JJF7|JFL|L-L---7L--J|F7L7|||F7L7||FJ||F7L7|FJF-J-|F--JLJL7FJ|LJFJ||L-7L-7-||L-7|L7FJ|L7|L-7L7F-J|L-7|L-JLJ|FJ|.JL77JFJFJJ|FJL||FL7.J..FJ
LF7LLF.---J--F-L|7LL-7F7LJL7||||||FJLJL-J|||L||L7L7F7|L7F7|F7||-L-7|F||F7L-7|FJL7FJL-JL-JFJ|F-J||L-7L-7||F----J|FJ77F7---.7|.JJJ---7J|F-7FJ.
FLJ7.|7.JFJ7|LF--7F-7||L--7|||||||L---7F7|||FJ|FJFJ|||FJ|L7|LJL--7|L-JLJ|F7||L7FJL--7F7F-JFJL7F7|F7|F-JLJL-----JL-7-J|F-LFL77LJ7-|--JL77FJ-J
F-7FFJ-7-JJLL7L-7|L7|LJLF-JLJLJLJ|F--7||||||L7|L7L-J||L7L7|L----7LJF7F--J|||L7||F7F7LJ|L-7L-7|||||LJL-7F-7F----7F-J7F|J|7|...F7|--7||.L-|JFJ
|JJ7J|FL-JJL|-F-J|FJL-7.L------7FJL-7LJ|LJ|L-JL7L--7LJFJFJ|F7FF7L7FJLJF7L||L7||LJ||L-7|F-JF-JLJ||L7F-7LJFJL7F7LLJLF--7---|.|-J-L7-J7J7J||7JJ
||---JF-J.FF|FL-7|L7F-JF-7F7F--JL7F7L7FJ7FL-7F-JF7JL-7L7|FJ|L7||FJL-77||FJL7||L-7|L7FJ|L-7L-7F-J|FJ|FJF7L-7LJL7JF7|F7|7.LFF7L7JL|..LLJJ|L|77
-7.FL-JJJFFJ-F--JL7||F7L7|||L--7FJ|L7||F7F7L|L7FJ|F7.|FJ|L7|FJ||L7F-JFJ|L-7|||F-JL-JL-JF-JF-J|F7||L|L7|L-7|F-7|FJ|||LJJ-F7||F-7J|F-F|JLL-|7J
JJ-L7J...--7.L---7LJ||L-JLJ|F77||.|FJ||||||FJFJL7|||FJ|FJFJ||FJ|FJL-7L7L7FJLJ|L---7F---JF7L-7LJ||L7|FJL-7LJL7LJL7LJL7FLFJ||||FJFLLF7.7..|.-.
F|LJ|FL.L7FFF-7F7L7FJL----7|||FJ|FJ|L|LJ|||L7|F7||||L7|L7L7||L7||F--J-L7LJF-7|F---J|FF7FJL7FJF-J|FJ|L7F7L-7FJFF7|F--JF7|FJ|||L7--F||F|7.|.|F
F|7.FF.JF-||L7LJL-JL7F----JLJ|L7LJFJFJF-J||FJ||||LJL-JL7L7||L7||||-F7F7|F7L7LJL---7|FJLJF7|L7|7FJL7L7|||F7|L-7|||L7F-JLJL-JLJFJ|.FJL7-7--F7|
||L-7.|L-LLLJL---7F-JL-7F7F-7|FL-7L7L7L7FJ|L7|||L-7F7F-J||LJFJ|||L7||||LJL7|F7F7F7|LJF--J||FJL7L-7|FJ||LJ||F-J|||FJ|F---7F-7FJF-7L7FJJJJ|LL|
F7LL|-J|||.L-F---JL7F-7LJLJF||F--JFJFJFJL7|FJ||L7|LJ|L7F7L-7L7|LJFJ|LJL7JL|||LJLJ||F-JF7|||L-7L7FJ|L7|L-7LJL-7||||FJL-7LLJF||L|FJFJL7FF7|7-|
|.J7...F-J-7.L----7||FJF7|F7||L--7L7L7L-7|||FJ|FJF77L7||L-7L7||F7L7L--7L7FJ|L--7FJ|L7L|L7LJF7L7|L7L7||F-JF---J|LJLJF--JF7F7||FJL7L7FJ7JJ||JJ
|..F-FJLJFLF-F--7F|LJL-JL7||||FF-JFJFJF-J|||L7|L7||F-JLJF-J.||||L-JF7FL7|L7|F7.||.L7L7L7L7FJ|J||||FJ||L-7L-7|FJF7F-JLF7||||LJL7FJFJL7|-|7|.F
|FF--J|-LJ7||L-7|FJF7F7F7LJLJL7L7FJFJFJF7|LJFJL7|||L-7F-JF7FJLJL-7FJL7FJ|FJLJ|FJL7J|FJFJFJ|FJFJ|FJ|L||F7|F-JFJFJLJF-7|LJLJL7F7||FJF7|J.LJ|F7
F|J|-||.|LFFF--JLJFJLJLJ|F7F-7L-J|.L7|7|||F7|F7||||F7||F7|LJF----J|F-JL7LJF-7|L-7L-J|FJFJFJL-JFJL7L7|||LJL7LL7L--7|FJ|F----J|||LJFJ|||.JFJ-|
.|JL7-L7-F--JF----JF7F--J|||FL7F7L7FJ|FJ|LJ|||||||||||LJ|L-7|F7F-7|L7FFJF7L7LJF7L-7FJL7|LL7F--J.FJFJ||L7F7L7L|F--J|L7||F7F77|LJF-JJLJ-JLJJF|
|77-7FL|JL-7FJF----JLJF7FJLJF7LJL7LJFJL7L7FJ||||LJ||LJF-JFFJLJ||FJL7|FJFJL-JF-J|F7|L7FJ|F-J|F7F7L7L7|L7||L-JFJL--7|FJ|||||L-JF7L7JF|...LJFL7
L|L7.|F||LLLJJL-7F--7FJLJF7FJL7F7|F7|F7|FJL7|||L7FJ|F-J7F7L7F-J||F7||L7|F7F7|F-J|||FJ|FJL-7|||||||FJL7|||-F7L7F--J||FJLJLJF-7||FJ||F7FL..L7|
LJ.LJJ-7FFJF7F--J|F7||.F7||L-7LJ|LJ||||||F7||||FJL7||F-7||FJ|F-J||||L7||||||||F-J|||FJ|F--J||||L7|L7FJ||L-JL-JL---JLJF7F-7|LLJLJ|FF7.F-J-L|7
|L-7FF7.7LFJ|L---J|LJ|FJLJ|F7L-7|F7||||||||||||L77||||FJ|LJ|||F-J|||FJ|||||||||F-J||L7|L7F-J|||.LJFJ|FJ|-F7F---------JLJJLJF7F7FFFJ|F77JF|LF
77-L-L77FFL7|F7F-7|F-JL7F7LJL7FJLJLJLJ||LJ|||||FJFJ|||L7L-7FJ|L7FJ|||FJ||LJ|||||F7||FJ|FJ|F7|||F--JFJ|FJFJLJF-7F7F---------JLJL7FL7LJL7L-J||
|L-7FF7-F-7||||L7LJL7F-J||F-7LJF-----7|L7FJ|LJ|L7L7|||FJF7|L7L7||FJ|||FJL7LLJLJLJLJ||FJL7LJ||LJ|F-7L7||FL---JFJ|LJF--7F7F------JF7|F--J.L|7|
7J7FFJ|FL7LJLJL7|F--JL-7|||FJF-JJF---J|FJL7L-7|FJ-LJLJ|FJLJFJFJ||L7||||F7L-------77|||F7||FJL7FJ|FJFJ||F----7L-JF7|F7LJLJF------JLJL--77FLF7
|L--L7L7|L----7|LJF7F7FJ|LJ|FJ|F-JF--7|L7LL7FJLJF7F---JL--7|FJ-LJFJ|||LJL7F-7F--7L7||LJ|L7L7FJL7|L7L7LJL---7|F7FJLJ||F---JF7F--7F7F7F7|.F-77
L7J|FL7L-7F7F7|L7FJ|||L-JF7LJF-JF7|F-JL-JF-JL-7FJLJF-7F7F-J|L-7F7L7||L-7L||FJL-7L7||L7FJFJ-LJF7||FL-JF----7||||L---JLJF-7FJ|L-7LJLJ||LJ7JLLJ
.|FF--JF-J|LJLJFJL7||L7F-JL7FJF-JLJL7F7F7L---7|L--7L7|||L-7L7FJ|L-J|L7FJFJ|L-7FJFJ|L-J|FJ.F--JLJL-7F7L---7LJLJL----7F-JFJ|.L-7L--7L||.FJ7LJ.
FLFL7F7L7FJF7F7L--JLJFJL-7FJL-J.F7F-J|||L--7FJL-7FJFJ||L7FJ.||FL7F7||||FJFJF-J|7L7L--7LJF7L--7F7F-J||F7F7L7F7F----7|L-7L7L-7J|F-7|-|L7-LJ-JF
7JL.||L7LJFJLJL-7F--7||F-J|F7F--J|L--JLJF7FJL7F-JL7L7||J||F-JL7FJ||L7||L7L7L-7L7FJF7FJ.FJL---J||L-7|||LJ|FJ|||F---J|F-JF|F7L7LJ7|L7L-JF7-|.|
77LF||F|F7|F-7F-J|-FJL7|F7|||L--7L---7F-J||.|LJJF7|FJ|L7LJL7F7|L7|L-JLJ|L7L-7|FJL7||L7FJF----7|L--J||L-7||FJLJL7F7JLJFF-J|L7L--7|FJJ|-F--J7J
|7JLLJ-||||L7|L-7|FJF7|LJ|LJL---JF-7FLJF7|L7F---JLJL7L7L--7||||FJL-7F----JF7||L7FJ|L7|L7L7F--J|7F7|||LFJ|||F---J||F7F7L-7L7|F7FJ||J7|-|L|L|7
.--FFLFLJLJFJL--J|L-J|L--JF--7F7FJJL---J||FJL7F--7F7L7L7F7|||||L7F-JL-7F7FJ||L7|L7|FJ||L7|L--7|FJL7|L7L7|LJL-7F7|LJLJL-7|FJ||LJ-||.F77|-LJL|
7J--|.LL-F7L--7F-JF--JF---JF7LJLJF|F7F7FJLJF7||F-J|L7||LJLJLJ|L7||F---J||L7||FJL7||L7|F-J||F-J|L-7|L7L-JL----J|LJF-----JLJ.LJJ|-LJFJL--7.--J
L--7..FLFJL-7-LJF7L---JF---JL-7F-7FJLJLJF7J||||L-7|7|L---7F-7|FJLJ|F7F7||FJ||L7FJ|L7||L-7|FJF7|F-JL-JF------7FJF7L-7F--7F---7FFF-7|F---J7-FJ
-|F7-L77L--7L7|FJL-----JF7F-7FJL7|L-----JL-J|LJF7|L7|F7F7LJFJ|L--7LJ|||||L7|L7||FJFJ||F-J|L-J||L-7F-7L7F----J|FJL7FJ|F-J|F--J7JL7LJL-7LLJ-L-
|FLJ.L-7L|.L7L-JF--7F-7FJLJFJL--JL----------JF7|LJFJ|||||F7L7|F7FJF-J||||FJL-JLJL7L7LJL7FJF-7LJF-JL7L-JL-----JL-7||7|L--JL7F7-F7L-7F-J.L7.FJ
7|L|7J...F7FL7F7L7LLJJ||F--JF7F7F7F---------7|||F7L7||LJ||L-JLJLJJL-7|LJ|L---7L|F|FJF7.LJJL7|F-JF7FJF7F7F---7F--JLJFJF7F7FJ|L7|L7FJL-7..LJ7|
.|-LL.|-FF---J|L7L7F7FJ|L---J||LJ||F-------7|||LJL7||L-7|L--------7FJL-7|F-7FJF--J||||F7F7-||L-7|LJFJLJ|L--7LJF7F7-|FJLJLJ.L7LJFJL7F-J7.|-|7
J|-FJF|-LL7F--JJL7|||L7L7F---J|F-J|L--7FF7FLJ|L7F-J|L-7|L7F7F7F7F-JL7F7||L7LJLL--7|FJLJ|||FJL--JL7FL7F7L---JF-J||L7|L------7L7FJF7||FLF--7L-
|--JFLF-|J||F---7LJ||J|FJ|F-7FJL--JF-7L-JL7F-JFJL-7L-7|L7LJLJ|||L-7FJ|LJL7|-|JJFFJ|L--7||LJF-----JF7LJL7F---JF7LJFJ|F---7F7L-JL-JLJL7-|F-JLJ
77FLF-F-7J||L7F7L--JL-J|FJ|FJ|F----J7L----JL-7L--7|F7|L7L7F7-LJ|F-JL7L7JJ|L-7-F-L-JF--JLJF7|F---7FJL---J|F-7FJ|F7L-JL--7|||F-7F7F7F7L-JL--7|
F-F-J.|7F-LJ7LJL-----7FJ|FJL7|L-------------7|F--JLJ|L7|FJ||F77LJ-LLL-J|L|F-JF7|F7.L-----J||L-7FJ|F7F---JL7LJ||||F-7F--JLJLJ.|||||||F7F---J7
|||J|FLLJ7L||.F7F--7|LJFJL77LJFF--7F7F7F----J|L----7L-J||FJ|||F7F7JFLJFL.LJ-FJL7|L--7F7-F7LJF-JL-J|||F----JF-7||||FJL-7F7F7F7LJLJ||LJ|L-7|J|
F|..FJ.L-F7F7FJLJF7L---JF-JF---JF7LJ||LJF7-F7|F----J|F7LJL7LJLJLJ|-LJ.-.LJLFL-7|L--7LJL-JL--JF7F-7|LJL-----JFJLJLJL7F-J|LJ|||F--7|L7|L-7L77.
LL777|7-FJLJ|L-7FJL-7F7FJF-JF---JL-7|L--JL-JLJL------JL7F7|F----7|JLF-F77LFF--JL---JF7F7F7F7FJ|L7||F--------JF7F7-FJL--JF-J||L7FJL7L--7|FJ|7
L||L77|-L--7|F7LJF7JLJLJ-L--JF--7|FJL7F-7F7F7F---7F-7F7LJ||L---7LJ-JL7-LFFJL--7F-7F7|||LJLJLJFJFJ|||F7F------JLJL7L-----JF7|L-JL-7|F--J||JL7
.L7FL-JFF--JLJ|F7||F-7FF7F7F-JF7L7L-7LJJ||LJ|L--7LJFJ||F7LJF---J-|.7J|7||.FJFFJ||LJLJLJF-----JFJ|LJLJLJF--7F7F7F7L7-F----JLJF7F7FJLJ-F7LJ|.L
F-LF.FFFJF---7LJLJ|L7L-JLJ|L--JL7L--JF-7|L-7|F-7L-7L-J||L7FJ|7.JL|F|.7---7.LLL-JF-----7|F--7F7|.F7F---7L-7LJLJLJL7L-JF---7F-J|||L----JL7-|7J
.LL|7J7L-J-F7L7F-7L7L7F--7|F7FF7L--7F|FJ|F7|||FJF7L--7LJF|L-7-J7LLL.-|.JJJ7-|F--JF-7F7LJL-7LJLJFJ|L--7|F7L----7F7L--7L-7FJL7|||L7F-----JFJJ7
--F-|.FL7F-J|.LJ7L7|7LJLFJLJ|FJL--7L7|L7LJLJLJL7|L--7L7F-JF-J.|L7||J|LFJ||J|FL--7|.LJL----JF--7L7L---JLJL-----J|L--7|F7||F7L7LJJ|L----7----L
|F-JL-JJFJF-JF--7|||F7F7L--7|L-7F7L-J|FJF7-F7.FJL--7L-J|F7L---7J||J|||L-7FF-L7FLLJF7F-----7L7FJFL--------7F-7F-JF--JLJLJ|||FJF7F|F-7F-J7|.L|
||-J|LJ.L7L7L|F-JFJLJ|||F7FJL--J|L-7.|L-JL-JL7L--7FJ|F7LJ|F---J7|JJ-LL7-L7L-7F|-LFJLJF---7L-J|F7F7F------J|FJ|F-JF7F---7|||L7|L7|L7LJJ--7.F|
|7.F|7F7FL7|FJ|F7L-7FJ||||L7F7F-JF7L-JF7F----JF-7LJFFJL-7|L7F7J7F7.F7-|FL-7L7JLF|L---J|F7L7F7LJ|||L7F7F7F7|||||F7|||F--JLJL7LJFJ|FJJL||.F|FJ
L.77LJ-F--JLJFJ|L--JL7|LJL-J|||F-J|F7FJ|L----7|FJF7FJF7FJL7LJ|FFJLF-|--||LL--7-7-FF----JL-J|L-7LJ|FJ|||||LJL-JLJLJLJL-----7|F7|7|||LLFF7-FL.
J7|.FL.L--7F7L-JF-7F7LJF-7F7|LJL-7LJLJLL7F7F7LJ|FJ||FJLJF7L--JF7-|.|LF.|-F7FLL7JLFJF--7F---JF7L-7|L-JLJLJF---7F7F--7F7F7F-JLJLJFJ|7-.|L-J||J
||LFJLFLLFJ||F--JFJ||F7L7||||F---JF7F7F7LJLJL--J|FJ||F|FJL-7F7FF-7-L-7|7LLJJ-7F-FL-JF7LJF7F7|L--JL7LF77F7L--7|||L-7LJLJLJF7F--7L-J|||77|.-JJ
FJFL7.|.||FJ||F--JFJLJ|FJLJLJL----JLJ||L---7F7|FJ|FJL7FJF--J|L7|FJJLLJLFJL.|FL|JLLF7||F-J|||L--7F7L7|L-JL-7FJLJ|F-JF-----JLJF-JFJJ|JJLJJ-|LF
F-7JLFF7FJ|FJ||F--JF--J|F--------7F--J|F---J|L7|FJ|F-J|FJF7FJFJ||JF7.LF-7J-J-JLF--JLJLJF7LJL---J||FJL-7F-7LJF-7||F7L7F------JF77-F--7-|J7F-|
L-J|.L|LJFJ|FJLJLF7L7F-JL----7F-7|L---JL----JFJ|L7|L-7||FJ||FJFJL7J||.F|JF77F7L|F---7F-J|F------J||F7FLJ-L--JFJLJ|L-JL------7||F-7LFL7L--J-J
.L-JFLL-7L7LJL|F-JL-J|F----7-LJFJL--7F-------JFJFJ|F-J|||FJ|L-JF7|FLFF77.|L-7.F||.|.LJ7FJ|F------JLJ|F7F7F---JF--JF-7F7F----J|LJFJFJL-JJ|JFJ
||.|L-J-L7|.F7FJF7F--JL---7L7F7L---7LJF--7F7F7L7L-JL--JLJL-JF--JLJ7FL||L|J|LL-LLJ-L7F--JFJL-7F--7F-7LJLJ|L---7|F--JFLJLJF7JF7|F7|L7.F|FL|.||
.LL7JJL-LLJFJLJFJ||F7.F7F-JFJ|L----JF-JF7LJLJL-JF-7F----7F-7|F---7JJL|L7|-J7|JF||.LFL---JF-7LJF-J|FL---7L-7F7||L7F--77F7|L-JLJ|LJ|L-7FJFJ777
J..|7L7.LLFJF-7|FJ||L7|LJF7L7L---7F7L7FJ|F-7F7F7|FJL7F-7|L7|LJF7FJ|.F|FJJ||L7-L7-F7F7F7F7|FJF-JF7|F----JF7LJ|LJFJ|F-JFJLJF-7F7|F77.LLLJL-LLJ
F-LLL-LF7L|FJJLJL7|L7LJF7|L7L----J|L-JL7|||LJLJ|||F-J|FJL-JL7FJLJF7-FJ|L||-FJL.|J|||||||LJ|FJF7||||F7F7FJL-7L--JFJL--JF7FJ-LJLJ||77FJ||7|.LF
FJ-LLF--|JLJF-7F7LJF|F7||L7L7F----JF7F-J|L----7|||L--JL---7FJL--7|L7L7|L7|LJ|LFF7|LJLJ|L-7LJFJLJLJLJ||||F--JF--7|F---7|||F-----JL7.L7L--.F.-
L7FFLJJL|7L|L7||L---J||||FJLLJF----JLJF7L--7F7|||L7F-7F7F-JL--7FJL7|FJ|-JF-F7.FJ||F7F7|F7L--JF------J|LJL---JF-J|L--7LJLJ|F-7F-7FJJL-|J.F-.|
L777J|J.L||F7||L-----JLJLJ|F-7L-------JL--7LJLJLJ-|L7||LJ-F7F7||F-JLJFJLF7|LF-JFJLJLJ|LJ|.F7FL--7F---JF7-F7F7|F-JF--JF7.FJL7|L7LJJ-F7L7FJJF7
F||||.F7F|-||||F7FF--7F7JF7L7L---------7F7|F7F7F-7|FJ|L7F7||||LJL---7L7FJL7LL-7|F7|F7|F7L-JL7F7-LJF-7FJL-JLJ|LJF7L---JL-JF7|L-JJF7-LF7L|JJJJ
|FJ--7LJ||.|LJLJL-JF7LJL7|L7L---------7|||LJLJLJFJ|L7L7LJ||||L7JF--7L7LJF-JF77||||FJ|LJL7F7FJ|L-7.L7|L-----7L7FJL7F----7FJLJLF7F|JFLLJLF7L7|
.L|J|FFJ|JFL-7F7F--JL--7||FJF---------JLJL--7F--J-L-JFJF7LJLJFJFJF-JF|F-JF-J|FJ||||FJJF7LJ|L7|F7L--JL------JJ|L-7|L---7|L-7F-JL----7FJ-LJ7|7
F.L77-F--7JF-J||L7F----JLJL7L--7F----7F7JF-7|L------7L7||F7F-J.|FJF|FJL7||F-JL7||||L7FJL7FJFJLJL----7F-7F---7L--JL----JL--J|F------J7J||L-.F
L|.||JL|LF.L-7|L-JL-------7|LF7LJF---J||FJFJL7F----7L7LJ|||||F-J|F7FJF7L-JL77FJLJ||FJL-7|L7L7F7F7F7LLJFLJF--J|F7F---7LF7.F-JL-7F--7L-JL7J|-|
FJJ----J7LF7JLJF7F-------7||FJL7FL----JLJFJF-JL---7L-JF7LJLJFJF-J|||FJL7F-7L7L-7FJ||F7FJL-JFJ||||||F--7F-JF7F7|||F--JFJL-JF---J|F-J7JF--7L7|
7|.LJLF.F7JLF7|||L---7F-7LJLJF7L--7F7F---JLL-7F---JF7FJL7FF7L7|F7||LJF-J|LL-JF7||FJLJ|L-7F7L7||||||L-7|L-7|LJLJLJL---JF7F7L7F-7|L-7F--7FJ.|J
L7.FL-J-|-7-|L-JL7F7.LJFJF-7FJL--7||LJF---7F7||F7F7||L-7L7|L-JSJ||L-7L-7|F7F-J|||L7F-JF7LJL7LJLJLJL7FJL--J|F-7F7F7F---JLJL-J|FJ|F-J|F-J7.F|J
|L-7-|7L|L.LL-7F7LJL--7|FJFJ|F7F7||L7FJF--J||LJ|LJ|||F7L7||F7F7FJL-7|7FJLJ|L-7||L7||-FJ|F7|L--7F--7LJF----JL7|||||L-----7F--J|FJL--JL7-7JJJ7
LF-7-7-77J-7JLLJL----7LJL7L-J|||LJL-J|FJF--J|F-JF-J|LJL7|LJ|||LJF--JL7L-7FJ|FJ|L7LJL7L7||L7F--JL7|L--JF7JF-7||||||F7F---JL7F-J|F-7F--J7J|.L|
|L7J-J.|-7-JF|LF7F7F7L---JF--JLJF----JL-JF--JL-7|F7L--7|L7FJLJF7L---7L7FJ|F7L7L7L7F7L7||L7|L-7F7L7-F--JL-J7LJLJLJLJ|L-7F7FJL--JL7LJ|F-77.FF|
JJ.|.FFL-|.FJLFJLJLJ|F-7F7L-----JF------7L7F7F7|LJL7JFJ|FJL7F7||F7F-JFJL7|||FJFJ7LJ|FJ|L7||F7||L-JFJF----7F------7FJF7LJLJF-7F-7L--7L7L7F7-.
LFF-777|FL-J7.L---7FJL7||L-------JF----7L7LJLJ|L-7FJFJFJ|F-J|||LJ|L-7|F7|||||FJF7F7|L7|FJ|||||L7F-JFJF---JL7F----JL7|L7F7FJL|L7|F7FJFJFJ|||7
F|L-J.LL|.FLFF7F--J|F7||L---------JF7F7L7|F---JF7|L-JFJFJL--J||F7L7FJLJLJ||LJL-J||||FJ||FJ|||L-J|F-J||F----JL-7-F77LJFLJ|L-7|FJ|||L-JFJFJL77
F-J|.F7.L---FJ|L--7|||||F--7JF-----J||L-JLJF-7J||L7F-J7L7F---JLJL7|L-7F7FJL-7F--J|||L7||L7||L7F-J|F-7LJF--7F7FJFJL-7F7F7L7FJ|L7||L7F7L-JF7L7
|L7JF|-77L7FL7|F--JLJLJ|L-7L7|F7F--7LJF7F7-L7L-JL-JL-7F7||FF-7-F7||F7LJ|L-77|L7F7|LJFJ||FJ||FJL--JL7L--JF7LJ|L7|F-7|||||7LJ.L7|||F|||F7FJL7|
-JF7LJJJF.F77||L------7|F7|FJLJ||F7L7FJLJL-7|F7F--7F7||||L7L7L7|LJLJ|F7L-7|FJFJ||L-7L7|||FJ|L-7F-7FJF---JL-7L7LJL7|LJLJL----7|||L7LJLJ|L7-LJ
.L7L77J.F-JL-JL-------JLJLJL7F7LJ|L-JL7F---JLJ||F7LJLJ|||FJJL7|L--7FJ||F7||L7L-JL7.L7LJ|||FJF-J|FJL-JF-----JFL---J|F--7F7F--J||L7|J|7LL7|-J|
L.L7--JLL-------7F----7F7F-7LJL-7L---7||LF-77FJLJ|F7F7||||JF7||F7FJ|FJ||LJL-JF---JF7L-7||||FJJFJL7-F7L---7LF7F7F7.|L-7|||L--7|L7LJF7J-FJ|JFJ
.F7L-|7JFLF-----J||F7LLJLJ-L-7F-JF---J|L7L7L7L7F-J|||||||L-JLJ|||L7|L7|L--7F-JF7F7||JFJLJ|||F-JF-JFJ|F7F7L-JLJLJL7L--JLJL-7FJL-J7.LL-FL-JF||
7LJ|F7J||-|F----7|FJL---7F7F7||F7L-7F7|FJFJFJF||F7||||||L--7F-J|L7|L7||F-7|L-7|||||L7L7F-J||L-7|F7|FJ|||L--7F7F--J.F7FF--7|L7-F--7.|.||J.F7|
77.FF7LF--J|F---J|L7F7F7LJLJLJLJL--J||||-|FJF7||||||||||F7J||F7L7||FJ|||FJL7FJ||||L7|L||F7||F7||||||7||L-7|LJ|L--7FJL-JF-JL-JFJF-J7.F--7.7--
F-F7||-L---JL7F-7||LJLJL-7F-7F-7F7F7||||FJ|FJ||||||||||||L7||||FJ||L7||||F7|L7||||FJL7|||||||||LJ||L7||F7L--7|F-7LJF--7L-7F-7L7|F7-FLJLJ7|-J
L-JL|J7LF---7|||LJF7F----JL7||FJ|LJ||||LJFJL7||||||||LJLJFJ|||||FJ|FJ|LJLJ|L7||LJ|L-7||||||LJ|L7FJL7LJ|||F7FJ|L7|F7L-7|F-JL7|FJLJ|-J-F7.|7-|
F|-LJ.L-L--7|LJF--J|L---7F7|||L-J-FJ||L-7|F-JLJ|||||L--7FJFJ|||||FJL7|F7F-JFJ|L7J|F-JLJLJ||F-JFJL7FJF7||LJ|L7|FJLJL--JLJF7FJLJF--JJ.F7-7LL-7
FL.L7.|.F--J|F7L--7|F---J|||LJ|F7FJFJ|F-J|L7F--J||||F7FJL7|FJ|||||-FJLJ|L-7|FL-JFJL---7F-J|L-7L-7|L-J||L-7|FJ|L----7F-77||L7F-JF7|.F7JL.77F|
77FJ|F--JF-7LJL---JLJF7F7|||F--JLJFJF|L-7|FJ|F7FJ||||LJF7LJL7|LJ|L7|F7FJF-JL--7L|F-7F7|L-7L7FJF7|L7F7||F7|||FJF----JL7|FJL-JL--JL7-F7.FJL7-7
|FF-LL7F7|.L-7F7F---7|LJLJ||L----7|7FJF7||L7||||FJ||L-7|||F-J|F-JFJ||||FJF7F7FJFJL7||||F-JFJ|FJ|L7||||||LJ||L7L------JLJF-7F7F---JF|L-J-7J7|
FJ||.L||LJF--J|||F--J|F---J|F----JL7L7||||FJ||||L7||F7LJL7L--JL7FJJ||||L7|||LJ7L7FJLJ||L--JL|||L7|||||LJF-JL7|F-7F7F---7L7LJ|L-7..F7.F7.-JFL
JF-L-FLJLLL--7|LJ|F-7||F7F7|L7F-7F7L7LJ||LJ.||LJ7||LJL7F7L7F---JL7FJ|||-LJ||F7F7||F7FJ|F----JL-7LJLJ|L7FJF7FJ|L7|||L--7L7L-7|F7|7F|FFJ-7JFLJ
L|J|J|FL7LLF-JL7FJL7LJ|||||L7||FJ|L7L-7|L--7||F--JL-7F||L7|L7F-7FJ|FJLJF--J||LJLJLJ||FJ|F7F-7F7L---7L7|L7|||FJFJ|||F7FJ.L7FJ||LJJ--F.LLJ.LJ|
FJL|FJ7FFF-JF--JL7FJF-J||||FJ||L7|FJF-JL7F7|||L--7F7|FJ|FJ|FJ|FJL7|L-7FJF-7||F-7F7FJLJ|||LJFJ||F7F-JFJ|FJ|LJ|FJ-LJ|||L-77||-||LJL|FL77-J.F-7
JJ-F-.F7L|F7|F--7|L7L--J|||L7LJ|LJL7L-7FJ|||LJF--J||||FJ|FJL7|L7FJ|F7||FJ7||||FJ||L-7F7||FFJFJLJ||F7L7||FJF-JL-7F-J||F7L7LJ-|L7J.LJ7L--.L7L7
L|FL|.|.FLJLJL-7LJFJF---J|L-JF-----JF-JL-J|L-7L7F7|||||J||F-J|FJL7||||LJF-J|LJL7|L7FJ||||FJFJJF-JLJL7LJLJ7L7F7FJL-7|LJL7L7|FJFJ7..LJ-|.|.|.7
FFF.LF|-F-7F---JF7L7|F7F7L--7L-----7L----7|F7|L||LJ||LJFJ|L7FJL7FJLJ|L-7L-7L7F7|L7||FJLJ|L7|F-JF-7F7L-----7LJ|L--7|L--7L7L7|FJ.|F-.JJLFL7F.|
FLJ7|F-7L7LJF7F7||FJ|||||F--JF7F7F-JF--7FJLJLJFJL-7|L7-|FJFJL7FJL7-FJF7L7FJFJ|LJFJ||L--7L7LJ|F7|FJ|L-----7|F-JF7FJ|F7FJFJFJLJJF-J|..7.|JFJF-
|JJF|JL7LL7FJ||||||-||||||F7FJLJLJF7L7-LJF7F7LL7F7|L7L7|L7L7FJL-7L7|FJ|FJL7L7|F7L7||F--JFJ-FJ|||L7L-----7|||F7||L7|||L7L7L-7F-7J-F7F|7JFF7J7
||FLJ.F|.LLJ|LJ|||L7||LJLJ||L7F--7|L7L---JLJL-7|||L7|FJ|FJ7LJF7FJFJ||F|L-7|FJ|||FJ||L7F7L-7|FJLJ-L7F7F--JLJLJ|||FJLJ|FJFJF-J|FJJFL-7JJF|7F77
L-||FL|J7F||F--J||FJLJF---J|-LJF7||FJF7F-7F7F7|LJ|FJLJFJL7F--JLJFJL|L7L-7|||-||||FJL7LJ|F-J|L--7F-J|LJ7F---7FJ||L-7LLJJL7L--JL7FJ-J||F-7||.|
|7|LF-L--J--L--7|||-JLL-7F7L7F7|LJ||FJ|L7||||||F7|L--7L7FJL7F7F7L7.L7L7FJ||L7||||L-7L7L|L-7|F7FJ|F7L7F7|F--JL7||F7L7F7-LL-7F7FJJFL---7FJ-|F|
7-FJJ.||7|7-|FFJ|LJ-|J.FLJL7LJLJF7||L7L7|LJLJ|||LJF--JFJL-7||LJL7L7FJFJL7||FJLJ|L7LL7L7L7FJ||||LLJL7LJLJL---7LJ||L7LJ|F-F-J|LJFL|.F|LJ|JFF77
|JJJLL-L7L7J.FL-J.JJ|.FF77LL-7F7|||L7|FJL--7|LJL-7L--7L---J||F--JFJ|FJF7||LJLF-JFJF7L7|FJL7||LJF7F-JF-7F----JF-J|JL-7|J7L-7|FJJ7|-FF--7-FJLJ
F7|FF7LL|-L.F7L|.J7-|FFJL7FF-J|LJ|L7LJL-7F7|F7F--JF-7L---7|LJL7F7L7LJFJLJL--7L-7L7|L-J||F7|||-FJLJF-JFJL----7L-7L-7-||-JJFLJJJ-LJ|L7|.|.L7|7
LL7-L|J|LFJ77|.-J.77FFJF7L-JF7|F-JFJF---J|LJ||L--7L7|F-7FJJ-F-J|L7L-7L7F7F-7|F-JFJL7F7||||||L7|F-7L-7|F7F7F7|FLL7FJ-LJ.L--|FL7.L-J-||7FF---F
.F77.|7|FLFF-J7.L7|FFL-JL-7FJ|||F-JFJF7F7L--JL--7|FJ|L7||7LL|F7L7L7FJ7LJ|L7LJL-7L7-LJ|||||||FJ||-L7FJLJ|||||L7LFJL7..L..F-L7-F7F|JLJ7-F.L|-|
FFJ|FJ7LL7JF7LL|.F-F------J|FJ||L-7|FJLJL7F--7F7||L7|FJLJ7LFLJL7L7|L7F--JFJJL7.L7|F--J|||LJ||J|L-7|L-7-LJ||L7L7L7FJ--L--J--JFJFL|-F-F-L7---J
F|-LLJFF-J-L7FJL-FJL-7F--7FJL7|L7FJLJF---J|LFJ|LJ|FJLJ..F|-FLJFJFJ|FJ|F7FJJ.J-|.LJL-7FJ||LL||FJF-J|F7L7F|LJJL-J-||J|FJ.LL7L-L-F7|.|.LJ.|7.LL
|J7-J-F|.|LLJ-.|F|7|J|L7FJ|LFJ|FJL7F-JF7F7L7L7L-7LJJF|-L-L7|JFJFJ7LJF||LJ|.77-|-|LJ|LJFLJLLLJL7|7LLJL7|J7LLL7.|LLJL-|.J7.|7L|JLF-7JF|F7F--..
|L-7-L|J.|FLL7F-|J-JFL-JL7|7L-JL7FJL7FJLJ|FJFJF7|.LLFF7LJJ|7-|FJF7L|-||7LFF--FJFJ|LFJ|J-|-.LF-JL77-LL||7L7|LFFJ-.L7||-L--JF7J--7.FJFL7-F-J-L
7-LJ7|L--|7JL77.L||L|LL7LLJJ7F77|L-7||LLFJL7L-JLJ.F.LJ||7.F77LJ7|L-7J|L7|FL-7.F|-F-JJ||.JJFLL7F-J7JFL|L7J---F7J|-|F|J..|7L7.J7L|..7|FLF||.|J
L-J7.|.LJL-JF--7J|||L77-JJ|LFJL-JF-JLJ-L|F7L77LJ-L|FLL.F|-L|LJJ7|-FLJ|FJF|LLJ-7LF|F7.J--J7|-FLJ7|7.J-|FJL|L7LL7-.|L7L7-J7|JL|77|.F|F|.JL7777
...F7|F7|LJFJ7F7.LF7L-L-J7LJ|F7F7|J|F|J7LJ|FJJJ-J-J.LL-F|JL-7|LLL.JJFLJJ-77LJ.|-J7.-FJFLJL7.L|--JF7|-LJJF--J-FJ|FJFJLL7L|JLLFJ-J7JL-J7JLFJF7
-F|7LLJ-L.LF.-J|F|JLJJ-L.FJ.LJLJLJ.FFJJ7LLLJJ7JJ.JF|-JF-J-FL7-7|L7.||-JJ-J-7FF-7.77-77JL||J-7J-L7|JF7L-L-77L-LF|LLJLF7.7J--F|JJ-J7|J-77-JFJ7
.LJ|7LL7L-F7-LJ||LFJ.|-L|JF7.J7|-L-J|JFL-7|LL7FFL-7.|7-FL7.-J|L7L7-L|JL7LL|L7J||FL-7-JJ.7J7.|J|||77||7F-L-7.FFJJ-FJ.F-J|-L.-JJ.|L7|.7L77F-7|
77L|-.|L7FLLJJ.L|7J..-.F-7-|7|7|||JFJ.-J.7J.FJ-JL|JJ.7-L7|77FJ.J.L.|JLFJJL7LLJFJLF7J.FF|J--7||||||FL7LJF|L|7-7|JFF--7FLL.||J7.-77FJJ|FF7JFF7
-7-LLLJ|L|7FJ|F.J7...L7|F-7||7|J-J.L|7.|F|-JJ-F|||.|7LJL7.|L|F-FJJF|7FL|.7J..--77.|.L|JJ.|.F-7||F-F7L77FL.|7FJ---J77L-7|L-|JFF7L-7|-FJ|.L|L7
L7LLLL--7L-JJL.LL--.|-F-L-|-7-LJJ-F.LJ--LJFJ--JL---7-LJLL-7.|JJ|.LF-FJ-LF|-7-|-J-F|-LLLL|-JLLFJLJ.L|JLJ7-F-FJ-7-J.-J-LJ7JL7-J.J7JJ|J|L-|.7-|

231
10/main.s Normal file
View File

@@ -0,0 +1,231 @@
global _start
[bits 32]
[section .text]
%include "utils.s"
_start:
; find line length
mov edi, file
mov ecx, file.over - 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.over - 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
mov ecx, (1024*64)/141
mov edi, new_f
fill_new_f:
push ecx
mov al, '.'
mov ecx, 140
rep stosb
mov al, 10
stosb
pop ecx
loop fill_new_f
; 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]
mov ebx, edi
sub ebx, file
mov al, [edi]
mov [ebx+new_f], al
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
call newline
; go get an image editor and fill
; and ready for lots of counting :3
mov esi, new_f
mov ecx, file.over - file
call print_string
call newline
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: incbin "input"
.over:
[section .bss]
new_f: resb 1024*64

208
10/main_part1.s Normal file
View File

@@ -0,0 +1,208 @@
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]

BIN
10/solution.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

258
10/utils.s Normal file
View File

@@ -0,0 +1,258 @@
; call # val val2
; int $0x80 eax eax edx -
;
; arg1 arg2 arg3 arg4 arg5 arg6 arg7
; ebx ecx edx esi edi ebp -
exit:
mov eax, 1 ; exit
int 0x80
; filename in EBX
; return handle in EBX
; read only
open_file:
push eax
push ecx
mov eax, 5 ; open
xor ecx, ecx ; read only
int 0x80
mov ebx, eax
pop ecx
pop eax
ret
; file handle in EBX
; buffer in ECX
; count of bytes to read in EDX
; return bytes actually read in EAX
; exits on error
read_file:
mov eax, 3 ; read
int 0x80
test eax, eax
js .err
ret
.err:
mov eax, 4 ; write
mov ebx, 1 ; stdout
mov ecx, .err_str
mov edx, 21
int 0x80
jmp exit
.err_str: db `Could not read file.\n`
; string input in ESI
; value in EAX
; CF set if none, clear if some
; ESI set past checked area
dec_parse:
push ebx
push edx
push edi
xor eax, eax
xor edi, edi
mov ebx, 10 ; base
lodsb
sub al, '0'
js .no_input
cmp al, 9
jle .got_char
.no_input:
stc ; set CF
jmp .done
.loop:
xor eax,eax
lodsb
sub al, '0'
js .dec_done
cmp al, 9
jg .dec_done
.got_char:
xchg edi,eax
mul ebx
add edi,eax
jmp .loop
.dec_done:
clc ; clear CF
.done:
mov eax,edi
pop edi
pop edx
pop ebx
ret
; string input in ESI
; value in EAX
; CF set if none, clear if some
; ESI set past checked area
sign_dec_parse:
push ebx
push ecx
push edx
push edi
xor eax, eax
xor edi, edi
xor ecx, ecx ; neg flag
mov ebx, 10 ; base
cmp byte [esi], '-'
jne .no_minus
inc esi
mov cl, 1
.no_minus:
lodsb
sub al, '0'
js .no_input
cmp al, 9
jle .got_char
.no_input:
stc ; set CF
jmp .done
.loop:
xor eax,eax
lodsb
sub al, '0'
js .dec_done
cmp al, 9
jg .dec_done
.got_char:
xchg edi,eax
mul ebx
add edi,eax
jmp .loop
.dec_done:
test ecx, ecx
jz .not_neg
neg edi
.not_neg:
clc ; clear CF
.done:
mov eax,edi
pop edi
pop edx
pop ecx
pop ebx
ret
; modifies no regs
newline:
pushad
push 10
mov eax, 4 ; write
mov ebx, 1 ; stdout
mov ecx, esp ; string
mov edx, 1 ; length
int 0x80
add esp, 4
popad
ret
; modifies no regs
space:
pushad
push 9
mov eax, 4 ; write
mov ebx, 1 ; stdout
mov ecx, esp ; string
mov edx, 1 ; length
int 0x80
add esp, 4
popad
ret
; input in EAX, all regs unmodified
print_dec:
pushad ; save regs
; max 4294967296 is 10 chars
; round to nearest 32-bit boundary
sub esp, 12
; string in ECX, length in EDX
lea ecx, [esp+11] ; last possible byte
; check for 0
test eax, eax
jz .zero
mov ebx, 10 ; base 10
xor esi, esi ; counter
.div_shit:
xor edx, edx
; divide
div ebx
dec ecx ; next char
inc esi
; store
add dl, '0'
mov byte [ecx], dl
; check if done
test eax, eax
jnz .div_shit ; continue
mov edx, esi ; counter in edx
jmp .write
.zero:
mov byte [ecx], '0'
mov edx, 1 ; length
.write:
mov eax, 4 ; write
mov ebx, 1 ; stdout
int 0x80
add esp, 12 ; restore stack
popad ; restore regs
ret
; input in EAX, all regs unmodified
print_sign_dec:
pushad ; save regs
; range -2147483648 to 2147483647 is 11 chars
; round to nearest 32-bit boundary
sub esp, 12
; string in ECX, length in EDX
lea ecx, [esp+11] ; last possible byte
; check for 0, negative
xor ebp, ebp
test eax, eax
jz .zero
jns .positive
neg eax
mov ebp, 1
.positive:
mov ebx, 10 ; base 10
xor esi, esi ; counter
.div_shit:
xor edx, edx
; divide
div ebx
dec ecx ; next char
inc esi
; store
add dl, '0'
mov byte [ecx], dl
; check if done
test eax, eax
jnz .div_shit ; continue
mov edx, esi ; counter in edx
jmp .write
.zero:
mov byte [ecx], '0'
mov edx, 1 ; length
.write:
test ebp, ebp
jz .no_minus
dec ecx
inc edx
mov byte [ecx], '-'
.no_minus:
mov eax, 4 ; write
mov ebx, 1 ; stdout
int 0x80
add esp, 12 ; restore stack
popad ; restore regs
ret
; input in ESI, len in ECX, all regs unmodified
print_string:
pushad ; save regs
mov eax, 4 ; write
mov ebx, 1 ; stdout
mov edx, ecx ; length
mov ecx, esi ; string
int 0x80
popad ; restore regs
ret

3
11/Makefile Normal file
View File

@@ -0,0 +1,3 @@
all:
nasm -g -felf32 main.s && ld -melf_i386 -g main.o

140
11/input Normal file
View File

@@ -0,0 +1,140 @@
...........................#.......#.....................#................#.......................................#.............#...........
..................................................#...........................................#.......................................#.....
........#....................................#....................................#.......................#.................................
........................................................................................................................#...................
#...................#.......................................#...............................................................................
...............#.......................................................................#...........#...........#............#...............
........................................................#...........................................................................#.......
..............................................#.....................#...................................#...................................
.............................#......#.....................................#.................................................................
.......................#...........................#............................................#.................#.........................
.....#.....................................................................................................................................#
...........#......#...............................................#..............................................................#..........
.......................................................................................#...................#................................
..............................#........................#....................................................................#...............
.................................................#..........#......................................#........................................
........#................................#...................................................#..........#.....#......#......................
.........................#.........................................................................................................#........
............#.................................................................#.........#...................................................
....................#.......................................................................................................................
............................................#.............#.................................................................................
..............................#.....#...........................................................#........................................#..
#.........#........................................#............#................................................................#..........
.........................................................................................................#..................................
..................#.....................................#..............................#.............................#.......#..............
...........................#..............................................#.................................................................
...........................................................................................#......#.........................................
.......................#.......#..................#..........#....................................................................#......#..
.....#.............................................................#............................................#...........................
....................................#............................................#......................................#...................
.....................................................................................................................................#......
..............#.............................#.......#....................................#..................................................
.........#......................................................#.................................................#...........#.............
............................................................................................................................................
.#.....................................................................#..........#....................#....................................
..................................#....................................................................................................#....
...........#.........#............................#......#........................................#.........................................
................................................................................................................................#...........
..............................................................................................#.............................................
......................................#..............#.......................................................#...........#..................
....#............#.........................................#................................................................................
............#..............#.............................................................#..................................................
...............................................#...................................................#..........................#............#
..................................#.........................................................................................................
........................................................................#...........#...............................#.....#.................
#.........#..............#..................................................................................................................
.......................................................................................................................................#....
................#..........................................#................#................#.................#..................#.........
...................................................................#........................................................................
................................................#....................................................#......................................
.....................................................#..........................................#...........................................
..........................#.................................................................................................................
.....#.....#.....................................................................#.......#..............................#...................
.....................#........................#...............................................................#................#............
................................#........#............................................................#.....................................
.................................................................................................#................#.........................
..................................................................#.................................................................#.......
............................................................................................................................................
................................................#.....#.................#................#....................................#.............
......................#.....................................................................................#........#..................#...
..........#........................#................................................#.......................................................
....#.............#...................................................................................#...........................#.........
.........................................#..................................................#.....................#.........................
............................................................................................................................................
..........................#..................#..........................#.................................................#.................
.......................................................................................#......................#.............................
................................#......#.....................#................................#......................#..................#...
............................................................................................................................................
........#.........#.................................................................#.......................................#......#........
..........................................#........#........................................................................................
............................................................................................................................................
...............................................................................................#.......................#....................
............................#............................................................................#.................................#
............................................................................................................................................
......#...........#...................................#........#........#...................................................................
....................................................................................#.........................................#.............
.......................................#.........#......................................................................#...................
............................................................................................................................................
..............................#..................................................................................#..........................
.......................#......................................................#................#............................................
........#..........................................................#..................#................#...........................#........
.............#.....#................#.......................................................................................................
.........................................#...............................#.....................................#............................
.#...........................................................#...................#..................#.......................................
...........................#.................#............................................................................#.................
.......................................................#..................................................#.........#.....................#.
......................................................................................#........#............................................
......#.........#.................#............................#................................................................#...........
..........................................................................#.................................................................
...........#.........#.........................................................................................#............................
...........................................#..............#.................................................................#...............
.....................................................#.............#...................................................................#....
....#.........#.................#................................................................................................#..........
.......................#.......................................................#..................#........#............#...................
......................................#..................................#...................#..............................................
.......#.....................................#......................................................................#.......................
..#..........................#...........................#..........................#.......................................................
...........#.............................................................................#......................#......................#....
...............................................................#.........................................#..................#...............
.................#......................#........#...............................#..........................................................
......................#.......................................................................#......#..............................#.......
............................#......#......................#.................................................................................
...........................................#.............................#..........................................#.....#.................
...........#......................................................................................#.....................................#...
.......................................................#..........#....................................#.......#.................#..........
...............................#........................................................#...................................................
..#.....#.............................#................................#....................................................................
..................................................#...........................#.............................#...............................
.............................................................................................#.....#........................................
...............#........................................#.............................................................#.....................
#....................#...........#..........................................................................................................
............................#..............#..............................#.......................................................#.........
.....................................................................................#......................................................
.................#...........................................................................................#..............................
.........#..............#............................................................................................#...................#..
....................................#................#..............................................#.......................................
...............................#.........#.................#...................#.........................#..................#...............
#.............................................#........................................#....................................................
......................................................................#..........................................#..........................
.............#...............................................................................#........#...............................#.....
...#............................................................#............................................#..........#..................#
...................................................#........................................................................................
..........................................#..............................#..................................................#...............
.............................................................#....................#.....................................................#...
.....................#..............#..................#................................................#...................................
.......#.......................#........................................................#.......#..............#.................#..........
..........................................................................................................................#.................
...#.......................................#....................#...................#.......................................................
..................#.........................................................................................................................
...........................#...........#...................................................................#......#.........................
................................#.............#....................#........................................................................
.........................................................................................#.......#..........................................
.......#.....................................................#................................................................#...........#.
..................................................#.......................#.................................................................
.............#...................................................................................................#...................#......
............................#.........#................#.............................#................#.....................................
......................#.......................................................................#...........................#.................
............................................................................................................................................
.............................................................................................................#.......#............#.........
.......#...........#.....#.....#.............................#..............................................................................
.............#...............................#..........#..........................................#......................................#.

10
11/input_test Normal file
View File

@@ -0,0 +1,10 @@
...#......
.......#..
#.........
..........
......#...
.#........
.........#
..........
.......#..
#...#.....

278
11/main.s Normal file
View File

@@ -0,0 +1,278 @@
%define EXPANSION 1000000-1
global _start
[bits 32]
[section .text]
%include "utils.s"
_start:
; find line length
mov edi, file
mov ecx, file.over - file
mov al, 10 ; \n
repne scasb
mov eax, edi
sub eax, file
mov [line_len], eax
call print_dec
call newline
mov eax, -1
mov ecx, 512
mov edi, empty_rows
rep stosd
mov eax, -1
mov ecx, 512*2
mov edi, stars
rep stosd
; find empty rows
xor ebx, ebx
mov ebp, empty_rows
check_rows:
mov eax, [line_len]
mov ecx, eax
mul ebx
lea edi, [eax+file]
mov esi, edi
add esi, ecx
mov al, '.'
repe scasb
mov eax, esi
cmp edi, esi
jne .not_empty
.empty:
mov [ebp], ebx
add ebp, 4
.not_empty:
.cont:
inc ebx
cmp eax, file.over
jb check_rows
; find empty cols
xor ebx, ebx
mov ebp, empty_cols
check_cols:
lea edi, [file+ebx]
.l:
cmp edi, file.over
jae .empty
cmp byte [edi], '.'
jne .not_empty
add edi, [line_len]
jmp .l
.empty:
mov [ebp], ebx
add ebp, 4
.not_empty:
inc ebx
cmp ebx, [line_len]
jb check_cols
print_empty_rows:
mov esi, empty_str
mov ecx, 6
call print_string
mov esi, empty_rows
xor eax, eax
.l:
lodsd
cmp eax, -1
je .done
call space
call print_dec
jmp .l
.done:
call newline
print_empty_cols:
mov esi, empty_str
mov ecx, 6
call print_string
mov esi, empty_cols
xor eax, eax
.l:
lodsd
cmp eax, -1
je .done
call space
call print_dec
jmp .l
.done:
call newline
; find #s
xor ebx, ebx ; row
mov ebp, stars
find_stars:
mov eax, ebx
mul dword [line_len]
lea edi, [file+eax] ; row ptr
cmp edi, file.over
jae .done
xor ecx, ecx ; col
.for_cols:
cmp byte [edi+ecx], '#'
jne .for_cols_cont
mov eax, ebx
call print_dec
call space
mov [ebp], ebx ; row
mov eax, ecx
call print_dec
call newline
mov [ebp+4], ecx ; col
add ebp, 8
.for_cols_cont:
inc ecx
cmp ecx, [line_len]
jb .for_cols
inc ebx
jmp find_stars
.done:
call newline
; calc adjustments
calc_adj:
xor ecx, ecx
.fill:
mov [adj_rows+ecx*4], ecx
mov [adj_cols+ecx*4], ecx
inc ecx
cmp ecx, 256
jb .fill
; do rows
mov esi, empty_rows
.rows:
lodsd
cmp eax, -1
je .rows_done
inc eax
.add_to_rows:
add dword [adj_rows+eax*4], EXPANSION
inc eax
cmp eax, 256
jb .add_to_rows
jmp .rows
.rows_done:
; do cols
mov esi, empty_cols
.cols:
lodsd
cmp eax, -1
je .cols_done
inc eax
.add_to_cols:
add dword [adj_cols+eax*4], EXPANSION
inc eax
cmp eax, 256
jb .add_to_cols
jmp .cols
.cols_done:
; apply adjustments
apply_adj:
xor eax, eax
mov esi, stars
mov edi, stars
.l:
lodsd ; row
cmp eax, -1
je .done
mov eax, [adj_rows+eax*4]
stosd
lodsd ; col
mov eax, [adj_cols+eax*4]
stosd
jmp .l
.done:
; print stars
print_stars:
mov esi, stars
xor eax, eax
.l:
lodsd
cmp eax, -1
je .done
call print_dec
call space
lodsd
call print_dec
call newline
jmp .l
.done:
call newline
; calc distances
sub esp, 4
mov ebp, stars
calc_dist:
lea esi, [ebp+8]
mov ecx, [ebp] ; row
mov edx, [ebp+4] ; col
mov [esp], ebp
xor edi, edi ; running sum low
xor ebp, ebp ; running sum high
.to_next:
lodsd ; row
cmp eax, -1
je .all_added
sub eax, ecx
; abs (m := n>>31, n := (n+m)^m)
mov ebx, eax
sar ebx, 31
add eax, ebx
xor eax, ebx
; add to total
add edi, eax
adc ebp, 0
lodsd ; col
sub eax, edx
mov ebx, eax
sar ebx, 31
add eax, ebx
xor eax, ebx
; add to total
add edi, eax
adc ebp, 0
jmp .to_next
.all_added:
add dword [final_value], edi
adc dword [final_value_high], ebp
calc_dist_cont:
mov ebp, [esp]
add ebp, 8
cmp dword [ebp], -1
jne calc_dist
calc_dist_end:
add esp, 4
game_over:
; answer is penultimate + (ultimate * 2^32)
mov eax, [final_value]
call print_dec
call newline
mov eax, [final_value_high]
call print_dec
call newline
jmp exit
[section .data]
line_len: dd 0
final_value: dd 0
final_value_high: dd 0
file: incbin "input"
.over:
empty_str: db "Empty:"
not_empty_str: db "Not Empty:"
[section .bss]
empty_rows: resd 256
empty_cols: resd 256
adj_rows: resd 256
adj_cols: resd 256
stars: resd 512*2

267
11/main_part1.s Normal file
View File

@@ -0,0 +1,267 @@
global _start
[bits 32]
[section .text]
%include "utils.s"
_start:
; find line length
mov edi, file
mov ecx, file.over - file
mov al, 10 ; \n
repne scasb
mov eax, edi
sub eax, file
mov [line_len], eax
call print_dec
call newline
mov al, 0xff
mov ecx, 512
mov edi, empty_rows
rep stosb
mov eax, -1
mov ecx, 512
mov edi, stars
rep stosd
; find empty rows
xor ebx, ebx
mov ebp, empty_rows
check_rows:
mov eax, [line_len]
mov ecx, eax
mul ebx
lea edi, [eax+file]
mov esi, edi
add esi, ecx
mov al, '.'
repe scasb
mov eax, esi
cmp edi, esi
jne .not_empty
.empty:
mov [ebp], bl
inc ebp
.not_empty:
.cont:
inc ebx
cmp eax, file.over
jb check_rows
; find empty cols
xor ebx, ebx
mov ebp, empty_cols
check_cols:
lea edi, [file+ebx]
.l:
cmp edi, file.over
jae .empty
cmp byte [edi], '.'
jne .not_empty
add edi, [line_len]
jmp .l
.empty:
mov [ebp], bl
inc ebp
.not_empty:
inc ebx
cmp ebx, [line_len]
jb check_cols
print_empty_rows:
mov esi, empty_str
mov ecx, 6
call print_string
mov esi, empty_rows
xor eax, eax
.l:
lodsb
cmp al, -1
je .done
call space
call print_dec
jmp .l
.done:
call newline
print_empty_cols:
mov esi, empty_str
mov ecx, 6
call print_string
mov esi, empty_cols
xor eax, eax
.l:
lodsb
cmp al, -1
je .done
call space
call print_dec
jmp .l
.done:
call newline
; find #s
xor ebx, ebx ; row
mov ebp, stars
find_stars:
mov eax, ebx
mul dword [line_len]
lea edi, [file+eax] ; row ptr
cmp edi, file.over
jae .done
xor ecx, ecx ; col
.for_cols:
cmp byte [edi+ecx], '#'
jne .for_cols_cont
mov eax, ebx
call print_dec
call space
mov [ebp], bx ; row
mov eax, ecx
call print_dec
call newline
mov [ebp+2], cx ; col
add ebp, 4
.for_cols_cont:
inc ecx
cmp ecx, [line_len]
jb .for_cols
inc ebx
jmp find_stars
.done:
call newline
; calc adjustments
calc_adj:
xor ecx, ecx
.fill:
mov [adj_rows+ecx], cl
mov [adj_cols+ecx], cl
inc ecx
cmp ecx, 256
jb .fill
; do rows
mov esi, empty_rows
.rows:
lodsb
cmp al, -1
je .rows_done
movzx eax, al
inc eax
.add_to_rows:
inc byte [adj_rows+eax]
inc eax
cmp eax, 256
jb .add_to_rows
jmp .rows
.rows_done:
; do cols
mov esi, empty_cols
.cols:
lodsb
cmp al, -1
je .cols_done
movzx eax, al
inc eax
.add_to_cols:
inc byte [adj_cols+eax]
inc eax
cmp eax, 256
jb .add_to_cols
jmp .cols
.cols_done:
; apply adjustments
apply_adj:
xor eax, eax
mov esi, stars
mov edi, stars
.l:
lodsw ; row
cmp ax, -1
je .done
mov al, [adj_rows+eax]
stosw
lodsw ; col
mov al, [adj_cols+eax]
stosw
jmp .l
.done:
; print stars
print_stars:
mov esi, stars
xor eax, eax
.l:
lodsw
cmp ax, -1
je .done
call print_dec
call space
lodsw
call print_dec
call newline
jmp .l
.done:
call newline
; calc distances
mov ebp, stars
xor edi, edi ; running total
calc_dist:
lea esi, [ebp+4]
movzx ecx, word [ebp] ; row
movzx edx, word [ebp+2] ; col
xor eax, eax
.to_next:
lodsw ; row
cmp ax, -1
je .all_added
sub eax, ecx
; abs (m := n>>31, n := (n+m)^m)
mov ebx, eax
sar ebx, 31
add eax, ebx
xor eax, ebx
; add to total
add edi, eax
lodsw ; col
sub eax, edx
mov ebx, eax
sar ebx, 31
add eax, ebx
xor eax, ebx
; add to total
add edi, eax
jmp .to_next
.all_added:
calc_dist_cont:
add ebp, 4
cmp dword [ebp], -1
jne calc_dist
calc_dist_end:
mov [final_value], edi
game_over:
mov eax, [final_value]
call print_dec
call newline
jmp exit
[section .data]
line_len: dd 0
final_value: dd 0
file: incbin "input"
.over:
empty_str: db "Empty:"
not_empty_str: db "Not Empty:"
[section .bss]
empty_rows: resb 256
empty_cols: resb 256
adj_rows: resb 256
adj_cols: resb 256
stars: resd 512

258
11/utils.s Normal file
View File

@@ -0,0 +1,258 @@
; call # val val2
; int $0x80 eax eax edx -
;
; arg1 arg2 arg3 arg4 arg5 arg6 arg7
; ebx ecx edx esi edi ebp -
exit:
mov eax, 1 ; exit
int 0x80
; filename in EBX
; return handle in EBX
; read only
open_file:
push eax
push ecx
mov eax, 5 ; open
xor ecx, ecx ; read only
int 0x80
mov ebx, eax
pop ecx
pop eax
ret
; file handle in EBX
; buffer in ECX
; count of bytes to read in EDX
; return bytes actually read in EAX
; exits on error
read_file:
mov eax, 3 ; read
int 0x80
test eax, eax
js .err
ret
.err:
mov eax, 4 ; write
mov ebx, 1 ; stdout
mov ecx, .err_str
mov edx, 21
int 0x80
jmp exit
.err_str: db `Could not read file.\n`
; string input in ESI
; value in EAX
; CF set if none, clear if some
; ESI set past checked area
dec_parse:
push ebx
push edx
push edi
xor eax, eax
xor edi, edi
mov ebx, 10 ; base
lodsb
sub al, '0'
js .no_input
cmp al, 9
jle .got_char
.no_input:
stc ; set CF
jmp .done
.loop:
xor eax,eax
lodsb
sub al, '0'
js .dec_done
cmp al, 9
jg .dec_done
.got_char:
xchg edi,eax
mul ebx
add edi,eax
jmp .loop
.dec_done:
clc ; clear CF
.done:
mov eax,edi
pop edi
pop edx
pop ebx
ret
; string input in ESI
; value in EAX
; CF set if none, clear if some
; ESI set past checked area
sign_dec_parse:
push ebx
push ecx
push edx
push edi
xor eax, eax
xor edi, edi
xor ecx, ecx ; neg flag
mov ebx, 10 ; base
cmp byte [esi], '-'
jne .no_minus
inc esi
mov cl, 1
.no_minus:
lodsb
sub al, '0'
js .no_input
cmp al, 9
jle .got_char
.no_input:
stc ; set CF
jmp .done
.loop:
xor eax,eax
lodsb
sub al, '0'
js .dec_done
cmp al, 9
jg .dec_done
.got_char:
xchg edi,eax
mul ebx
add edi,eax
jmp .loop
.dec_done:
test ecx, ecx
jz .not_neg
neg edi
.not_neg:
clc ; clear CF
.done:
mov eax,edi
pop edi
pop edx
pop ecx
pop ebx
ret
; modifies no regs
newline:
pushad
push 10
mov eax, 4 ; write
mov ebx, 1 ; stdout
mov ecx, esp ; string
mov edx, 1 ; length
int 0x80
add esp, 4
popad
ret
; modifies no regs
space:
pushad
push 9
mov eax, 4 ; write
mov ebx, 1 ; stdout
mov ecx, esp ; string
mov edx, 1 ; length
int 0x80
add esp, 4
popad
ret
; input in EAX, all regs unmodified
print_dec:
pushad ; save regs
; max 4294967296 is 10 chars
; round to nearest 32-bit boundary
sub esp, 12
; string in ECX, length in EDX
lea ecx, [esp+11] ; last possible byte
; check for 0
test eax, eax
jz .zero
mov ebx, 10 ; base 10
xor esi, esi ; counter
.div_shit:
xor edx, edx
; divide
div ebx
dec ecx ; next char
inc esi
; store
add dl, '0'
mov byte [ecx], dl
; check if done
test eax, eax
jnz .div_shit ; continue
mov edx, esi ; counter in edx
jmp .write
.zero:
mov byte [ecx], '0'
mov edx, 1 ; length
.write:
mov eax, 4 ; write
mov ebx, 1 ; stdout
int 0x80
add esp, 12 ; restore stack
popad ; restore regs
ret
; input in EAX, all regs unmodified
print_sign_dec:
pushad ; save regs
; range -2147483648 to 2147483647 is 11 chars
; round to nearest 32-bit boundary
sub esp, 12
; string in ECX, length in EDX
lea ecx, [esp+11] ; last possible byte
; check for 0, negative
xor ebp, ebp
test eax, eax
jz .zero
jns .positive
neg eax
mov ebp, 1
.positive:
mov ebx, 10 ; base 10
xor esi, esi ; counter
.div_shit:
xor edx, edx
; divide
div ebx
dec ecx ; next char
inc esi
; store
add dl, '0'
mov byte [ecx], dl
; check if done
test eax, eax
jnz .div_shit ; continue
mov edx, esi ; counter in edx
jmp .write
.zero:
mov byte [ecx], '0'
mov edx, 1 ; length
.write:
test ebp, ebp
jz .no_minus
dec ecx
inc edx
mov byte [ecx], '-'
.no_minus:
mov eax, 4 ; write
mov ebx, 1 ; stdout
int 0x80
add esp, 12 ; restore stack
popad ; restore regs
ret
; input in ESI, len in ECX, all regs unmodified
print_string:
pushad ; save regs
mov eax, 4 ; write
mov ebx, 1 ; stdout
mov edx, ecx ; length
mov ecx, esi ; string
int 0x80
popad ; restore regs
ret

3
12/Makefile Normal file
View File

@@ -0,0 +1,3 @@
all:
nasm -g -felf32 main.s && ld -melf_i386 -g main.o

1000
12/input Normal file

File diff suppressed because it is too large Load Diff

1001
12/input5 Normal file

File diff suppressed because it is too large Load Diff

7
12/input_test Normal file
View File

@@ -0,0 +1,7 @@
???.### 1,1,3
.??..??...?##. 1,1,3
?#?#?#?#?#?#?#? 1,3,1,6
????.#...#... 4,1,1
????.######..#####. 1,6,5
?###???????? 3,2,1

171
12/main.s Normal file
View File

@@ -0,0 +1,171 @@
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 dword [contiguous_broken+16], 0
mov dword [contiguous_broken+20], 0
mov dword [contiguous_broken+24], 0
mov dword [contiguous_broken+28], 0
mov dword [contiguous_broken+32], 0
mov dword [contiguous_broken+36], 0
mov dword [contiguous_broken+40], 0
mov dword [contiguous_broken+44], 0
mov dword [contiguous_broken+48], 0
mov dword [contiguous_broken+52], 0
mov dword [contiguous_broken+56], 0
mov dword [contiguous_broken+60], 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
; clear cache
mov edi, cache
mov ecx, (cache.end - cache)/4
mov eax, -1
rep stosd
; setup do_stream vars
xor esi, esi ; line idx
mov ebp, [line_len]
xor edi, edi ; contiguous_broken idx
xor edx, edx ; poss_counter high
xor ebx, ebx ; poss_counter low
call do_stream ; call into recursive routine
add [final_value+0], ebx ; poss_counter low
adc [final_value+4], edx ; poss_counter high
mov eax, edx
call print_dec
call space
mov eax, ebx
call print_dec
call newline
jmp parse_line_cont
do_stream:
cmp byte [line+esi], '.'
je .cont
cmp byte [line+esi], '#'
jne .branch
.broke:
cmp byte [contiguous_broken+edi], 0
je .ret ; branch impossible
movzx ecx, byte [contiguous_broken+edi]
inc edi
.consume_things:
mov al, byte [line+esi]
inc esi
cmp esi, ebp
ja .ret ; branch impossible
cmp al, '.'
je .ret ; branch impossible
loop .consume_things
cmp esi, ebp
je .cont
cmp byte [line+esi], '#'
je .ret ; branch impossible
; .cont consumes . or ? (must be .)
jmp .cont
.branch: ; recursive branch
mov eax, esi
shl eax, 8 ; *256
cmp dword [eax+edi*8+cache], -1
je .not_cached
add ebx, [eax+edi*8+(cache+0)]
adc edx, [eax+edi*8+(cache+4)]
jmp .cont
.not_cached:
push edx
push ebx
push esi
push edi
xor ebx, ebx
xor edx, edx
call do_stream.broke ; assume #
pop edi
pop esi
mov eax, esi
shl eax, 8
mov [eax+edi*8+(cache+0)], ebx
mov [eax+edi*8+(cache+4)], edx
pop eax
add ebx, eax
pop eax
adc edx, eax
; assume .
.cont:
inc esi
cmp esi, ebp
jb do_stream
; iff we are at the end of stream
; and contiguous_broken is exhausted
; we add a possibility
cmp byte [contiguous_broken+edi], 0
jne .ret
add ebx, 1 ; poss counter
adc edx, 0
.ret:
ret
parse_line_cont:
pop esi
cmp esi, file.over-1
jb parse_line
call newline
game_over:
mov eax, [final_value+4]
call print_dec
call space
mov eax, [final_value+0]
call print_dec
call newline
jmp exit
[section .data]
line_len: dd 0
final_value: dd 0, 0
final_setting: dd 0, 0
curr_setting: dd 0, 0
file: incbin "input5"
.over:
nl_str: db "new line!"
.over:
[section .bss]
contiguous_broken: resb 64
line: resb 512
cache: resd 256*64*2
cache.end:

124
12/main_part1.s Normal file
View File

@@ -0,0 +1,124 @@
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

258
12/utils.s Normal file
View File

@@ -0,0 +1,258 @@
; call # val val2
; int $0x80 eax eax edx -
;
; arg1 arg2 arg3 arg4 arg5 arg6 arg7
; ebx ecx edx esi edi ebp -
exit:
mov eax, 1 ; exit
int 0x80
; filename in EBX
; return handle in EBX
; read only
open_file:
push eax
push ecx
mov eax, 5 ; open
xor ecx, ecx ; read only
int 0x80
mov ebx, eax
pop ecx
pop eax
ret
; file handle in EBX
; buffer in ECX
; count of bytes to read in EDX
; return bytes actually read in EAX
; exits on error
read_file:
mov eax, 3 ; read
int 0x80
test eax, eax
js .err
ret
.err:
mov eax, 4 ; write
mov ebx, 1 ; stdout
mov ecx, .err_str
mov edx, 21
int 0x80
jmp exit
.err_str: db `Could not read file.\n`
; string input in ESI
; value in EAX
; CF set if none, clear if some
; ESI set past checked area
dec_parse:
push ebx
push edx
push edi
xor eax, eax
xor edi, edi
mov ebx, 10 ; base
lodsb
sub al, '0'
js .no_input
cmp al, 9
jle .got_char
.no_input:
stc ; set CF
jmp .done
.loop:
xor eax,eax
lodsb
sub al, '0'
js .dec_done
cmp al, 9
jg .dec_done
.got_char:
xchg edi,eax
mul ebx
add edi,eax
jmp .loop
.dec_done:
clc ; clear CF
.done:
mov eax,edi
pop edi
pop edx
pop ebx
ret
; string input in ESI
; value in EAX
; CF set if none, clear if some
; ESI set past checked area
sign_dec_parse:
push ebx
push ecx
push edx
push edi
xor eax, eax
xor edi, edi
xor ecx, ecx ; neg flag
mov ebx, 10 ; base
cmp byte [esi], '-'
jne .no_minus
inc esi
mov cl, 1
.no_minus:
lodsb
sub al, '0'
js .no_input
cmp al, 9
jle .got_char
.no_input:
stc ; set CF
jmp .done
.loop:
xor eax,eax
lodsb
sub al, '0'
js .dec_done
cmp al, 9
jg .dec_done
.got_char:
xchg edi,eax
mul ebx
add edi,eax
jmp .loop
.dec_done:
test ecx, ecx
jz .not_neg
neg edi
.not_neg:
clc ; clear CF
.done:
mov eax,edi
pop edi
pop edx
pop ecx
pop ebx
ret
; modifies no regs
newline:
pushad
push 10
mov eax, 4 ; write
mov ebx, 1 ; stdout
mov ecx, esp ; string
mov edx, 1 ; length
int 0x80
add esp, 4
popad
ret
; modifies no regs
space:
pushad
push 9
mov eax, 4 ; write
mov ebx, 1 ; stdout
mov ecx, esp ; string
mov edx, 1 ; length
int 0x80
add esp, 4
popad
ret
; input in EAX, all regs unmodified
print_dec:
pushad ; save regs
; max 4294967296 is 10 chars
; round to nearest 32-bit boundary
sub esp, 12
; string in ECX, length in EDX
lea ecx, [esp+11] ; last possible byte
; check for 0
test eax, eax
jz .zero
mov ebx, 10 ; base 10
xor esi, esi ; counter
.div_shit:
xor edx, edx
; divide
div ebx
dec ecx ; next char
inc esi
; store
add dl, '0'
mov byte [ecx], dl
; check if done
test eax, eax
jnz .div_shit ; continue
mov edx, esi ; counter in edx
jmp .write
.zero:
mov byte [ecx], '0'
mov edx, 1 ; length
.write:
mov eax, 4 ; write
mov ebx, 1 ; stdout
int 0x80
add esp, 12 ; restore stack
popad ; restore regs
ret
; input in EAX, all regs unmodified
print_sign_dec:
pushad ; save regs
; range -2147483648 to 2147483647 is 11 chars
; round to nearest 32-bit boundary
sub esp, 12
; string in ECX, length in EDX
lea ecx, [esp+11] ; last possible byte
; check for 0, negative
xor ebp, ebp
test eax, eax
jz .zero
jns .positive
neg eax
mov ebp, 1
.positive:
mov ebx, 10 ; base 10
xor esi, esi ; counter
.div_shit:
xor edx, edx
; divide
div ebx
dec ecx ; next char
inc esi
; store
add dl, '0'
mov byte [ecx], dl
; check if done
test eax, eax
jnz .div_shit ; continue
mov edx, esi ; counter in edx
jmp .write
.zero:
mov byte [ecx], '0'
mov edx, 1 ; length
.write:
test ebp, ebp
jz .no_minus
dec ecx
inc edx
mov byte [ecx], '-'
.no_minus:
mov eax, 4 ; write
mov ebx, 1 ; stdout
int 0x80
add esp, 12 ; restore stack
popad ; restore regs
ret
; input in ESI, len in ECX, all regs unmodified
print_string:
pushad ; save regs
mov eax, 4 ; write
mov ebx, 1 ; stdout
mov edx, ecx ; length
mov ecx, esi ; string
int 0x80
popad ; restore regs
ret

3
13/Makefile Normal file
View File

@@ -0,0 +1,3 @@
all:
nasm -g -felf32 main.s && ld -melf_i386 -g main.o

1351
13/input Normal file

File diff suppressed because it is too large Load Diff

17
13/input_test Normal file
View File

@@ -0,0 +1,17 @@
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
#.##..##.
..#.##.#.
##......#
##......#
..#.##.#.
..##..##.
#.#.##.#.
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
#...##..#
#....#..#
..##..###
#####.##.
#####.##.
..##..###
#....#..#
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!@

159
13/main.s Normal file
View File

@@ -0,0 +1,159 @@
global _start
[bits 32]
[section .text]
%include "utils.s"
_start:
mov dword [start], file
jmp do_line_cont
do_line:
; line len
mov esi, edi ; start
mov ecx, 1024
mov al, 10 ; \n
repne scasb
mov eax, edi
sub eax, esi
mov [line_len], eax
mov [start], esi
jmp vert_loop
do_line_cont:
; get next input
mov al, '!'
mov ecx, 1024
mov edi, [start]
repne scasb
mov ecx, 1024
repe scasb
cmp byte [edi-1], '@'
je game_over
.skip_newline:
cmp byte [edi], 10
jne do_line
inc edi
jmp .skip_newline
vert_loop:
mov ebp, [line_len]
mov edx, 1 ; col num
mov esi, [start] ; first col
.check_cols:
cmp byte [esi+1], 10 ; \n
je .done
lea edi, [esi+1]
push esi
xor ecx, ecx ; wrong thing count
jmp .check_rows
.cont:
pop esi
inc esi
inc edx
jmp .check_cols
.potential_mirror:
inc edi
dec esi
cmp byte [edi], 10
je .mirror
cmp byte [esi], 10
je .mirror
; esi left col edi right col
.check_rows:
xor eax, eax ; row 0
.check_rows_l:
mov bl, [esi+eax]
mov bh, [edi+eax]
cmp bl, '!'
je .potential_mirror
cmp bh, bl
je .eq
inc cl
cmp cl, 2
je .cont
.eq:
add eax, ebp
jmp .check_rows_l
.mirror:
cmp cl, 0 ; we want *exactly* one wrong
je .cont
mov eax, edx
call print_dec
call newline
add [final_value], eax
add esp, 4
jmp do_line_cont
.done:
horz_loop:
mov ebp, [line_len]
mov edx, 1 ; col num
mov esi, [start] ; first row
.check_rows:
cmp byte [esi+ebp], '!'
je .done
lea edi, [esi+ebp]
push esi
xor ecx, ecx ; wrong thing count
jmp .check_cols
.cont:
pop esi
add esi, ebp
inc edx
jmp .check_rows
.potential_mirror:
add edi, ebp
sub esi, ebp
cmp byte [edi], '!'
je .mirror
cmp byte [esi], '!'
je .mirror
; esi up row edi down row
.check_cols:
xor eax, eax ; row 0
.check_cols_l:
mov bl, [esi+eax]
mov bh, [edi+eax]
cmp bl, 10
je .potential_mirror
cmp bh, bl
je .eq
inc cl
cmp cl, 2
je .cont
.eq:
inc eax
jmp .check_cols_l
.mirror:
cmp cl, 0 ; we want *exactly* one wrong
je .cont
mov eax, edx
call space
call print_dec
call newline
mov ebx, 100
mul ebx
add [final_value], eax
add esp, 4
.done:
jmp do_line_cont
game_over:
call newline
call newline
mov eax, [final_value]
call print_dec
call newline
jmp exit
[section .data]
final_value: dd 0
start: dd 0
line_len: dd 0
file: incbin "input"
.over:
[section .bss]

145
13/main_part1.s Normal file
View File

@@ -0,0 +1,145 @@
global _start
[bits 32]
[section .text]
%include "utils.s"
_start:
mov dword [start], file
jmp do_line_cont
do_line:
; line len
mov esi, edi ; start
mov ecx, 1024
mov al, 10 ; \n
repne scasb
mov eax, edi
sub eax, esi
mov [line_len], eax
mov [start], esi
jmp vert_loop
do_line_cont:
; get next input
mov al, '!'
mov ecx, 1024
mov edi, [start]
repne scasb
mov ecx, 1024
repe scasb
cmp byte [edi-1], '@'
je game_over
.skip_newline:
cmp byte [edi], 10
jne do_line
inc edi
jmp .skip_newline
vert_loop:
mov ebp, [line_len]
mov edx, 1 ; col num
mov esi, [start] ; first col
.check_cols:
cmp byte [esi+1], 10 ; \n
je .done
lea edi, [esi+1]
push esi
jmp .check_rows
.cont:
pop esi
inc esi
inc edx
jmp .check_cols
.potential_mirror:
inc edi
dec esi
cmp byte [edi], 10
je .mirror
cmp byte [esi], 10
je .mirror
; esi left col edi right col
.check_rows:
xor eax, eax ; row 0
.check_rows_l:
mov bl, [esi+eax]
mov bh, [edi+eax]
cmp bl, '!'
je .potential_mirror
cmp bh, bl
jne .cont
add eax, ebp
jmp .check_rows_l
.mirror:
mov eax, edx
call print_dec
call newline
add [final_value], eax
add esp, 4
jmp do_line_cont
.done:
horz_loop:
mov ebp, [line_len]
mov edx, 1 ; col num
mov esi, [start] ; first row
.check_rows:
cmp byte [esi+ebp], '!'
je .done
lea edi, [esi+ebp]
push esi
jmp .check_cols
.cont:
pop esi
add esi, ebp
inc edx
jmp .check_rows
.potential_mirror:
add edi, ebp
sub esi, ebp
cmp byte [edi], '!'
je .mirror
cmp byte [esi], '!'
je .mirror
; esi up row edi down row
.check_cols:
xor eax, eax ; row 0
.check_cols_l:
mov bl, [esi+eax]
mov bh, [edi+eax]
cmp bl, 10
je .potential_mirror
cmp bh, bl
jne .cont
inc eax
jmp .check_cols_l
.mirror:
mov eax, edx
call space
call print_dec
call newline
mov ebx, 100
mul ebx
add [final_value], eax
add esp, 4
.done:
jmp do_line_cont
game_over:
call newline
call newline
mov eax, [final_value]
call print_dec
call newline
jmp exit
[section .data]
final_value: dd 0
start: dd 0
line_len: dd 0
file: incbin "input"
.over:
[section .bss]

258
13/utils.s Normal file
View File

@@ -0,0 +1,258 @@
; call # val val2
; int $0x80 eax eax edx -
;
; arg1 arg2 arg3 arg4 arg5 arg6 arg7
; ebx ecx edx esi edi ebp -
exit:
mov eax, 1 ; exit
int 0x80
; filename in EBX
; return handle in EBX
; read only
open_file:
push eax
push ecx
mov eax, 5 ; open
xor ecx, ecx ; read only
int 0x80
mov ebx, eax
pop ecx
pop eax
ret
; file handle in EBX
; buffer in ECX
; count of bytes to read in EDX
; return bytes actually read in EAX
; exits on error
read_file:
mov eax, 3 ; read
int 0x80
test eax, eax
js .err
ret
.err:
mov eax, 4 ; write
mov ebx, 1 ; stdout
mov ecx, .err_str
mov edx, 21
int 0x80
jmp exit
.err_str: db `Could not read file.\n`
; string input in ESI
; value in EAX
; CF set if none, clear if some
; ESI set past checked area
dec_parse:
push ebx
push edx
push edi
xor eax, eax
xor edi, edi
mov ebx, 10 ; base
lodsb
sub al, '0'
js .no_input
cmp al, 9
jle .got_char
.no_input:
stc ; set CF
jmp .done
.loop:
xor eax,eax
lodsb
sub al, '0'
js .dec_done
cmp al, 9
jg .dec_done
.got_char:
xchg edi,eax
mul ebx
add edi,eax
jmp .loop
.dec_done:
clc ; clear CF
.done:
mov eax,edi
pop edi
pop edx
pop ebx
ret
; string input in ESI
; value in EAX
; CF set if none, clear if some
; ESI set past checked area
sign_dec_parse:
push ebx
push ecx
push edx
push edi
xor eax, eax
xor edi, edi
xor ecx, ecx ; neg flag
mov ebx, 10 ; base
cmp byte [esi], '-'
jne .no_minus
inc esi
mov cl, 1
.no_minus:
lodsb
sub al, '0'
js .no_input
cmp al, 9
jle .got_char
.no_input:
stc ; set CF
jmp .done
.loop:
xor eax,eax
lodsb
sub al, '0'
js .dec_done
cmp al, 9
jg .dec_done
.got_char:
xchg edi,eax
mul ebx
add edi,eax
jmp .loop
.dec_done:
test ecx, ecx
jz .not_neg
neg edi
.not_neg:
clc ; clear CF
.done:
mov eax,edi
pop edi
pop edx
pop ecx
pop ebx
ret
; modifies no regs
newline:
pushad
push 10
mov eax, 4 ; write
mov ebx, 1 ; stdout
mov ecx, esp ; string
mov edx, 1 ; length
int 0x80
add esp, 4
popad
ret
; modifies no regs
space:
pushad
push 9
mov eax, 4 ; write
mov ebx, 1 ; stdout
mov ecx, esp ; string
mov edx, 1 ; length
int 0x80
add esp, 4
popad
ret
; input in EAX, all regs unmodified
print_dec:
pushad ; save regs
; max 4294967296 is 10 chars
; round to nearest 32-bit boundary
sub esp, 12
; string in ECX, length in EDX
lea ecx, [esp+11] ; last possible byte
; check for 0
test eax, eax
jz .zero
mov ebx, 10 ; base 10
xor esi, esi ; counter
.div_shit:
xor edx, edx
; divide
div ebx
dec ecx ; next char
inc esi
; store
add dl, '0'
mov byte [ecx], dl
; check if done
test eax, eax
jnz .div_shit ; continue
mov edx, esi ; counter in edx
jmp .write
.zero:
mov byte [ecx], '0'
mov edx, 1 ; length
.write:
mov eax, 4 ; write
mov ebx, 1 ; stdout
int 0x80
add esp, 12 ; restore stack
popad ; restore regs
ret
; input in EAX, all regs unmodified
print_sign_dec:
pushad ; save regs
; range -2147483648 to 2147483647 is 11 chars
; round to nearest 32-bit boundary
sub esp, 12
; string in ECX, length in EDX
lea ecx, [esp+11] ; last possible byte
; check for 0, negative
xor ebp, ebp
test eax, eax
jz .zero
jns .positive
neg eax
mov ebp, 1
.positive:
mov ebx, 10 ; base 10
xor esi, esi ; counter
.div_shit:
xor edx, edx
; divide
div ebx
dec ecx ; next char
inc esi
; store
add dl, '0'
mov byte [ecx], dl
; check if done
test eax, eax
jnz .div_shit ; continue
mov edx, esi ; counter in edx
jmp .write
.zero:
mov byte [ecx], '0'
mov edx, 1 ; length
.write:
test ebp, ebp
jz .no_minus
dec ecx
inc edx
mov byte [ecx], '-'
.no_minus:
mov eax, 4 ; write
mov ebx, 1 ; stdout
int 0x80
add esp, 12 ; restore stack
popad ; restore regs
ret
; input in ESI, len in ECX, all regs unmodified
print_string:
pushad ; save regs
mov eax, 4 ; write
mov ebx, 1 ; stdout
mov edx, ecx ; length
mov ecx, esi ; string
int 0x80
popad ; restore regs
ret

3
14/Makefile Normal file
View File

@@ -0,0 +1,3 @@
all:
nasm -g -felf32 main.s && ld -melf_i386 -g main.o

101
14/input Normal file
View File

@@ -0,0 +1,101 @@
......O........#....O..O.O#O.O.##.O#.O##.O#......O........O....O.#..OO#.OO.#..#.........#.O..#O..#.O
O#..O...O....O.#...##.O....O..O.#...#...O..O#.#.#......#.O##O#....#..O...O..#.#......#.#O..#..#....#
O....##.O#O##.O...#...#.#.......OO.##..###.OO..O.#.#.OO#O..##..O.O.#...#..O.#....O.##.O#OO..........
....O#.O..OO.#..OOOO#.......O.....O.#O......OOO#....O.....O......O.....#..OOO.....O...O.O##OO.....##
OO#..#.O.##..##..#........O..OO.......#..O.OO.OO..#O...OO.##...#.OOO...O.O.O..#.O..#..O.O.##.O...OOO
#.....#OO.O......O..####O...O.....O.......#..#OO#..#...O...OOO.#....O#.....O...........#O#OO...O..O.
#O.O......O...O.O...O##.O#..OO....O..##.OO#O.##O.#.#.......O.O#.....OOOO......#..OO###OO.......O..#.
#.O.OO...#...##.O..OO..#.......O.O.O.O......O#....##.OOO.O.....#O#..##...OO.......#OOO.O..O......##.
..O.OO.O.#O.O........#..##.#.OO.O..##.O...O.#.....#..O.#....O..#O..O.#OO......O........#.#....#O..#.
..O......OO.O............OO#....##....#......O.#..O..O...O.O..#O......O.OO#.#.......O....#....##.O.#
.....#.O#O.#..#.#.##....#O....O.O.O.OO......#..O.O..#..OOOO....#.#..O.#.O.O..O.O#.O...O#..#..O##.O..
O..O#.OO.#.##.#.........OO.#.....#OO...........O....O..OO..O.O###..O.O.#O...O.O...#...O..O#O...OO...
.#.#...OO...#.O...O.........#OO..#.....O....##.#.OO.#.#.#OOO...#OOO.O.O..O#......#.##..........O....
....#..#...#...#.......#..#......##..O........O.OO.#O..#O.#.......#..#..O.O#.#...O#..O...O#.O...O.#O
.#O#O.O..........#O##.O#.#.........##.#............#.#.....#..#OO...#O....#OO.O.OO.#..#...O#........
.#..#.O#O...##O....O.....##...OOO#...#O..#..O##O..#..OO.#...#O.....#.O...O#.O#.OO...###.#..O#O..OO..
...#...O....O.#....#..#.O#OO...O.O#.#....O..#OO.#.O....#O#...O...O..O.##O..#.......O.##....O##....O.
#...O...O...O#O##O.O.#.#.....#.O...#.....##..#.#OO....OO#.......#..O..O.#.#O...#.#.#.....OO.O...OO..
.O...OO.O.....##.O.##.#O.....#O..O.###..#..##.O.##O....OO..#O#....O.....O...#O#O...OO.........O..##O
.O..OO.#O.#...O...O...#...O....#.O.O.O....#O.###O.#..#..##OO.O...O.#.#.#..O...#.....O.#.O.O.#..O....
O...OO.#...O.#..#.O..O#..O#....##.#O.##...#......#O#O..O..#.##.....O...#O#..O.O...OO...OO..#.OO.O.OO
.O.O....O.O.##O#....##..##O......#.#O#..O..#...OO..O...O.#..#O#..#..#.O...#.O.OO....O#..O##.O..O..O.
....#..O..O.OO.#.O...#OOOOO.OO.O#..O....#.#O.##........#OO.#.#.O.#.OO#...#OO..#.OO...O..#.O.....O#.#
.#O...O......#OOO#..#..#....O...O..O.#O....#O#...O..#...OO.#.O.O...O..#..#..O..##.O##.....O.O..OO..#
..#O.##.#.......OOOO.OO.....O..O........##.O.OO....O###..#.O...#O.O.#OO.#....O.O.#..........#.OO....
.##...##.#......O.#.OO#...#..O##..#..##.O.......O#..O.O.#.O..#.....#..O#....O....OO.OO.O..#...O#..O.
..##O##O......O.#O.O.....#..#.#O#.O..#O#O..#OO.#..#.#.....##O.................O.....O#OO...##...O..O
....#O#O..O.#..O....#.....#.....#......O.#O........O#..O.O#..OO...#.#.O..##....O.....#......O#....#.
#.....#...O....OO..O##.OO....O.#..#O.........O..............O....##OO##.....#.##.O...#..O..#O#OO...O
...O.#O#...O..OO#...O.#O#.......#..O...O#.#..#O...#.O.O....O##...##...#.OO...O.O..OO#.#..........##.
.......#OO....#.#O#..........O.##.O.O#.....O.OO.O.OO##...##O...OO.O..O#.OO...O......O#O..O.O.##...OO
..O.O#.#.....OO............O.O..#.O#.O.O.#.##.#O.O...#.O.....O..#.#....O..#O#O....O.O.#..OOO..O..O..
..O.#.O.............#OO#.#O....#O#...OO..O##...#.....O...............#..#..O..O#....O..##...O..O.O#.
...........O.........##O#.#.O.O..O##........#..#....#O..##O..##.OO...O#.##..#..#.#O....O.O.#........
...............OOO.#........O....#.#O..##.O...O.O#.......#.#O.#...#O.......###.......O.OO...O.O..O.#
.#.O#....#......O...OO##..O#O...O.O#.O.##.OO...OOOO....OO....#.#....##.###.O.O..O..##....#..........
..OO.....OO#O.........O.#..O....#......#.#.#.#...##O.OO#.O......O..O.#O....O#...OOO....O..O.O..#..#O
#O...O.O.......##..#..O..O...O...O..O.#..#.#.O.OO............OO....#OOOO#...OO.#.O#OO....O##.O....#.
.O#..OOO.O.#.......O....#......O.OO.#......#..#.O.......###.#....#O..O....O#.O.....#O#....O#.#.....#
....OOO#.#..#.O..O....#...O.#...OO....#..OO.O#O..O....O.O...O...O#O..O..O......O.#O..O#O..........O#
..O..#.OO###....#..O....#.O..#.....O.O.#..OOO.O...##...O#..##..O#.O.......O.#.###...O.....O......O..
..O##..OO..O.O...O.#....OO.OOO.O........O......#.O..O..........O...O#OOO..O....O.#..O##O.......#....
O.O..OO##.#...#O#..#...O..#.......#O..###..OOO..O..#.O#.O..#....O.OO#.##..##O.......OO#OO..#.O....#O
...#..O.#........OO.O....OOO#.O..O#O.......O....O........#O#...#O#.#..OO..O....#O.O....O...O###.#...
O..#.......#..#.....O..OOO.#..#OO...#O.O...O.....##O.O.#O....#.....#...#.........OO.O....#...O#O#...
.O..O.#O....O#O.###....#O.O.....................###......O..#...O.OO.....#.......O..#...OO.......##.
............#O#..#.#.......#.##....#O.#....O.#...O...OOO.O.....#O..####O...O..#..#.O##....#OO##.#.#.
....O.#..#.....#...#OO#.##...O..OO....#....O#..O......OO.OO.#OO....#.O..#.....#.##..#.O...O.O#.##O..
...#OO#.O.O......#...O.O.....#......#.......................#.#.....O..O.#OO.#..OOO.OO.O.......#..#.
O#..#OO.OO.O#....##.O.#....OO..#.#.....O...O...#.O...O...O..#..O.....O..OO..O...O...O#....#...O.O...
.......OO.#O..#O#OO.#.............#....O.O#..#..#.....#..O.O#..#..##O.O.O...O.O.#O..OO..#O...OO...#.
#..#O.O.O.....O..O#.#............##O#....O.O#...#...............#OO..O.....#...OOO#.......OO...#....
..#...O...OO..#...O#O.O.O.O....O..#O#O......#.#....#..OO....#O...OO.O..O#.#O#OO.#...O.O.O..#....##.O
..#..O#..##.O...O..O....O.O.#.....#.O.OO..#.#.#...OO#....#..#O........OO.OO#.#..#..##O...O.OO.O#.#..
...#O..OO.O#OO..O#O#O....#O....#.O#.OO.##.......O.O.OO##.......#.O.O.#O.##.......O..O....##.#O..#..#
#....##...O.......#..#OO.........#O.O.O.O#...O......O.......OO##....O....#.#O.#.#.....O.OO..#...O.O.
.O..O#.....O.#..O..#..#O..O.O...O..O.#....#.....#.#.O...O..#.O.O.O....O....O.O..O#O.....O.O....O...O
.......O...O.O....O.O.OO...##..OOOOOO.O...O.##.O...#...O.O#O...#.O.O.O.........O..#..O.....##.#....#
...O..........#.O...O.O.OOO...##.....#OO.......O....#.....O.......#.#O.........O.##O#..##...O.O.#.O.
..OO#O.....O.##......O..#...#..OO.....#O#.O..#.O..#.O.#......O.#O.#..O.#.#.O..#.O......#.....O..#.O.
..O#...O..O.O.OO....#..O.......#..#.O.#....O..OO#.OO.O..#.#O..O.#.......O...O#.OO.......O#........O#
...OO....#..O...O.#....#.#OOO...O.#.#.#.O....OO...OO...#......#O..#..O.#O....#O...#..O..OO#....OO..O
.O.OO##....OO.#...O.......O...O.O.O.O.O.....O.O#..O#O......##O..#..###.O....O...O..#O.##O#....#..##.
.#..O.O....O#O..OO#........#O#.OOO...##.....O#..#.#..O#.OOO.O...#.....O#........O#O......##...O.....
..O#O.....O.#O...O...#.O.........#OO..#O.O.##..##O..OO....O...O.#.#...#..O...O#.O...O......#OO...#.#
O.........##.....###O.O.#.O##..##.O.#.O.OO......OOO...O#.O#..OO..........##.##O.O#O.O...##.O....O..O
O..##OO.OO.......#......O.#..#.....O...O#.O#..#...OO...#.O...#O.#.O..O..OOO#....O..O...#....O...#.O.
..#.....#OOO#..O..O.....O........#...O..OO.O.....OO....O.###.....#O.#..O..#...#.###O..O#...O.#...O..
O.O..#O..###.#....O#......###..#....O..OOO..O..O..OO..OO#O.....O..#..O##.#.#..OO..##..#.....O....O..
..O......O..#.......##..#O..OO.O.O....#..OOO..OO.#..#..OO.O...O.....#.OO#OOO.O.##.....O...O##.#...O.
O.OO.#O..#.#...#...##...O.#O....O##O...O##.OO#.O.###.#OO..OO#O......OOO..#OOOO...OO....#.O#.........
.#O#O#O.O.O....O.O.O...###O.O#.#OO#.O......#O#.O#O#........O...#OOO..OOO.........O...#O#...O......#.
.OO.O.#..#.#..O.....OO.O.O#.....O...O..O.#.OO.O.....#.....O.......O.OO......O...OO..O..O....#..O.#.O
.#...O#..O..#.#O...#O...O..O.....#.#.O#.OO#.#..#.....OO.#....O.#OO.....OO.O.O..O.O....#......O..OO..
...OO.##.O...#.#....##O.O..#.............#.#...#.#.#.OOO.##.......O#.O.O...OO....O..#....#.....O...O
.O...OO............#....O.#OO.#....#O....O###.#.....O.O.......#.O....#O...O...O.O.#..OO....#....#...
#.#......#O.....O..#.O.OO.........O...##....O....#..##OO..##O#..O.O......O....#.O..O......#..##....O
OOO....#.#.O.#.O#..#.....#O.O.O..O.OO.......#O.#......O##.O.#.#...#.#..OO#O.O...O..O..O.O.....#..#O.
##..O##..O...#.#..#..............#O..#O.O.O..#..O....O...#..#OO...O##....O...O...#O....OO...#.O..O..
.#...OO#.#O.......##..#O...O.#..#......O#O....#..OO..OO.#O..O...O.#.O.........O........#.##.##...O.#
...O.O..O...#O..O.O..OO.OO##O.O.O.#..#...O..##...O##O#O..#.#.O#.#O#..#..OO..O....O..OOOO..##..O.....
##........#............#....O.....O.#.O.#.O.O.#O...#O......O.#....O...#O#...OO#.#O##........O.......
OOO#O.OO..#.......OO.OO...O...##.O.##..O....OO...O.O.............##O......#.#..O..#O..##..#....#...O
.#O.......#O...O..#O......O#OO.O.O#.O......#O#......#..###.O.#.#..O#.....##.O.O...O..O.O.#..OO#.#.#O
.....O.O...O.#.....OO###..##.O.....O....#...O.O...........#O#..#O..#....#.O.......###...#..O.#....#O
#O.OO.........O#..#O.....O....O#......#....O..OOO..O.#.OO#...O..O##....##O..#..O#..O......O.OOO.O.OO
.#...O.#.#O....O..OO....#O..#...#O........#....O...O.....O..O..O.##.......O#...#..#O..#.#...O..O.O.O
......O..O...#....O....#OO#....#.#..##OO.....O.O.#......OO.O#..........#..O..#.O##.........###..O...
.O.O#..#O.#..#....O......O..OO.#O.O....O.#......#O.O.....O..OO#..O#.O.#....#...O.O...#O..#......##.O
......O.....O.#...#....#....O#O.##...O.......O.#.##.###O#.#........O.#O.O..#...#...#.O.....O.O.O#...
#.#O#.#..#.#.......#..#..#.....##O#.......#.#..##OO.........O.O....#O...O....O....#..##..#OO..O...OO
.O..#.O.O.......O....#.O........O...#O.#.....O#....#.......O.O...O...O#..##....O...#.OOO...O.#O##...
.......#..O..O...O....O#...O#....#O..O....##..#....##O....OO..#......#....O..#O.....O.O#OO..........
..O#......O.O......#.....#O.#.#.#.O...#OO.....O.O#.....O#.O.#.....OO.O.O.O....O..OO..##.#.....OO#..O
#O...O.#..#...OOO#...O......O#..O..O....###....OO..O#.#O..##.O#.O##....#.#.O#.##.....O.............O
.O.##.........#O....#..O#.O.#...O......O#.O#.OO#...O.O..........##.##O....O.#O#O..O.#...OO.O#.O.O...
#OO.O.OO.....O#....O.OO..###...O.....#..O##...O..###.O...#.O..#.O...O...OOO.#.O.#..O...O#..OO.#O...O
.###..#.OO#O..O.#..#.O..O...#....#.#..#O.O....#O....O#..#......#...#..O.....O.O.#O...O..O.....O#..#.
..###....OOOO......#O....O.....O.O.O..O.#O..##...#O#..#..#....#.O..#..O.......O...#.O#.#..#...O....#
......#O.#.......O..OO#O#....#.....OO#..#.OO..O.#....#...#O....#...O....O#.......O..#.O.#...#.#.O...

11
14/input_test Normal file
View File

@@ -0,0 +1,11 @@
O....#....
O.OO#....#
.....##...
OO.#O....O
.O.....O#.
O.#..O.#.#
..O..#O..O
.......O..
#....###..
#OO..#....

355
14/main.s Normal file
View File

@@ -0,0 +1,355 @@
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:
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:

74
14/main_part1.s Normal file
View File

@@ -0,0 +1,74 @@
global _start
[bits 32]
[section .text]
%include "utils.s"
_start:
mov esi, file
xor ebp, ebp ; line num
; for chars in line
do_line:
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 the next spot to after this
lea eax, [ebp+1]
mov [col_next_spot+ebx], al
jmp .cont
.round_rock:
; add to next spot line load
movzx eax, byte [col_next_spot+ebx]
inc byte [line_load_cnt+eax]
; increment next spot
inc byte [col_next_spot+ebx]
jmp .cont
line_done:
inc ebp ; line num
cmp esi, file.over
jb do_line
lea ecx, [ebp-1]
output_loads:
mov ebx, ebp
sub ebx, ecx
mov eax, ebx
call print_dec
call space
movzx eax, byte [ecx+line_load_cnt-1]
call print_dec
call space
mul ebx
call print_dec
call newline
add [final_value], eax
loop output_loads
game_over:
mov eax, [final_value]
call print_dec
call newline
jmp exit
[section .data]
line_len: dd 0
final_value: dd 0
file: incbin "input"
.over:
[section .bss]
col_next_spot: resb 128
line_load_cnt: resb 128

258
14/utils.s Normal file
View File

@@ -0,0 +1,258 @@
; call # val val2
; int $0x80 eax eax edx -
;
; arg1 arg2 arg3 arg4 arg5 arg6 arg7
; ebx ecx edx esi edi ebp -
exit:
mov eax, 1 ; exit
int 0x80
; filename in EBX
; return handle in EBX
; read only
open_file:
push eax
push ecx
mov eax, 5 ; open
xor ecx, ecx ; read only
int 0x80
mov ebx, eax
pop ecx
pop eax
ret
; file handle in EBX
; buffer in ECX
; count of bytes to read in EDX
; return bytes actually read in EAX
; exits on error
read_file:
mov eax, 3 ; read
int 0x80
test eax, eax
js .err
ret
.err:
mov eax, 4 ; write
mov ebx, 1 ; stdout
mov ecx, .err_str
mov edx, 21
int 0x80
jmp exit
.err_str: db `Could not read file.\n`
; string input in ESI
; value in EAX
; CF set if none, clear if some
; ESI set past checked area
dec_parse:
push ebx
push edx
push edi
xor eax, eax
xor edi, edi
mov ebx, 10 ; base
lodsb
sub al, '0'
js .no_input
cmp al, 9
jle .got_char
.no_input:
stc ; set CF
jmp .done
.loop:
xor eax,eax
lodsb
sub al, '0'
js .dec_done
cmp al, 9
jg .dec_done
.got_char:
xchg edi,eax
mul ebx
add edi,eax
jmp .loop
.dec_done:
clc ; clear CF
.done:
mov eax,edi
pop edi
pop edx
pop ebx
ret
; string input in ESI
; value in EAX
; CF set if none, clear if some
; ESI set past checked area
sign_dec_parse:
push ebx
push ecx
push edx
push edi
xor eax, eax
xor edi, edi
xor ecx, ecx ; neg flag
mov ebx, 10 ; base
cmp byte [esi], '-'
jne .no_minus
inc esi
mov cl, 1
.no_minus:
lodsb
sub al, '0'
js .no_input
cmp al, 9
jle .got_char
.no_input:
stc ; set CF
jmp .done
.loop:
xor eax,eax
lodsb
sub al, '0'
js .dec_done
cmp al, 9
jg .dec_done
.got_char:
xchg edi,eax
mul ebx
add edi,eax
jmp .loop
.dec_done:
test ecx, ecx
jz .not_neg
neg edi
.not_neg:
clc ; clear CF
.done:
mov eax,edi
pop edi
pop edx
pop ecx
pop ebx
ret
; modifies no regs
newline:
pushad
push 10
mov eax, 4 ; write
mov ebx, 1 ; stdout
mov ecx, esp ; string
mov edx, 1 ; length
int 0x80
add esp, 4
popad
ret
; modifies no regs
space:
pushad
push 9
mov eax, 4 ; write
mov ebx, 1 ; stdout
mov ecx, esp ; string
mov edx, 1 ; length
int 0x80
add esp, 4
popad
ret
; input in EAX, all regs unmodified
print_dec:
pushad ; save regs
; max 4294967296 is 10 chars
; round to nearest 32-bit boundary
sub esp, 12
; string in ECX, length in EDX
lea ecx, [esp+11] ; last possible byte
; check for 0
test eax, eax
jz .zero
mov ebx, 10 ; base 10
xor esi, esi ; counter
.div_shit:
xor edx, edx
; divide
div ebx
dec ecx ; next char
inc esi
; store
add dl, '0'
mov byte [ecx], dl
; check if done
test eax, eax
jnz .div_shit ; continue
mov edx, esi ; counter in edx
jmp .write
.zero:
mov byte [ecx], '0'
mov edx, 1 ; length
.write:
mov eax, 4 ; write
mov ebx, 1 ; stdout
int 0x80
add esp, 12 ; restore stack
popad ; restore regs
ret
; input in EAX, all regs unmodified
print_sign_dec:
pushad ; save regs
; range -2147483648 to 2147483647 is 11 chars
; round to nearest 32-bit boundary
sub esp, 12
; string in ECX, length in EDX
lea ecx, [esp+11] ; last possible byte
; check for 0, negative
xor ebp, ebp
test eax, eax
jz .zero
jns .positive
neg eax
mov ebp, 1
.positive:
mov ebx, 10 ; base 10
xor esi, esi ; counter
.div_shit:
xor edx, edx
; divide
div ebx
dec ecx ; next char
inc esi
; store
add dl, '0'
mov byte [ecx], dl
; check if done
test eax, eax
jnz .div_shit ; continue
mov edx, esi ; counter in edx
jmp .write
.zero:
mov byte [ecx], '0'
mov edx, 1 ; length
.write:
test ebp, ebp
jz .no_minus
dec ecx
inc edx
mov byte [ecx], '-'
.no_minus:
mov eax, 4 ; write
mov ebx, 1 ; stdout
int 0x80
add esp, 12 ; restore stack
popad ; restore regs
ret
; input in ESI, len in ECX, all regs unmodified
print_string:
pushad ; save regs
mov eax, 4 ; write
mov ebx, 1 ; stdout
mov edx, ecx ; length
mov ecx, esi ; string
int 0x80
popad ; restore regs
ret

3
15/Makefile Normal file
View File

@@ -0,0 +1,3 @@
all:
nasm -g -felf32 main.s && ld -melf_i386 -g main.o

1
15/input Normal file

File diff suppressed because one or more lines are too long

1
15/input_test Normal file
View File

@@ -0,0 +1 @@
rn=1,cm-,qp=3,cm=2,qp-,pc=4,ot=9,ab=5,pc-,pc=6,ot=7

160
15/main.s Normal file
View File

@@ -0,0 +1,160 @@
global _start
[bits 32]
[section .text]
%include "utils.s"
_start:
; HASH
mov esi, file
xor ebx, ebx ; current value
xor edi, edi ; current label high
xor ecx, ecx ; current label low
mov ebp, 17 ; mul value
hash:
movzx eax, byte [esi]
inc esi
cmp al, 10
je next_seq
cmp al, '-'
je minus
cmp al, '='
je equals
; save label
cmp ecx, 0x00ffffff
ja .needs_high
shl ecx, 8
mov cl, al
jmp .do_hash
.needs_high:
xchg eax, edi
shl eax, 8
mov al, cl
xchg eax, edi
mov cl, al
.do_hash:
; do HASH
; current += new
add eax, ebx
; current *= 17
mul ebp
; current %= 256
movzx ebx, al
jmp hash
; i'm not using a linked list whatever
minus:
; box *box = boxes+current*1024
shl ebx, 10
lea ebp, [ebx+boxes]
lea ebx, [ebx+boxes+4]
; box->max
mov eax, [ebp]
.find_eq:
test eax, eax
jz .done
dec eax
cmp [ebx], ecx
jne .cont
cmp [ebx+4], edi
jne .cont
xchg esi, edx
; remove match, move others down
mov edi, ebx
lea esi, [ebx+12]
; len = eax*8 + eax*4
mov ecx, eax
shl ecx, 3
shl eax, 2
add ecx, eax
rep movsd
xchg esi, edx
; decrease max
dec dword [ebp]
jmp .done
.cont:
add ebx, 12
jmp .find_eq
.done:
inc esi
jmp next_seq
equals:
; box *box = boxes+current*1024
shl ebx, 10
lea ebp, [ebx+boxes]
lea ebx, [ebx+boxes+4]
; box->max
mov eax, [ebp]
.find_eq:
test eax, eax
jz .no_match
dec eax
cmp [ebx], ecx
jne .cont
cmp [ebx+4], edi
jne .cont
; update match
mov al, [esi] ; ascii num
sub al, '0' ; to binary
mov [ebx+8], al
jmp .done
.cont:
add ebx, 12
jmp .find_eq
.no_match:
; new entry
mov [ebx], ecx
mov [ebx+4], edi
mov al, [esi]
sub al, '0'
mov [ebx+8], al
; inc max
inc dword [ebp]
.done:
add esi, 2
next_seq:
xor ebx, ebx ; current value
xor edi, edi ; current label high
xor ecx, ecx ; current label low
mov ebp, 17 ; mul value
cmp esi, file.over
jb hash
mov esi, boxes
calc_shit:
cmp dword [esi], 0
je .cont
mov edi, esi
sub edi, boxes
shr edi, 10 ; box idx
inc edi ; box num
mov ecx, 1 ; slot num
lea ebx, [esi+4] ; lenses
.inner:
mov eax, edi ; box num
mul ecx ; slot num
mul dword [ebx+8] ; focal length
add [final_value], eax
add ebx, 12
inc ecx
cmp ecx, [esi]
jbe .inner
.cont:
add esi, 1024
cmp esi, boxes.end
jb calc_shit
game_over:
mov eax, [final_value]
call print_dec
call newline
jmp exit
[section .data]
final_value: dd 0
file: incbin "input"
.over:
[section .bss]
boxes: resb 256*1024
.end:

44
15/main_part1.s Normal file
View File

@@ -0,0 +1,44 @@
global _start
[bits 32]
[section .text]
%include "utils.s"
_start:
; HASH
mov esi, file
xor ebx, ebx ; current value
mov ebp, 17 ; mul value
hash:
movzx eax, byte [esi]
inc esi
cmp al, ','
jle .next_seq
; do HASH
; current += new
add eax, ebx
; current *= 17
mul ebp
; current %= 256
movzx ebx, al
jmp hash
.next_seq:
add [final_value], ebx
xor ebx, ebx
cmp esi, file.over
jb hash
game_over:
mov eax, [final_value]
call print_dec
call newline
jmp exit
[section .data]
final_value: dd 0
file: incbin "input"
.over:
[section .bss]

258
15/utils.s Normal file
View File

@@ -0,0 +1,258 @@
; call # val val2
; int $0x80 eax eax edx -
;
; arg1 arg2 arg3 arg4 arg5 arg6 arg7
; ebx ecx edx esi edi ebp -
exit:
mov eax, 1 ; exit
int 0x80
; filename in EBX
; return handle in EBX
; read only
open_file:
push eax
push ecx
mov eax, 5 ; open
xor ecx, ecx ; read only
int 0x80
mov ebx, eax
pop ecx
pop eax
ret
; file handle in EBX
; buffer in ECX
; count of bytes to read in EDX
; return bytes actually read in EAX
; exits on error
read_file:
mov eax, 3 ; read
int 0x80
test eax, eax
js .err
ret
.err:
mov eax, 4 ; write
mov ebx, 1 ; stdout
mov ecx, .err_str
mov edx, 21
int 0x80
jmp exit
.err_str: db `Could not read file.\n`
; string input in ESI
; value in EAX
; CF set if none, clear if some
; ESI set past checked area
dec_parse:
push ebx
push edx
push edi
xor eax, eax
xor edi, edi
mov ebx, 10 ; base
lodsb
sub al, '0'
js .no_input
cmp al, 9
jle .got_char
.no_input:
stc ; set CF
jmp .done
.loop:
xor eax,eax
lodsb
sub al, '0'
js .dec_done
cmp al, 9
jg .dec_done
.got_char:
xchg edi,eax
mul ebx
add edi,eax
jmp .loop
.dec_done:
clc ; clear CF
.done:
mov eax,edi
pop edi
pop edx
pop ebx
ret
; string input in ESI
; value in EAX
; CF set if none, clear if some
; ESI set past checked area
sign_dec_parse:
push ebx
push ecx
push edx
push edi
xor eax, eax
xor edi, edi
xor ecx, ecx ; neg flag
mov ebx, 10 ; base
cmp byte [esi], '-'
jne .no_minus
inc esi
mov cl, 1
.no_minus:
lodsb
sub al, '0'
js .no_input
cmp al, 9
jle .got_char
.no_input:
stc ; set CF
jmp .done
.loop:
xor eax,eax
lodsb
sub al, '0'
js .dec_done
cmp al, 9
jg .dec_done
.got_char:
xchg edi,eax
mul ebx
add edi,eax
jmp .loop
.dec_done:
test ecx, ecx
jz .not_neg
neg edi
.not_neg:
clc ; clear CF
.done:
mov eax,edi
pop edi
pop edx
pop ecx
pop ebx
ret
; modifies no regs
newline:
pushad
push 10
mov eax, 4 ; write
mov ebx, 1 ; stdout
mov ecx, esp ; string
mov edx, 1 ; length
int 0x80
add esp, 4
popad
ret
; modifies no regs
space:
pushad
push 9
mov eax, 4 ; write
mov ebx, 1 ; stdout
mov ecx, esp ; string
mov edx, 1 ; length
int 0x80
add esp, 4
popad
ret
; input in EAX, all regs unmodified
print_dec:
pushad ; save regs
; max 4294967296 is 10 chars
; round to nearest 32-bit boundary
sub esp, 12
; string in ECX, length in EDX
lea ecx, [esp+11] ; last possible byte
; check for 0
test eax, eax
jz .zero
mov ebx, 10 ; base 10
xor esi, esi ; counter
.div_shit:
xor edx, edx
; divide
div ebx
dec ecx ; next char
inc esi
; store
add dl, '0'
mov byte [ecx], dl
; check if done
test eax, eax
jnz .div_shit ; continue
mov edx, esi ; counter in edx
jmp .write
.zero:
mov byte [ecx], '0'
mov edx, 1 ; length
.write:
mov eax, 4 ; write
mov ebx, 1 ; stdout
int 0x80
add esp, 12 ; restore stack
popad ; restore regs
ret
; input in EAX, all regs unmodified
print_sign_dec:
pushad ; save regs
; range -2147483648 to 2147483647 is 11 chars
; round to nearest 32-bit boundary
sub esp, 12
; string in ECX, length in EDX
lea ecx, [esp+11] ; last possible byte
; check for 0, negative
xor ebp, ebp
test eax, eax
jz .zero
jns .positive
neg eax
mov ebp, 1
.positive:
mov ebx, 10 ; base 10
xor esi, esi ; counter
.div_shit:
xor edx, edx
; divide
div ebx
dec ecx ; next char
inc esi
; store
add dl, '0'
mov byte [ecx], dl
; check if done
test eax, eax
jnz .div_shit ; continue
mov edx, esi ; counter in edx
jmp .write
.zero:
mov byte [ecx], '0'
mov edx, 1 ; length
.write:
test ebp, ebp
jz .no_minus
dec ecx
inc edx
mov byte [ecx], '-'
.no_minus:
mov eax, 4 ; write
mov ebx, 1 ; stdout
int 0x80
add esp, 12 ; restore stack
popad ; restore regs
ret
; input in ESI, len in ECX, all regs unmodified
print_string:
pushad ; save regs
mov eax, 4 ; write
mov ebx, 1 ; stdout
mov edx, ecx ; length
mov ecx, esi ; string
int 0x80
popad ; restore regs
ret

3
16/Makefile Normal file
View File

@@ -0,0 +1,3 @@
all:
nasm -g -felf32 main.s && ld -melf_i386 -g main.o

110
16/input Normal file
View File

@@ -0,0 +1,110 @@
\....|...-...../.....|....................-./............|/.....................-........./.....-.............
\..........-.....................-......................................|....................\..../.....-.....
....\......-...../../../...\......................\.........................-.............|.............|.....
.........../..../...........|/\.............\........\.......|.........|..|../............/.........|.........
\./...\........\..........\......./....../...............................|....|........|................/.....
|-.....|............/...............|...\...|...../......../.....|............|..\..|..../.......-.........\..
........-.............||../..........|.........../..................../.|.....|\..-/......./...\...\....-.....
....................//........................./..........\.......|...|.........../......\-......-...\........
....../..........\......\.....................\................\......\..\..|.................................
.................\...............-....../........./....-./..........|..../..-..|../................\..........
.............-...............-......|.../.....-.....//.\................../..........-......-...........-.....
.........../.\.....................\............-..........|.......\..................\.......................
...............\............/.|...\........../....\.............|...........\...............|.../........\....
./..............\................-\.../\.......-....................-..............-|.............\.-.........
../....../.........|..../......\...\.\.................|......./.......|...............-.........-............
-...-............................\.............-.\........-.....|.........././-......|......-..../...|........
................-.....................|..|...\.././.............|..........................-.............-....
.......|...............................|.......................................-......../.............|-...-..
.\|............................\................|.....-.....-................................./...-..\...../..
.......\......-....\|......|........................................./...||...............\...................
.................../......../.......-......\..............|..\...........-.........-.............../..........
........................\......................../.................-........................\.....\...........
..........|......|........................|.|\...............\...|.............-...-....-............--.......
............|........../....\..........\........../..-..|...........-...\........................./..-........
.............||../..../.......................-/.......\.....\............./|..-...............|.....|........
................................|..\.........-......./...........-../-............\................\....-../..
.............-.............................|.\...............................\\...............................
..|.......-................................\.......|.......\.....................|../\..........\..........-..
......-..\..........-.................\.-..../\......./......./..-.......................\.....-........\.....
............................../.....................\.................\................|..../\.............\..
..............................-.......\.........-..........\....../............./.....-........\...-.........|
/..................\...||..|...........\...............-............\..........|./.....-.-./.............../..
.....|......./...............\.......-................-...........................................\...........
.|.................../.....\............./.....\.................-.../.......-..............\..-..............
......\........|...|...........//..........|\.\..............................-..../...-............|..........
|......\....|\......|........../.........../........-.........|.-\//................/..\....|.../........|....
.-....-......................./.........\.........-.../............................-..|........|.....|...|....
.........-..................-..........-....-....................-....-./.......................|.../......\..
..-../......................-\.....|...\........./.-...............-.................../../............|......
.-/.......-../.......-...|\...../..........-...\.......\.........-....\-................-......|........-.....
.............................\\\............-..............|........../...................-......../....../../
.....-....\....\......................-..\...............-..|...............-................-.......\......|.
..-...\.............................../.../.............................--.......-..|.|\...../...............\
......\.../...-.....|....|......\.../|...................................-................-................./.
.......-......-.../..................|../..................\..........................\-..........-\..........
.-.......\.........|....|\/./-\.-.....|..................-...................................-|...\...........
...........-........../\..................\./..........................\...../...........-...\...../..\....-..
..-.|...../|......\..\........|.............-.....|..........\...-...-../......................../.......|....
......../................/..\.......\..-...|.....\.......|\..........................-..\../..........\./.....
........\.-......|......|..........|........-...................-..\.....-./..............-.\......\..........
........|./..................\........|......................\............................./.-\....\........-.
........\.|......\................/..\....-/.\.....-.....|............................\..\.|............|...-.
...-.....-|..................|...............-./.....................\..\............|.....-..................
..........|\./.....\..................|.........|.....................-\./..\........\........................
../........\..............|....-...............................................|..........-......../..........
..\..............|...../../....................-....\.....................|........\...\\.....................
...........................-...\......\......./../..........\-...../.......................-...........\......
-.|........................../.....|...............\..........-.............\...-................-.......-....
/../.........\........./......-.../..-..................-.......................\............--...............
\...............|......-..../......................................-........./|......................\|....../
.....\.......................................-...................-.../...........\.......|../.............|...
....-....||......\..\.......-.........-......../..../............\..................................-.........
...-..|.......\..\..|..........-../-..........\............../...............|..../........./....../.......|./
.......................\.......././.............\..................-..........|................../....|.......
-.|.....................\\.........../......./.|................/................|./......./....-.............
......-...............-....-................|./\..\-/...../......../....-....\....|.-.................../...\.
...............\......-...\...\....-....-/....................\./....../..................-|........\./...../.
.\......................./..\.........\.........|............|.......-../..\.-..|.-..........................|
..|../.....................|/......................./......../.../.........-.../.|./.|.-..............|....-..
...-.-/............/............|..........|....../\...\./.....|..................|....\............/.........
.....|........./.........\.............../......./../../...................|.......//.......\..\..........\...
......./.............\...........\.\..............................................\...................|.......
...............-|...../..-............................\.....-.............../\.........-....................\.
.........-.....................-...\...................-..../.................||....\.........-.......-..-....
.|../..\...\......|..\./.........\..............|..\/......../...............-..-....................-.....\..
..................|........\.-.....|.......\............../................................/...-....|...../...
...........-......./........-...--........\.../..-...../.|............|......./...............|....../\......\
.../.....\...................-..../....................................-......................|.............-.
.\.....|....-.....|.....-...................................................|../....\..................\.....-
....-........../\......../.......-....\............................./-.............-..........................
....\.........-........./......../....|..............\........\../.................\.|...............\........
.........-..............|./............-.......................\.......\......-\......\......../..............
-.|...|./-..........\..........-...-............|...-......................\..\.............................-.
............/......................../.........................................\/..........|.....|.-........|/
....../..|./..././.....-......................../....|................../..|........-.....................|./.
.......................\....................../......./......\/........\......./....../\|.....\...............
\...........\/.|../..................../...............\\...\..../..................\......./.................
.../................/...............\./....-./........../........./\..-.................................\.....
........-.......-...........\........-.......\............|............|.....-........|..|..../...............
.............|...|............/....\............................................-..\......./.../..........\...
...................../-..|...........-................../.\...|.....\.....|/.................|................
..|................\.....-...........|.\............-.........|....../...................\......-.|.......\...
........\......../.....-...\..\...........\........|/.............../......|.......|.\..|........|............
..........\.....................-..|/.....\............-............../.......................|./........\....
.......\........|...........\......\.......-..-.....|............./......|\..............................|....
.........\.......................-............-/.................................\............|...............
.........\................/.............................../..........\................-../../......|......-...
....\...-./...............\...............|.....\|....|/...............-...........................-..........
.|.......\.......-............./.......\............./....................|......|../......-...........\......
.....\.....-.....\...\................/......\...\../.\...\....\-....-././...............................|./..
.....................-.\.\.........../......./...-......./-.........................\.......|../....\..|..../.
|..\......./-......-...../..-....../.................../..-.....................-..../...........\...../......
......................................./................|....\/....\............/....../......................
......................../..........|........-............|.........................|.\................|....../
-.............-...|...........-....-..-.|\.......|......\..........-......|-...-......\.......................
...........\.\\.../.................\..........\..-......-......|.-............................-.||...|....../
....|................--........|.|..........|......\.............................................-............
.-..|................/../..-.........................../...../.....\.../....-.....\-..................../.....
............./|..........................\...................................-..-..........|....\..|..........
....|...../........./.-....-..................../.........../....................-................\./.........

10
16/input_test Normal file
View File

@@ -0,0 +1,10 @@
.|...\....
|.-.\.....
.....|-...
........|.
..........
.........\
..../.\\..
.-.-/..|..
.|....-|.\
..//.|....

511
16/main.s Normal file
View File

@@ -0,0 +1,511 @@
%include "utils.s"
global _start
[bits 32]
[section .text]
%define LINE_LEN 111 ; real
%define FILENAME "input"
;%define LINE_LEN 11 ; test
;%define FILENAME "input_test"
;%define ITER_PRINT
;%define FINAL_PRINT
_start:
; bit 3 bit 2 bit 1 bit 0
; up down left right
; start top left going right
mov dword [test_edge_line], 0
mov dword [test_edge_col], 0
mov byte [test_edge_dir], 1
mov byte [energized], 1
jmp next_iteration
next_edge_tile:
; clear energized
mov edi, energized
xor eax, eax
mov ecx, (128*128)/4
rep stosd
mov eax, [test_edge_line]
mov ecx, [test_edge_col]
mov bl, [test_edge_dir]
cmp bl, 1 ; we're testing going right
jne .maybe_2
; we're going down first col
cmp eax, LINE_LEN-2 ; check if last line
je .bl_corner
inc eax
jmp start_iterations
.bl_corner:
mov bl, 8 ; try going up
jmp start_iterations
.maybe_2:
cmp bl, 2 ; we're testing going left
jne .maybe_4
; we're going up the last col
cmp eax, 0 ; check if first line
je .tr_corner
dec eax
jmp start_iterations
.tr_corner:
mov bl, 4 ; try going down
jmp start_iterations
.maybe_4:
cmp bl, 4 ; we're testing going down
jne .maybe_8
; we're going along the top line backward
cmp ecx, 0 ; check if first col
je .tl_corner
dec ecx
jmp start_iterations
.tl_corner:
jmp game_over ; nothing to do! jump to exit
.maybe_8: ; we're testing going up
; we're going along the bottom line
cmp ecx, LINE_LEN-2 ; check if last col
je .br_corner
inc ecx
jmp start_iterations
.br_corner:
mov bl, 2 ; try going left
jmp start_iterations
start_iterations:
mov [test_edge_line], eax
mov [test_edge_col], ecx
mov [test_edge_dir], bl
mov edx, LINE_LEN
mul edx
add eax, ecx
mov byte [energized+eax], bl
next_iteration:
%ifdef ITER_PRINT
; debug printing
dbg:
xor esi, esi ; top line
.for_lines:
xor ecx, ecx ; leftmost char
.for_chars:
movzx eax, byte [esi+ecx+energized]
movzx ebx, byte [esi+ecx+file]
pushad
test al, al
jz .prnt_char
p_string ansi_color_highbold_green
cmp bl, '.'
jne .prnt_char
popcnt ecx, eax
cmp ecx, 1
jg .prnt_num
cmp al, 1
je .prnt_right
cmp al, 2
je .prnt_left
cmp al, 4
je .prnt_down
.prnt_up: mov al, '^'
call print_char
jmp .prnt_done
.prnt_down: mov al, 'v'
call print_char
jmp .prnt_done
.prnt_left: mov al, '<'
call print_char
jmp .prnt_done
.prnt_right: mov al, '>'
call print_char
jmp .prnt_done
.prnt_num:
mov eax, ecx
call print_dec
jmp .prnt_done
.prnt_char:
mov al, [esi+ecx+file]
call print_char
.prnt_done:
p_string ansi_color_reset
popad
.for_chars_cont:
inc ecx
cmp ecx, LINE_LEN-2
jbe .for_chars
.for_chars_done:
.for_lines_cont:
call newline
add esi, LINE_LEN
cmp esi, len(file)
jb .for_lines
call newline
; debug printing end
%endif
xor esi, esi ; top line
for_lines:
xor ecx, ecx ; leftmost char
for_chars:
movzx eax, byte [esi+ecx+energized]
movzx ebx, byte [esi+ecx+file]
; skip if not energized
test eax, eax
jz for_chars_cont
; select thing
cmp bl, '.'
je empty
cmp bl, '/'
je mirror_one
cmp bl, '\'
je mirror_two
cmp bl, '-'
je horz_split
cmp bl, '|'
je vert_split
p_string what_the_fuck
jmp exit
empty: ; .
; propagate
; test right
bt eax, 0
jnc .t_left
or byte [esi+ecx+energized+1], 1<<0
.t_left:
bt eax, 1
jnc .t_down
or byte [esi+ecx+energized-1], 1<<1
.t_down:
bt eax, 2
jnc .t_up
or byte [esi+ecx+energized+LINE_LEN], 1<<2
.t_up:
bt eax, 3
jnc .done
or byte [esi+ecx+energized-LINE_LEN], 1<<3
.done:
jmp for_chars_cont
mirror_one: ; /
; our energized is what hits us
; test right >/
bt eax, 0
jnc .t_left
or byte [esi+ecx+energized-LINE_LEN], 1<<3 ; up char going up
.t_left: ; /<
bt eax, 1
jnc .t_down
or byte [esi+ecx+energized+LINE_LEN], 1<<2 ; down going down
.t_down:
bt eax, 2 ; v
jnc .t_up ; /
or byte [esi+ecx+energized-1], 1<<1 ; left going left
.t_up:
bt eax, 3 ; /
jnc .done ; ^
or byte [esi+ecx+energized+1], 1<<0 ; right going right
.done:
jmp for_chars_cont
mirror_two: ; \
; our energized is what hits us
; test right >\
bt eax, 0
jnc .t_left
or byte [esi+ecx+energized+LINE_LEN], 1<<2 ; down char going down
.t_left: ; \<
bt eax, 1
jnc .t_down
or byte [esi+ecx+energized-LINE_LEN], 1<<3 ; up going up
.t_down:
bt eax, 2 ; v
jnc .t_up ; \
or byte [esi+ecx+energized+1], 1<<0 ; right going right
.t_up:
bt eax, 3 ; \
jnc .done ; ^
or byte [esi+ecx+energized-1], 1<<1 ; left going left
.done:
jmp for_chars_cont
horz_split: ; -
; our energized is what hits us
; right and left propagate
; test right
bt eax, 0
jnc .t_left
or byte [esi+ecx+energized+1], 1<<0
.t_left:
bt eax, 1
jnc .t_vert
or byte [esi+ecx+energized-1], 1<<1
; down and up go both left and right
.t_vert:
and eax, 1<<2 | 1<<3
jz .done
or byte [esi+ecx+energized+1], 1<<0 ; right going right
or byte [esi+ecx+energized-1], 1<<1 ; left going left
.done:
jmp for_chars_cont
vert_split: ; |
; our energized is what hits us
; down and up propagate
; test down
bt eax, 2
jnc .t_up
or byte [esi+ecx+energized+LINE_LEN], 1<<2
.t_up:
bt eax, 3
jnc .t_vert
or byte [esi+ecx+energized-LINE_LEN], 1<<3
; left and right go both down and up
.t_vert:
and eax, 1<<0 | 1<<1
jz .done
or byte [esi+ecx+energized+LINE_LEN], 1<<2 ; down going down
or byte [esi+ecx+energized-LINE_LEN], 1<<3 ; up going up
.done:
for_chars_cont:
inc ecx
cmp ecx, LINE_LEN-2
jbe for_chars
for_chars_done:
for_lines_cont:
add esi, LINE_LEN
cmp esi, len(file)
jb for_lines
xor ebp, ebp ; energized count
sub esi, LINE_LEN ; last line
; now go through backward
bkwd_for_lines:
mov ecx, LINE_LEN-2 ; rightmost char
bkwd_for_chars:
movzx eax, byte [esi+ecx+energized]
movzx ebx, byte [esi+ecx+file]
; skip if not energized
test eax, eax
jz bkwd_for_chars_cont
inc ebp ; energized count
; select thing
cmp bl, '.'
je bkwd_empty
cmp bl, '/'
je bkwd_mirror_one
cmp bl, '\'
je bkwd_mirror_two
cmp bl, '-'
je bkwd_horz_split
cmp bl, '|'
je bkwd_vert_split
p_string what_the_fuck
jmp exit
bkwd_empty: ; .
; propagate
; test right
bt eax, 0
jnc .t_left
or byte [esi+ecx+energized+1], 1<<0
.t_left:
bt eax, 1
jnc .t_down
or byte [esi+ecx+energized-1], 1<<1
.t_down:
bt eax, 2
jnc .t_up
or byte [esi+ecx+energized+LINE_LEN], 1<<2
.t_up:
bt eax, 3
jnc .done
or byte [esi+ecx+energized-LINE_LEN], 1<<3
.done:
jmp bkwd_for_chars_cont
bkwd_mirror_one: ; /
; our energized is what hits us
; test right >/
bt eax, 0
jnc .t_left
or byte [esi+ecx+energized-LINE_LEN], 1<<3 ; up char going up
.t_left: ; /<
bt eax, 1
jnc .t_down
or byte [esi+ecx+energized+LINE_LEN], 1<<2 ; down going down
.t_down:
bt eax, 2 ; v
jnc .t_up ; /
or byte [esi+ecx+energized-1], 1<<1 ; left going left
.t_up:
bt eax, 3 ; /
jnc .done ; ^
or byte [esi+ecx+energized+1], 1<<0 ; right going right
.done:
jmp bkwd_for_chars_cont
bkwd_mirror_two: ; \
; our energized is what hits us
; test right >\
bt eax, 0
jnc .t_left
or byte [esi+ecx+energized+LINE_LEN], 1<<2 ; down char going down
.t_left: ; \<
bt eax, 1
jnc .t_down
or byte [esi+ecx+energized-LINE_LEN], 1<<3 ; up going up
.t_down:
bt eax, 2 ; v
jnc .t_up ; \
or byte [esi+ecx+energized+1], 1<<0 ; right going right
.t_up:
bt eax, 3 ; \
jnc .done ; ^
or byte [esi+ecx+energized-1], 1<<1 ; left going left
.done:
jmp bkwd_for_chars_cont
bkwd_horz_split: ; -
; our energized is what hits us
; right and left propagate
; test right
bt eax, 0
jnc .t_left
or byte [esi+ecx+energized+1], 1<<0
.t_left:
bt eax, 1
jnc .t_vert
or byte [esi+ecx+energized-1], 1<<1
; down and up go both left and right
.t_vert:
and eax, 1<<2 | 1<<3
jz .done
or byte [esi+ecx+energized+1], 1<<0 ; right going right
or byte [esi+ecx+energized-1], 1<<1 ; left going left
.done:
jmp bkwd_for_chars_cont
bkwd_vert_split: ; |
; our energized is what hits us
; down and up propagate
; test down
bt eax, 2
jnc .t_up
or byte [esi+ecx+energized+LINE_LEN], 1<<2
.t_up:
bt eax, 3
jnc .t_vert
or byte [esi+ecx+energized-LINE_LEN], 1<<3
; left and right go both down and up
.t_vert:
and eax, 1<<0 | 1<<1
jz .done
or byte [esi+ecx+energized+LINE_LEN], 1<<2 ; down going down
or byte [esi+ecx+energized-LINE_LEN], 1<<3 ; up going up
.done:
bkwd_for_chars_cont:
dec ecx
jnz bkwd_for_chars
bkwd_for_chars_done:
bkwd_for_lines_cont:
sub esi, LINE_LEN
jns bkwd_for_lines
cmp ebp, [last_energized]
mov [last_energized], ebp
jne next_iteration
; print final
xor ebp, ebp
print_final:
xor esi, esi ; top line
.for_lines:
xor ecx, ecx ; leftmost char
.for_chars:
movzx eax, byte [esi+ecx+energized]
movzx ebx, byte [esi+ecx+file]
test al, al
jz .prnt_char
inc ebp
%ifdef FINAL_PRINT
p_string ansi_color_highbold_green
cmp bl, '.'
jne .prnt_char
popcnt edx, eax
cmp edx, 1
jg .prnt_num
cmp al, 1
je .prnt_right
cmp al, 2
je .prnt_left
cmp al, 4
je .prnt_down
.prnt_up: mov al, '^'
call print_char
jmp .prnt_done
.prnt_down: mov al, 'v'
call print_char
jmp .prnt_done
.prnt_left: mov al, '<'
call print_char
jmp .prnt_done
.prnt_right: mov al, '>'
call print_char
jmp .prnt_done
.prnt_num:
mov eax, edx
call print_dec
jmp .prnt_done
%endif
.prnt_char:
%ifdef FINAL_PRINT
mov al, [esi+ecx+file]
call print_char
.prnt_done:
p_string ansi_color_reset
%endif
.for_chars_cont:
inc ecx
cmp ecx, LINE_LEN-2
jbe .for_chars
.for_chars_done:
.for_lines_cont:
%ifdef FINAL_PRINT
call newline
%endif
add esi, LINE_LEN
cmp esi, len(file)
jb .for_lines
%ifdef FINAL_PRINT
mov eax, ebp
call print_dec
call newline
call newline
%endif
cmp [final_value], ebp
cmova ebp, [final_value]
mov [final_value], ebp
jmp next_edge_tile
game_over:
mov eax, [final_value]
call print_dec
call newline
jmp exit
[section .data]
final_value: dd 0
last_energized: dd 0
test_edge_line: dd 0
test_edge_col: dd 0
test_edge_dir: dd 0
file: incbin FILENAME
.over:
[section .bss]
padding: resb 128
energized: resb 128*128
[section .rodata]
what_the_fuck: db "Something is terribly wrong in this world."
.over:
ansi_color_reset: db `\e[0m`
.over:
ansi_color_green: db `\e[0;32m`
.over:
ansi_color_highbold_green: db `\e[1;92m`
.over:

429
16/main_part1.s Normal file
View File

@@ -0,0 +1,429 @@
%include "utils.s"
global _start
[bits 32]
[section .text]
%define LINE_LEN 111 ; real
%define FILENAME "input"
;%define LINE_LEN 11 ; test
;%define FILENAME "input_test"
;%define ITER_PRINT
_start:
; bit 3 bit 2 bit 1 bit 0
; up down left right
; top left starts going right
mov byte [energized], 1
next_iteration:
%ifdef ITER_PRINT
; debug printing
dbg:
xor esi, esi ; top line
.for_lines:
xor ecx, ecx ; leftmost char
.for_chars:
movzx eax, byte [esi+ecx+energized]
movzx ebx, byte [esi+ecx+file]
pushad
test al, al
jz .prnt_char
p_string ansi_color_highbold_green
cmp bl, '.'
jne .prnt_char
popcnt ecx, eax
cmp ecx, 1
jg .prnt_num
cmp al, 1
je .prnt_right
cmp al, 2
je .prnt_left
cmp al, 4
je .prnt_down
.prnt_up: mov al, '^'
call print_char
jmp .prnt_done
.prnt_down: mov al, 'v'
call print_char
jmp .prnt_done
.prnt_left: mov al, '<'
call print_char
jmp .prnt_done
.prnt_right: mov al, '>'
call print_char
jmp .prnt_done
.prnt_num:
mov eax, ecx
call print_dec
jmp .prnt_done
.prnt_char:
mov al, [esi+ecx+file]
call print_char
.prnt_done:
p_string ansi_color_reset
popad
.for_chars_cont:
inc ecx
cmp ecx, LINE_LEN-2
jbe .for_chars
.for_chars_done:
.for_lines_cont:
call newline
add esi, LINE_LEN
cmp esi, len(file)
jb .for_lines
call newline
; debug printing end
%endif
xor esi, esi ; top line
for_lines:
xor ecx, ecx ; leftmost char
for_chars:
movzx eax, byte [esi+ecx+energized]
movzx ebx, byte [esi+ecx+file]
; skip if not energized
test eax, eax
jz for_chars_cont
; select thing
cmp bl, '.'
je empty
cmp bl, '/'
je mirror_one
cmp bl, '\'
je mirror_two
cmp bl, '-'
je horz_split
cmp bl, '|'
je vert_split
p_string what_the_fuck
jmp exit
empty: ; .
; propagate
; test right
bt eax, 0
jnc .t_left
or byte [esi+ecx+energized+1], 1<<0
.t_left:
bt eax, 1
jnc .t_down
or byte [esi+ecx+energized-1], 1<<1
.t_down:
bt eax, 2
jnc .t_up
or byte [esi+ecx+energized+LINE_LEN], 1<<2
.t_up:
bt eax, 3
jnc .done
or byte [esi+ecx+energized-LINE_LEN], 1<<3
.done:
jmp for_chars_cont
mirror_one: ; /
; our energized is what hits us
; test right >/
bt eax, 0
jnc .t_left
or byte [esi+ecx+energized-LINE_LEN], 1<<3 ; up char going up
.t_left: ; /<
bt eax, 1
jnc .t_down
or byte [esi+ecx+energized+LINE_LEN], 1<<2 ; down going down
.t_down:
bt eax, 2 ; v
jnc .t_up ; /
or byte [esi+ecx+energized-1], 1<<1 ; left going left
.t_up:
bt eax, 3 ; /
jnc .done ; ^
or byte [esi+ecx+energized+1], 1<<0 ; right going right
.done:
jmp for_chars_cont
mirror_two: ; \
; our energized is what hits us
; test right >\
bt eax, 0
jnc .t_left
or byte [esi+ecx+energized+LINE_LEN], 1<<2 ; down char going down
.t_left: ; \<
bt eax, 1
jnc .t_down
or byte [esi+ecx+energized-LINE_LEN], 1<<3 ; up going up
.t_down:
bt eax, 2 ; v
jnc .t_up ; \
or byte [esi+ecx+energized+1], 1<<0 ; right going right
.t_up:
bt eax, 3 ; \
jnc .done ; ^
or byte [esi+ecx+energized-1], 1<<1 ; left going left
.done:
jmp for_chars_cont
horz_split: ; -
; our energized is what hits us
; right and left propagate
; test right
bt eax, 0
jnc .t_left
or byte [esi+ecx+energized+1], 1<<0
.t_left:
bt eax, 1
jnc .t_vert
or byte [esi+ecx+energized-1], 1<<1
; down and up go both left and right
.t_vert:
and eax, 1<<2 | 1<<3
jz .done
or byte [esi+ecx+energized+1], 1<<0 ; right going right
or byte [esi+ecx+energized-1], 1<<1 ; left going left
.done:
jmp for_chars_cont
vert_split: ; |
; our energized is what hits us
; down and up propagate
; test down
bt eax, 2
jnc .t_up
or byte [esi+ecx+energized+LINE_LEN], 1<<2
.t_up:
bt eax, 3
jnc .t_vert
or byte [esi+ecx+energized-LINE_LEN], 1<<3
; left and right go both down and up
.t_vert:
and eax, 1<<0 | 1<<1
jz .done
or byte [esi+ecx+energized+LINE_LEN], 1<<2 ; down going down
or byte [esi+ecx+energized-LINE_LEN], 1<<3 ; up going up
.done:
for_chars_cont:
inc ecx
cmp ecx, LINE_LEN-2
jbe for_chars
for_chars_done:
for_lines_cont:
add esi, LINE_LEN
cmp esi, len(file)
jb for_lines
xor ebp, ebp ; energized count
sub esi, LINE_LEN ; last line
; now go through backward
bkwd_for_lines:
mov ecx, LINE_LEN-2 ; rightmost char
bkwd_for_chars:
movzx eax, byte [esi+ecx+energized]
movzx ebx, byte [esi+ecx+file]
; skip if not energized
test eax, eax
jz bkwd_for_chars_cont
inc ebp ; energized count
; select thing
cmp bl, '.'
je bkwd_empty
cmp bl, '/'
je bkwd_mirror_one
cmp bl, '\'
je bkwd_mirror_two
cmp bl, '-'
je bkwd_horz_split
cmp bl, '|'
je bkwd_vert_split
p_string what_the_fuck
jmp exit
bkwd_empty: ; .
; propagate
; test right
bt eax, 0
jnc .t_left
or byte [esi+ecx+energized+1], 1<<0
.t_left:
bt eax, 1
jnc .t_down
or byte [esi+ecx+energized-1], 1<<1
.t_down:
bt eax, 2
jnc .t_up
or byte [esi+ecx+energized+LINE_LEN], 1<<2
.t_up:
bt eax, 3
jnc .done
or byte [esi+ecx+energized-LINE_LEN], 1<<3
.done:
jmp bkwd_for_chars_cont
bkwd_mirror_one: ; /
; our energized is what hits us
; test right >/
bt eax, 0
jnc .t_left
or byte [esi+ecx+energized-LINE_LEN], 1<<3 ; up char going up
.t_left: ; /<
bt eax, 1
jnc .t_down
or byte [esi+ecx+energized+LINE_LEN], 1<<2 ; down going down
.t_down:
bt eax, 2 ; v
jnc .t_up ; /
or byte [esi+ecx+energized-1], 1<<1 ; left going left
.t_up:
bt eax, 3 ; /
jnc .done ; ^
or byte [esi+ecx+energized+1], 1<<0 ; right going right
.done:
jmp bkwd_for_chars_cont
bkwd_mirror_two: ; \
; our energized is what hits us
; test right >\
bt eax, 0
jnc .t_left
or byte [esi+ecx+energized+LINE_LEN], 1<<2 ; down char going down
.t_left: ; \<
bt eax, 1
jnc .t_down
or byte [esi+ecx+energized-LINE_LEN], 1<<3 ; up going up
.t_down:
bt eax, 2 ; v
jnc .t_up ; \
or byte [esi+ecx+energized+1], 1<<0 ; right going right
.t_up:
bt eax, 3 ; \
jnc .done ; ^
or byte [esi+ecx+energized-1], 1<<1 ; left going left
.done:
jmp bkwd_for_chars_cont
bkwd_horz_split: ; -
; our energized is what hits us
; right and left propagate
; test right
bt eax, 0
jnc .t_left
or byte [esi+ecx+energized+1], 1<<0
.t_left:
bt eax, 1
jnc .t_vert
or byte [esi+ecx+energized-1], 1<<1
; down and up go both left and right
.t_vert:
and eax, 1<<2 | 1<<3
jz .done
or byte [esi+ecx+energized+1], 1<<0 ; right going right
or byte [esi+ecx+energized-1], 1<<1 ; left going left
.done:
jmp bkwd_for_chars_cont
bkwd_vert_split: ; |
; our energized is what hits us
; down and up propagate
; test down
bt eax, 2
jnc .t_up
or byte [esi+ecx+energized+LINE_LEN], 1<<2
.t_up:
bt eax, 3
jnc .t_vert
or byte [esi+ecx+energized-LINE_LEN], 1<<3
; left and right go both down and up
.t_vert:
and eax, 1<<0 | 1<<1
jz .done
or byte [esi+ecx+energized+LINE_LEN], 1<<2 ; down going down
or byte [esi+ecx+energized-LINE_LEN], 1<<3 ; up going up
.done:
bkwd_for_chars_cont:
dec ecx
jnz bkwd_for_chars
bkwd_for_chars_done:
bkwd_for_lines_cont:
sub esi, LINE_LEN
jns bkwd_for_lines
cmp ebp, [last_energized]
mov [last_energized], ebp
jne next_iteration
; print final
xor ebp, ebp
print_final:
xor esi, esi ; top line
.for_lines:
xor ecx, ecx ; leftmost char
.for_chars:
movzx eax, byte [esi+ecx+energized]
movzx ebx, byte [esi+ecx+file]
test al, al
jz .prnt_char
inc ebp
p_string ansi_color_highbold_green
cmp bl, '.'
jne .prnt_char
popcnt edx, eax
cmp edx, 1
jg .prnt_num
cmp al, 1
je .prnt_right
cmp al, 2
je .prnt_left
cmp al, 4
je .prnt_down
.prnt_up: mov al, '^'
call print_char
jmp .prnt_done
.prnt_down: mov al, 'v'
call print_char
jmp .prnt_done
.prnt_left: mov al, '<'
call print_char
jmp .prnt_done
.prnt_right: mov al, '>'
call print_char
jmp .prnt_done
.prnt_num:
mov eax, edx
call print_dec
jmp .prnt_done
.prnt_char:
mov al, [esi+ecx+file]
call print_char
.prnt_done:
p_string ansi_color_reset
.for_chars_cont:
inc ecx
cmp ecx, LINE_LEN-2
jbe .for_chars
.for_chars_done:
.for_lines_cont:
call newline
add esi, LINE_LEN
cmp esi, len(file)
jb .for_lines
call newline
game_over:
mov eax, ebp
call print_dec
call newline
jmp exit
[section .data]
final_value: dd 0
last_energized: dd 0
file: incbin FILENAME
.over:
[section .bss]
padding: resb 128
energized: resb 128*128
[section .rodata]
what_the_fuck: db "Something is terribly wrong in this world."
.over:
ansi_color_reset: db `\e[0m`
.over:
ansi_color_green: db `\e[0;32m`
.over:
ansi_color_highbold_green: db `\e[1;92m`
.over:

285
16/utils.s Normal file
View File

@@ -0,0 +1,285 @@
[bits 32]
[section .text]
; call # val val2
; int $0x80 eax eax edx -
;
; arg1 arg2 arg3 arg4 arg5 arg6 arg7
; ebx ecx edx esi edi ebp -
exit:
mov eax, 1 ; exit
int 0x80
; filename in EBX
; return handle in EBX
; read only
open_file:
push eax
push ecx
mov eax, 5 ; open
xor ecx, ecx ; read only
int 0x80
mov ebx, eax
pop ecx
pop eax
ret
; file handle in EBX
; buffer in ECX
; count of bytes to read in EDX
; return bytes actually read in EAX
; exits on error
read_file:
mov eax, 3 ; read
int 0x80
test eax, eax
js .err
ret
.err:
mov eax, 4 ; write
mov ebx, 1 ; stdout
mov ecx, .err_str
mov edx, 21
int 0x80
jmp exit
.err_str: db `Could not read file.\n`
; string input in ESI
; value in EAX
; CF set if none, clear if some
; ESI set past checked area
dec_parse:
push ebx
push edx
push edi
xor eax, eax
xor edi, edi
mov ebx, 10 ; base
lodsb
sub al, '0'
js .no_input
cmp al, 9
jle .got_char
.no_input:
stc ; set CF
jmp .done
.loop:
xor eax,eax
lodsb
sub al, '0'
js .dec_done
cmp al, 9
jg .dec_done
.got_char:
xchg edi,eax
mul ebx
add edi,eax
jmp .loop
.dec_done:
clc ; clear CF
.done:
mov eax,edi
pop edi
pop edx
pop ebx
ret
; string input in ESI
; value in EAX
; CF set if none, clear if some
; ESI set past checked area
sign_dec_parse:
push ebx
push ecx
push edx
push edi
xor eax, eax
xor edi, edi
xor ecx, ecx ; neg flag
mov ebx, 10 ; base
cmp byte [esi], '-'
jne .no_minus
inc esi
mov cl, 1
.no_minus:
lodsb
sub al, '0'
js .no_input
cmp al, 9
jle .got_char
.no_input:
stc ; set CF
jmp .done
.loop:
xor eax,eax
lodsb
sub al, '0'
js .dec_done
cmp al, 9
jg .dec_done
.got_char:
xchg edi,eax
mul ebx
add edi,eax
jmp .loop
.dec_done:
test ecx, ecx
jz .not_neg
neg edi
.not_neg:
clc ; clear CF
.done:
mov eax,edi
pop edi
pop edx
pop ecx
pop ebx
ret
; modifies no regs
newline:
pushad
push 10
mov eax, 4 ; write
mov ebx, 1 ; stdout
mov ecx, esp ; string
mov edx, 1 ; length
int 0x80
add esp, 4
popad
ret
; modifies no regs
space:
pushad
push 9
mov eax, 4 ; write
mov ebx, 1 ; stdout
mov ecx, esp ; string
mov edx, 1 ; length
int 0x80
add esp, 4
popad
ret
; input in EAX, all regs unmodified
print_dec:
pushad ; save regs
; max 4294967296 is 10 chars
; round to nearest 32-bit boundary
sub esp, 12
; string in ECX, length in EDX
lea ecx, [esp+11] ; last possible byte
; check for 0
test eax, eax
jz .zero
mov ebx, 10 ; base 10
xor esi, esi ; counter
.div_shit:
xor edx, edx
; divide
div ebx
dec ecx ; next char
inc esi
; store
add dl, '0'
mov byte [ecx], dl
; check if done
test eax, eax
jnz .div_shit ; continue
mov edx, esi ; counter in edx
jmp .write
.zero:
mov byte [ecx], '0'
mov edx, 1 ; length
.write:
mov eax, 4 ; write
mov ebx, 1 ; stdout
int 0x80
add esp, 12 ; restore stack
popad ; restore regs
ret
; input in EAX, all regs unmodified
print_sign_dec:
pushad ; save regs
; range -2147483648 to 2147483647 is 11 chars
; round to nearest 32-bit boundary
sub esp, 12
; string in ECX, length in EDX
lea ecx, [esp+11] ; last possible byte
; check for 0, negative
xor ebp, ebp
test eax, eax
jz .zero
jns .positive
neg eax
mov ebp, 1
.positive:
mov ebx, 10 ; base 10
xor esi, esi ; counter
.div_shit:
xor edx, edx
; divide
div ebx
dec ecx ; next char
inc esi
; store
add dl, '0'
mov byte [ecx], dl
; check if done
test eax, eax
jnz .div_shit ; continue
mov edx, esi ; counter in edx
jmp .write
.zero:
mov byte [ecx], '0'
mov edx, 1 ; length
.write:
test ebp, ebp
jz .no_minus
dec ecx
inc edx
mov byte [ecx], '-'
.no_minus:
mov eax, 4 ; write
mov ebx, 1 ; stdout
int 0x80
add esp, 12 ; restore stack
popad ; restore regs
ret
; input in ESI, len in ECX, all regs unmodified
print_string:
pushad ; save regs
mov eax, 4 ; write
mov ebx, 1 ; stdout
mov edx, ecx ; length
mov ecx, esi ; string
int 0x80
popad ; restore regs
ret
; input in AL, all regs unmodified
print_char:
pushad ; save regs
push eax
mov eax, 4 ; write
mov ebx, 1 ; stdout
mov edx, 1 ; length
mov ecx, esp ; string
int 0x80
add esp, 4
popad ; restore regs
ret
; --- MACROS ---
%define len(x) x %+ .over - x
%macro p_string 1
push esi
push ecx
mov esi, %1
mov ecx, len(%1)
call print_string
pop ecx
pop esi
%endmacro

3
17/Makefile Normal file
View File

@@ -0,0 +1,3 @@
all:
nasm -g -felf32 main.s && ld -melf_i386 -g main.o

143
17/input Normal file
View File

@@ -0,0 +1,143 @@
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
$545452221113224242466233542635423355626253426445443455757673665557347647355656433643746353634644662254525636256443646245624542442323123124434$
$423123553224156354662663652662565323453542525447336537477575644434676433736577536377777334455463373535224645325663632555343244432114515143455$
$412533154242243224353222366252356526355257367576363643744576774435663654744573466766563337774647645676664423643264353633522462246212343543534$
$312324515521642422652636445534644554523665356655534343537375547744446437364446564476574363354465364444335526246456466465534642522545221525355$
$431513132425342544645256323442532642676557544454577773477553376746647356735654457637736466555435447757676662446326565224355645426536544353433$
$152515313256642445666534554544332644373336536336456577474544746374336345737444775367547736546647553566343437636426552263525243344634253243155$
$135443325556463563643622655423352436666776776734633546375567453734754553445667477777766555547773656573443454755625255564266524452554644145234$
$241513543232556336524232462424435737746743746575776755464666467353446767477357654573667646735353777447336743456434254233635466225242632525121$
$442114466425542236636355532623577635665736777673573577436763575554353467744376756337466776666746547776573643366373454532562525346426364521212$
$541155622643423523354262433657364363646354575667566357546477534336746476674745444646634665776653773333473375747756253522266653336465444335443$
$315134623523366526522266354747643547566373676536336653534764337367777657666544734333553663574737675665473765764555363545425566323646362446212$
$353142355424432653444565325346456566644744764673467744633777464737845775474776766376767444574545433637456635633567664644636222333626546663624$
$315262562366632565525535545577665554665674353536337736534348577475484854557474447578374345363774654336434544754674634746633244226523442264433$
$335545645535423623266436675456635746457674747674657776647557877646646675874757745664876653556564444533753335375443577665252425255534456546245$
$553355652652264636363367377346645567667346557653434567688677545486848565546546665444456784473354343544647657374633433333555233425565253533356$
$243333363523322443663544336473347367764656335567475568787767645554484767666557847484654575478446467365374457346344653755573346552525256565322$
$666223435352636335653467647754757343776765635446446788867658547858868785684748487568855845688555756333373536554535476756744646434652424342333$
$645455232354462344243445636673564336664747664878865467785568865677886748754847884644784467558578757766455653753346354754754655533565264232532$
$466264662434546564673354575575444753656373744566465676768746765458687768457555786448878877475448775543545436357333657537436536626255346662656$
$654524643332325657443773473345666645437437457786476648665876645875844657466548548677668648768478465858346357657453545354733536252225236325324$
$245235543533534454757574456473757344733876884576864756557877774546778774555757444877858775558546876676464645537473477737556335324623665264554$
$552235662634536547455366376357656336444664848888574766754875756656755876868444465858655555676566668664686665663544655356774567736546326366635$
$353542423524446556643335547536347646576756685775676766655557774844768557867884484585678554847845646654865854437565545635345436754335643323263$
$326635253342553646346557637354574467764875575745775547574584574755667545768464448746656755546475444547874465334763664737345747437656333254563$
$653335566256277556643667467346775367576846755455468867867557557555887765578448878848456454866856764644668486873436476677765536767642445626356$
$353255366565746364356754435755657577566867745558644476548588748884548574488784666876485787774565875677468876756676547447547545755532634442565$
$526256464444756734475435756673776484768854466755657745844446568666657957857746556588454768855565754764675454455437656334744533657457623236224$
$345546363576475673635365446743587548544658648758765765475847775665595995997557889547584448655877685856876666444644644334674665743567346233266$
$533654332435774354776646364446474846575477447574584776856576779765587966968987698878988545587567868486876764888877575753575453556376745642566$
$633636424573637734764776635667487684676748668665568566866889869557556755989955889797856987487464457458644645786764873746476745365753365432463$
$436434525766744544555467765487678745586567856888558789667967898667788975588775596575969899765767668556484474454574865565553453736343757423566$
$562564353763677646656565447585778775865488767878759868968558979588977867688659588986697765665477854856584885664466675345566465573666456355365$
$232544366666336545573336765565884686888688676464687896586586865697669996659769557995958979656645555844656646558777648564373757645766465564263$
$325226433577434645734663776868484484574546847759659798668887755976978658579669665775876995696766765667567564857767757436736433534574356375464$
$233434647657566365675564855678657456764555868565669776899967977985978785677658977569987558877878886856748745484877655877536777645733565672553$
$346247373476565353376638555656666547878646777776699966987887775565755667655885557989588579667655656868844566557565885884763657647737363335464$
$532243475547755575777345844444764678745788878877675956599689759687889958677777568677756559957698788764847454855744856566777557736766676435464$
$262676537574457653774457566747874566475585789698955597778655878869799695678789958999766885657857566894858485757754485588476476734355556634663$
$554273745665445654454755465755788884874769777895865665659996575789596765989769785679566759565995579779754867476767446844747337344367377354722$
$223443465575665667345468464778664565646768567659578566988667856788688568878858975798856895758586987665776878777467678677846363447364466655752$
$356675376476767636478486488564575777675577587995586676557599976687578955896587568597887786867768768799584654454457787674446666776457355366334$
$446346746755447335376878747444548484767989866757676988577659767879598868996657877558889985695985588655575884455566754554678576776575736753747$
$554354566643337445757665664854558565869858866656857656695755689989897768888898967697656665688856899957759956444477448748884634353575536635376$
$534454344735356453685855755866568857866855877775658577698557768996777867979869796665786759779765759587979888785478444554847485657467766647545$
$443436776547774645468645577867656488896978758777798895598889679866888688869967986666655558857856758797976585648874675868764677345555644357543$
$257746743747434447467858858468464667666857679685959656776766788988696989987877767689978775665995977695959698477585465847875658656777474576447$
$645547747335346637656657768676586568997777755987596665968768787877997778697867879896899888669887779959895769844445545565666568367653644677547$
$553466736466736684746886666654678758976976679578775799668666689897777666887669787796967877596969796967796888966448555755588488566576673775433$
$776446577567576687686786446648658876958999656689977798667789899869887868779686996797769789857565999575769965795557567748557544647767643763474$
$445356637656674775556644475678659975969567657958685979868977878989668969687788668968878769775976789797698975665486687555884857456546534543563$
$463645333465775785746547746866865768899858897765787788669686689668888676768786776797687678987958668775876759975857585586487667853553464535457$
$564477673374747676645744768548578875768658857689997867667699686677789987896686787796899786989869758579587756857588556884768666757763734637656$
$753556345564735887488486654567965956577557956858677778979967788997886678979888678999679867786776689598666566999857586845478647775545436555553$
$345365637574455675565456864445579975865657859877896789776886696797878887676788766779699976687768989758796767975696688486546867688535773437576$
$563643757353635744777558764668598788688667657587699768679877688999788976678779987678888899988696779888988599798896845755458568487466666645664$
$543444466456568748754448767568587899956585778776877666796699889797797698667887698787866798988969666759756886776686778745884658447476754743675$
$775555364536476764685787847556888796868878858669787979898869969899798699976896877676666868866868676677787775667578585574574466774833577574646$
$634564673656787575774464768665888587665968667897896986988997878998889897878779887897997869989668679679957889756995447574784558575577733545643$
$577736376747365476448748478477796768757799598789868889798968776688779897897789868968889799788966888869898975668865987448565667558857736635643$
$466345746537546444778477645588885858759799788669769866667686687799778787887998988778696998968788686886759968759855878458545755745583464766353$
$367655547534675485475587886859656798596775967889999876777668999898997779779999977967889897689698666959958577896968754558887878487466364554457$
$653764635533546656444544748669777855769689666767996998967768787987877997777789877879797669966789688659586895965976884575646866457567553356675$
$446653547537785576645688746776557769889589679688779797969868988999887999799878887798996677697677978795956576655686964586475875475887577735776$
$344564775776467555666785757659665856977858698769987778997678797998997999999897899987886899987688889897695889685799576867746777467646546576365$
$654736333377688685576656654998969878958759867686996898766689989879877978777889778787868686788887869786797867597879898644784877645754354536375$
$767747647435455487886768675697877659896578787788669769779799998887879887889788888997789687686768666868776559656566955647588756888764347454776$
$774457766435866645686575458679965688767955998897969876799898877798778987778797797888997778868978867995859657556696594555667474878485536473347$
$366445576358856847557447789956599979755857769987889697967987878888879779878778977978986998889968887667768699579866588587785767748754376363554$
$766344743577475764568847579997598855976966669699688996999998987878789798788998777778898668697689869778596566556756677764576558674474576657474$
$736745557656466465485456767695967885795567669968688899788877778797997779788799999888779699767799986898695888998859665878677555646544465653554$
$577753734565685574848584466665798865998576787897887876898999799789897997898988879777977976686779986687656986997797786567785888786465457333447$
$543537356746774554476444747757978996777959898679879879898977897778987978898988989978978897768898866666796995878796566477765667684545335437676$
$437766576438547766556675687655968789988677789998678687769788997898888998987997777989979796877677699676678769556989886464447864567655446374465$
$774667644357778464657467446768777587599896669768898996799998899788777877898778789789886686796669799666668777585998986876745458765677776336474$
$673456737734575477884884555698977778886667898889798678889979888778788778978887888777789669779686678965957559675775777488875554667477337777664$
$665743475468848468864485465868588566687856668986879966888979797778988898997999899999898796978989787969699597586995555564868557476684777756734$
$646554756444674645545745554559686885658675878898988999988988999789988998987879997879776797879869887967979579868767585566467556584857466573677$
$364764647433677788866778744599756867979797699869867787666678777898999787898989797789767698987787689975759897675779695758585566676486736437565$
$535657367676788744488555688866567598959667976889768897689998888978878888799897997777877889778777976969959559979798875545858676548565476756446$
$633363763563454644784858847895797557969965876677987878976787878779988997777977799998877787677976867878977587865957557486665588466457543463635$
$375433566546784568846466745598558655679968776668798787899889779877878988779887997778797888678778996867596666657866874675645464786473443555447$
$434655743646446455646846467678988778555555686866869776667867788797877999888887888976676979997998988976998588698965984485774787566574577553376$
$757663464775848684556667686775675566755668979679877689867998687897999788888899797969769667797686789969697795968885567685786664865545733646333$
$436536333433585884585488446757557568878876857999666686869666787778897988977877887686867777689966698889899988598867685787566778656564477735445$
$436574534734348886888756757498889965758885899878987888866677979798879779777899977868767868996877788995778656675966566755867567565574633456555$
$564764653563688455554454885545886885979986956966688986677768987888887788888986967968696889979678777755778658995959858577865848685846647676536$
$774666566543587578854654454459798858796687579678788997996798879976879988877696966976978868687797675777579588669865747866555654646757563764356$
$334653746666747767874888446759658578686597896567669986768687786769869666679968799886689699667888658865797857988986544445767866746843445663555$
$775344654767678685848468464575877876687899677597996789798676698776979787769968688886967768966777857569696867798987665668774554657436543557567$
$766543343765565746568886858757686865568578796657979967896798688987979798966679878979878987979679598685776666567766775448885878555657665547357$
$636655364436434455888845888778685568678599896776668766887767676667867787968869876966876666689866987776969877858886687745584764557354464333464$
$675765663744534578545687478578698557858656798867678988867967999777996889699687796687898679786896785675995877868655448555846488877754667477734$
$376666657777454776866467685478859857875585897867777886776668979799679889766696977797676899977576857679985779975754888884877866665753763656567$
$553656636455355675644444444747459698859777767998579698866968997767787668988968899867897668767998695767758686979684446467848778567374445455366$
$754746745637544445664687865676568868689986785689987697689689969698679786996868877777898786786677866785998778985766777464665886563347736757447$
$744657466646636774744445554675666676868675955555767858786996667879668878978868776888798796869879978857865577996565788644766846855557536433763$
$446745655755373767857866885858587788668877866696695565989667697677966767697869689788978969797665869856666577584454657576664775376733565354756$
$654636755367566664586687484447778479787695578876796699778799789899898676987968866887987986956877768755999996846745684654755648755434654444754$
$635344556537573455855776668478688447578999955979699999695669968667779887688976668788756786965858995755576656777877658545555555647667534575366$
$435747556465374336665458878467447445675959779776975698666756899678787988689897869778795885896759756577958888884545566466868655534765435574357$
$437767766643564433747554467577668757587776755668689999998555765778667999677696988696955786556876667667988974746747864478454737537664677453677$
$664347635467563437656868568685484468455677569986876985879577699879986797878559965665568857786598876697898847446667476764656445454547563774635$
$335453357433477464545778558588687458646696878686798565588759596859598855679658897766897786687897896866587457546877768774845653576735343735752$
$655777543774646674548678844477675556474688567958786967887956958887675987768675555986588965589688887889886444888584878476586567343575354445663$
$235453363477465436646567678856678577655849767566798556879779898997989755658656559688876996696676858559457557464577456788673465676535365674745$
$653557535667556645354467867774587468586488865599677669989755886567678697988757889697878875858955878776457675775448445776473464477477767663723$
$423647457774664567367567688588786455886875877685666999576569666558878966575579888958887568875959897748876746485847657558833665657763667534445$
$642244736374347334553476484454457886864876777558556996776685999679967876675775769557785885758655565867454657858447768578474753663535574334625$
$336436733375445675473664646565856555648864767887656769899695675757975675565687699957587897798858758888587654455645575843733477364463637346554$
$335435534663443676666667487578676657684784777487588895569858889859686655956678559995599665976775765566474568674477774565755333637557456443362$
$544553574555543574737357456786577646746577857444859685759965869665959565775665768787565556566764745674557877684464784337435554455363447424542$
$532466367673434664644354657754588778676755775886768666885868799568878785557855988668678578786766445778646767754547786674353344647665577622636$
$254546266574455447676333746874647468845746684454766755965578588856776657996755995866665756584754744857764888446555686474747766466477373363255$
$266564352377575777574547445766866788765476854777647777755855596796559556988877659996958566787777584545576775754474473767554467654656553554332$
$522256355666446675564456747738664767486874667675476687786478896698989959668656659687968467645876545646468576457566664435353565756335325455423$
$444323436545645543755363664545566464457866856586678787858786757778956969568579798946747584467867878657848746487767644665534735673753556344635$
$323454432324636457364755566663657568465848475587778876786656855775678985985658687848774858847777567884787865845753573673347657574545444662333$
$634265532422373635667776375763433576454587888546578776578558775467647857865566478665585765455686464585664454657577753367736355637473456622255$
$622652422623346667557377766536775386775555647476757786588468585876875775475874454678454778445754858785856648473657737554774554374752234543644$
$626444363465537553657447547553534338748756846655465484858676444775654756856447485566556646575845685575686466474566556633663543776752343555663$
$535442263436653363546357777754675735775658785476758746846756747484788667788686756847555568587746787644556655745755367533554735377434563655355$
$554342625636334436643667447345746337765466846668685587767846687654478458468576565878864858748845754784458634476773434474546454344452263624345$
$565345336254245667667673464644643655375486646848574888844888558867884754554747767566586664467557686445654336335375474476363464323325434436625$
$332442354652352554553756635666445463456537777656657588588744485464885685786874588448866685887758677684775654736344634537577646434553463233633$
$264423644454226544363333743363353543453764748557767447766744574745865865746448687884547865745856555847664474444567466455356545323344624233336$
$624364424324325525254434475736744543756757746455757545887885684854876555585578764754564576867554753746356355666473343373737424256554255423523$
$662433222232665256245775334733557673537364464544457667464687655758776565487564647678487555685857676544475746676457447467754565543233223432355$
$335526225663422356565753436745336336337473673334447858766557576685575848668868544646668474687675476677666534474734376777532524234366425532456$
$224434544223322234353647375646454645545464356533655787476846747488548474786866778666778547634433667755755733766475767655364426634454342243225$
$115343665234633546565263376447534744657646576367346453768575867668478755786458868487856743347563663553647377756353665654344434266256634336435$
$542522653445666245465264554744743545554757337454635474734676576664554868545884455857744457443343774776545543664436646636526654445346625264641$
$212345454243326345366432525643537663566453477653467557566745535745888465744676443367676664343457436353346547364465644462456633524632446434245$
$152256444334346664644636266764544353565677537647674477765463657665645367433374777437633774465675755553674563647647452223353432253226324623542$
$543314543643455255443324653447436466475546347473733756375574455574647736546663676737753633747536667644363433373577625266565562536523653263531$
$323324156556533366424334223663556664354675665737455445654473743546365645433344367436563477354677564675374746774552632626523436564364436333125$
$235252143234364223446642636543224575373637463676356753733454753456563336535346777535556775743565435544465673644434525462634226464524365541444$
$132152313563645443345466655333626644763757433545675545554636757343657777557575474647543744454353557547677667745433252345352224344346244251442$
$145324252553642322332363652223266265665333337557545545565467373344435373577653536363764744455463574577733745442455342654643644622632454545141$
$532551554325522544422365464343624222657554543453736435733353775644654357356557335773453777745644576533447446326624326254632635265444511254421$
$231415354245432533366263463246653334334533336463333665345436677477356745734756355353637773745467756534536353223454622442252244524633251135155$
$115313455335154364554632663442562633255536347755433457547673466773633747543655343555654635633737643533463222323433222456626424343225333455422$
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$

15
17/input_test Normal file
View File

@@ -0,0 +1,15 @@
$$$$$$$$$$$$$$$
$2413432311323$
$3215453535623$
$3255245654254$
$3446585845452$
$4546657867536$
$1438598798454$
$4457876987766$
$3637877979653$
$4654967986887$
$4564679986453$
$1224686865563$
$2546548887735$
$4322674655533$
$$$$$$$$$$$$$$$

422
17/main.s Normal file
View File

@@ -0,0 +1,422 @@
%include "utils.s"
global _start
[bits 32]
[section .text]
; len +2 for padding
%define LINE_LEN (141+2)
%define FILENAME "input"
;%define LINE_LEN (13+2)
;%define FILENAME "input_test"
%define DBG_PRINT
_start:
; convert input file to useful data
mov esi, file
mov edi, cost
convert_input:
lodsb
cmp al, 10 ; \n
je .cont
cmp al, '$'
jne .num
mov al, 0xFF
stosb
jmp .cont
.num:
sub al, '0'
stosb
.cont:
cmp esi, file.over
jb convert_input
; im lazy so doing dijkstra
; thanks wikipedia
; for each vertex v in Graph.Vertices:
; dist[v] ← INFINITY
; prev[v] ← UNDEFINED
; add v to Q
mov ecx, LINE_LEN*LINE_LEN*32
mov eax, 0xffffffff
mov edi, dist
rep stosd
mov ecx, LINE_LEN*LINE_LEN*32
mov eax, 0xffffffff
mov edi, prev
rep stosd
mov ecx, LINE_LEN*LINE_LEN*32
mov eax, 1
mov edi, q
rep stosb
; for all real dir:
; dist[source@dir] ← 0
mov dword [dist+((((LINE_LEN*32)+(32*1)))|0b00_000)*4], 0
mov dword [dist+((((1*(LINE_LEN*32))+(32*1)))|0b10_000)*4], 0
; while Q is not empty and any dist[u] in Q < inf:
; u ← vertex in Q with min dist[u]
while_q:
xor ebp, ebp ; test node
mov ecx, 0xffffffff ; best dist
mov edx, 0xffffffff ; best node
.find_min:
cmp byte [q+ebp], 1
jne .cont
cmp [dist+ebp*4], ecx
cmovb ecx, [dist+ebp*4]
cmovb edx, ebp
.cont:
inc ebp
cmp ebp, LINE_LEN*LINE_LEN*32
jb .find_min
cmp ecx, 0xffffffff
je while_q_done
%ifdef DBG_PRINT
pushad
call newline
mov ebp, edx
mov eax, edx
xor edx, edx
shr eax, 5
mov ebx, LINE_LEN
div ebx
call print_dec
call space
mov eax, edx
call print_dec
call space
mov eax, ebp
and eax, 0b11111
call print_dec
call space
mov eax, ecx
call print_dec
call newline
popad
%endif
; remove u from Q
mov byte [q+edx], 0
; for each neighbor v of u still in Q:
; alt ← dist[u] + Graph.Edges(u, v)
; if alt < dist[v]:
; dist[v] ← alt
; prev[v] ← u
mov ebp, LINE_LEN*32 ; whatever
for_neighbor:
; turning neighbor 0
neighbor_0:
; neighbors += v@dir(u, ~u.dir & 0b10_000)
mov ebx, edx
not ebx
and ebx, 0b10000
; tmp := 32
mov edi, 32
; bt dir, 4
bt ebx, 4
; if CF tmp := LINE_LEN
cmovc edi, ebp
; bt dir, 3
; if CF tmp := -tmp
mov esi, edi
neg esi
bt ebx, 3
cmovc edi, esi
mov eax, edi
; v.dir := dir
or edi, ebx
; v := u + tmp
; CheckBounds(v)
; Graph.Edges(u, v) := cost(v)
; v := v + tmp
; CheckBounds(v)
; Graph.Edges(u, v) += cost(v)
; v := v + tmp
; CheckBounds(v)
; Graph.Edges(u, v) += cost(v)
; v := v + tmp
; CheckBounds(v)
; Graph.Edges(u, v) += cost(v)
mov ebx, eax
mov esi, edx
and esi, ~0b11111
add edi, esi ; v := u + tmp
mov eax, edi
shr eax, 5
movzx eax, byte [cost+eax]
cmp al, 0xff
je neighbor_1 ; off graph
mov esi, eax ; Graph.Edges(u, v) := cost(v)
add edi, ebx ; v := v + tmp
mov eax, edi
shr eax, 5
movzx eax, byte [cost+eax]
cmp al, 0xff
je neighbor_1 ; off graph
add esi, eax ; Graph.Edges(u, v) += cost(v)
add edi, ebx ; v := v + tmp
mov eax, edi
shr eax, 5
movzx eax, byte [cost+eax]
cmp al, 0xff
je neighbor_1 ; off graph
add esi, eax ; Graph.Edges(u, v) += cost(v)
add edi, ebx ; v := v + tmp
mov eax, edi
shr eax, 5
movzx eax, byte [cost+eax]
cmp al, 0xff
je neighbor_1 ; off graph
add esi, eax ; Graph.Edges(u, v) += cost(v)
; alt ← dist[u] + cost(v)
; if alt < dist[v]:
; dist[v] ← alt
; prev[v] ← u
add esi, ecx
%ifdef DBG_PRINT
pushad
call space
mov esi, eax
mov eax, edi
shr eax, 5
mov ecx, LINE_LEN
xor edx, edx
div ecx
call print_dec
call space
mov eax, edx
call print_dec
call space
mov eax, edi
and eax, 0x1f
call print_dec
call space
mov eax, esi
call print_dec
call newline
popad
%endif
cmp esi, [dist+edi*4]
jae neighbor_1 ; not better
mov [dist+edi*4], esi
mov [prev+edi*4], edx
; turning neighbor 1
neighbor_1:
; neighbors += v@dir(u, (~u.dir & 0b10_000) | 0b01_000)
mov ebx, edx
not ebx
and ebx, 0b10000
or ebx, 0b01000
; tmp := 32
mov edi, 32
; bt dir, 4
bt ebx, 4
; if CF tmp := LINE_LEN
cmovc edi, ebp
; bt dir, 3
; if CF tmp := -tmp
mov esi, edi
neg esi
bt ebx, 3
cmovc edi, esi
mov eax, edi
; v.dir := dir
or edi, ebx
; v := u + tmp
; CheckBounds(v)
; Graph.Edges(u, v) := cost(v)
; v := v + tmp
; CheckBounds(v)
; Graph.Edges(u, v) += cost(v)
; v := v + tmp
; CheckBounds(v)
; Graph.Edges(u, v) += cost(v)
; v := v + tmp
; CheckBounds(v)
; Graph.Edges(u, v) += cost(v)
mov ebx, eax
mov esi, edx
and esi, ~0b11111
add edi, esi ; v := u + tmp
mov eax, edi
shr eax, 5
movzx eax, byte [cost+eax]
cmp al, 0xff
je neighbor_2 ; off graph
mov esi, eax ; Graph.Edges(u, v) := cost(v)
add edi, ebx ; v := v + tmp
mov eax, edi
shr eax, 5
movzx eax, byte [cost+eax]
cmp al, 0xff
je neighbor_2 ; off graph
add esi, eax ; Graph.Edges(u, v) += cost(v)
add edi, ebx ; v := v + tmp
mov eax, edi
shr eax, 5
movzx eax, byte [cost+eax]
cmp al, 0xff
je neighbor_2 ; off graph
add esi, eax ; Graph.Edges(u, v) += cost(v)
add edi, ebx ; v := v + tmp
mov eax, edi
shr eax, 5
movzx eax, byte [cost+eax]
cmp al, 0xff
je neighbor_2 ; off graph
add esi, eax ; Graph.Edges(u, v) += cost(v)
; alt ← dist[u] + cost(v)
; if alt < dist[v]:
; dist[v] ← alt
; prev[v] ← u
add esi, ecx
%ifdef DBG_PRINT
pushad
call space
mov esi, eax
mov eax, edi
shr eax, 5
mov ecx, LINE_LEN
xor edx, edx
div ecx
call print_dec
call space
mov eax, edx
call print_dec
call space
mov eax, edi
and eax, 0x1f
call print_dec
call space
mov eax, esi
call print_dec
call newline
popad
%endif
cmp esi, [dist+edi*4]
jae neighbor_2 ; not better
mov [dist+edi*4], esi
mov [prev+edi*4], edx
; straight - neighbor 2
neighbor_2:
mov ebx, edx
and ebx, ~0b11111
cmp edx, (((LINE_LEN*32)+(32*1)))
je while_q_cont
; if u.dir & 0b00_111 < 6
; neighbors += v@dir(u, u.dir + 1)
mov ebx, edx
and ebx, 0b00111
cmp ebx, 6
jae while_q_cont ; neighbors done
mov ebx, edx
and ebx, 0b11111
inc ebx
; tmp := 32
mov edi, 32
; bt dir, 4
bt ebx, 4
; if CF tmp := LINE_LEN
cmovc edi, ebp
; bt dir, 3
; if CF tmp := -tmp
mov esi, edi
neg esi
bt ebx, 3
cmovc edi, esi
; v := u + tmp
mov esi, edx
and esi, ~0b11111
add edi, esi
; v.dir := dir
or edi, ebx
; alt ← dist[u] + cost(v)
; if alt < dist[v]:
; dist[v] ← alt
; prev[v] ← u
mov eax, edi
shr eax, 5
movzx eax, byte [cost+eax]
cmp al, 0xff
je while_q_cont ; off graph
add eax, ecx
%ifdef DBG_PRINT
pushad
call space
mov esi, eax
mov eax, edi
shr eax, 5
mov ecx, LINE_LEN
xor edx, edx
div ecx
call print_dec
call space
mov eax, edx
call print_dec
call space
mov eax, edi
and eax, 0x1f
call print_dec
call space
mov eax, esi
call print_dec
call newline
popad
%endif
cmp eax, [dist+edi*4]
jae while_q_cont ; not better
mov [dist+edi*4], eax
mov [prev+edi*4], edx
while_q_cont:
jmp while_q
while_q_done:
call newline
; last dist values
mov ebx, ((((LINE_LEN-2)*(LINE_LEN*32))+((LINE_LEN-2)*32))+0b00000)
print_last_dist:
mov eax, [dist+ebx*4]
call print_sign_dec
inc ebx
mov ecx, ebx
and ecx, 0b111
cmp ecx, 0b111
jne .space
call newline
mov ecx, ebx
and ecx, 0b11111
cmp ecx, 0b11111
je .done
inc ebx
jmp .cont
.space:
call space
.cont:
jmp print_last_dist
.done:
game_over:
jmp exit
[section .data]
file: incbin FILENAME
.over:
[section .bss]
dist: resd LINE_LEN*LINE_LEN*32
prev: resd LINE_LEN*LINE_LEN*32
q: resb LINE_LEN*LINE_LEN*32
cost: resb LINE_LEN*LINE_LEN
new_file: resb len(file)

363
17/main_part1.s Normal file
View File

@@ -0,0 +1,363 @@
%include "utils.s"
global _start
[bits 32]
[section .text]
; len +2 for padding
%define LINE_LEN (141+2)
%define FILENAME "input"
;%define LINE_LEN (13+2)
;%define FILENAME "input_test"
;%define DBG_PRINT
_start:
; convert input file to useful data
mov esi, file
mov edi, cost
convert_input:
lodsb
cmp al, 10 ; \n
je .cont
cmp al, '$'
jne .num
mov al, 0xFF
stosb
jmp .cont
.num:
sub al, '0'
stosb
.cont:
cmp esi, file.over
jb convert_input
; im lazy so doing dijkstra
; thanks wikipedia
; for each vertex v in Graph.Vertices:
; dist[v] ← INFINITY
; prev[v] ← UNDEFINED
; add v to Q
mov ecx, LINE_LEN*LINE_LEN*16
mov eax, 0xffffffff
mov edi, dist
rep stosd
mov ecx, LINE_LEN*LINE_LEN*16
mov eax, 0xffffffff
mov edi, prev
rep stosd
mov ecx, LINE_LEN*LINE_LEN*16
mov eax, 1
mov edi, q
rep stosb
; for all real dir:
; dist[source@dir] ← 0
mov dword [dist+((((LINE_LEN*16)+16))|0b0000)*4], 0
mov dword [dist+((((LINE_LEN*16)+16))|0b1000)*4], 0
; while Q is not empty and any dist[u] in Q < inf:
; u ← vertex in Q with min dist[u]
while_q:
xor ebp, ebp ; test node
mov ecx, 0xffffffff ; best dist
mov edx, 0xffffffff ; best node
.find_min:
cmp byte [q+ebp], 1
jne .cont
cmp [dist+ebp*4], ecx
cmovb ecx, [dist+ebp*4]
cmovb edx, ebp
.cont:
inc ebp
cmp ebp, LINE_LEN*LINE_LEN*16
jb .find_min
cmp ecx, 0xffffffff
je while_q_done
%ifdef DBG_PRINT
pushad
call newline
mov ebp, edx
mov eax, edx
xor edx, edx
shr eax, 4
mov ebx, LINE_LEN
div ebx
call print_dec
call space
mov eax, edx
call print_dec
call space
mov eax, ebp
and eax, 0b1111
call print_dec
call space
mov eax, ecx
call print_dec
call newline
popad
%endif
; remove u from Q
mov byte [q+edx], 0
; for each neighbor v of u still in Q:
; alt ← dist[u] + Graph.Edges(u, v)
; if alt < dist[v]:
; dist[v] ← alt
; prev[v] ← u
mov ebp, LINE_LEN*16 ; whatever
for_neighbor:
; turning neighbor 0
neighbor_0:
; neighbors += v@dir(u, ~u.dir & 0b1000)
mov ebx, edx
not ebx
and ebx, 0b1000
; tmp := 16
mov edi, 16
; bt dir, 3
bt ebx, 3
; if CF tmp := LINE_LEN
cmovc edi, ebp
; bt dir, 2
; if CF tmp := -tmp
mov esi, edi
neg esi
bt ebx, 2
cmovc edi, esi
; v := u + tmp
mov esi, edx
and esi, 0xFFFFFFF0
add edi, esi
; v.dir := dir
or edi, ebx
; alt ← dist[u] + cost(v)
; if alt < dist[v]:
; dist[v] ← alt
; prev[v] ← u
mov eax, edi
shr eax, 4
movzx eax, byte [cost+eax]
cmp al, 0xff
je neighbor_1 ; off graph
add eax, ecx
%ifdef DBG_PRINT
pushad
call space
mov esi, eax
mov eax, edi
shr eax, 4
mov ecx, LINE_LEN
xor edx, edx
div ecx
call print_dec
call space
mov eax, edx
call print_dec
call space
mov eax, edi
and eax, 0xf
call print_dec
call space
mov eax, esi
call print_dec
call newline
popad
%endif
cmp eax, [dist+edi*4]
jae neighbor_1 ; not better
mov [dist+edi*4], eax
mov [prev+edi*4], edx
; turning neighbor 1
neighbor_1:
; neighbors += v@dir(u, (~u.dir & 0b1000) | 0b0100)
mov ebx, edx
not ebx
and ebx, 0b1000
or ebx, 0b0100
; tmp := 16
mov edi, 16
; bt dir, 3
bt ebx, 3
; if CF tmp := LINE_LEN
cmovc edi, ebp
; bt dir, 2
; if CF tmp := -tmp
mov esi, edi
neg esi
bt ebx, 2
cmovc edi, esi
; v := u + tmp
mov esi, edx
and esi, 0xFFFFFFF0
add edi, esi
; v.dir := dir
or edi, ebx
; alt ← dist[u] + cost(v)
; if alt < dist[v]:
; dist[v] ← alt
; prev[v] ← u
mov eax, edi
shr eax, 4
movzx eax, byte [cost+eax]
cmp al, 0xff
je neighbor_2 ; off graph
add eax, ecx
%ifdef DBG_PRINT
pushad
call space
mov esi, eax
mov eax, edi
shr eax, 4
mov ecx, LINE_LEN
xor edx, edx
div ecx
call print_dec
call space
mov eax, edx
call print_dec
call space
mov eax, edi
and eax, 0xf
call print_dec
call space
mov eax, esi
call print_dec
call newline
popad
%endif
cmp eax, [dist+edi*4]
jae neighbor_2 ; not better
mov [dist+edi*4], eax
mov [prev+edi*4], edx
; straight - neighbor 2
neighbor_2:
; if u.dir & 0b0011 < 2
; neighbors += v@dir(u, u.dir + 1)
mov ebx, edx
and ebx, 0b0011
cmp ebx, 2
jae while_q_cont ; neighbors done
mov ebx, edx
and ebx, 0b1111
inc ebx
; tmp := 16
mov edi, 16
; bt dir, 3
bt ebx, 3
; if CF tmp := LINE_LEN
cmovc edi, ebp
; bt dir, 2
; if CF tmp := -tmp
mov esi, edi
neg esi
bt ebx, 2
cmovc edi, esi
; v := u + tmp
mov esi, edx
and esi, 0xFFFFFFF0
add edi, esi
; v.dir := dir
or edi, ebx
; alt ← dist[u] + cost(v)
; if alt < dist[v]:
; dist[v] ← alt
; prev[v] ← u
mov eax, edi
shr eax, 4
movzx eax, byte [cost+eax]
cmp al, 0xff
je while_q_cont ; off graph
add eax, ecx
%ifdef DBG_PRINT
pushad
call space
mov esi, eax
mov eax, edi
shr eax, 4
mov ecx, LINE_LEN
xor edx, edx
div ecx
call print_dec
call space
mov eax, edx
call print_dec
call space
mov eax, edi
and eax, 0xf
call print_dec
call space
mov eax, esi
call print_dec
call newline
popad
%endif
cmp eax, [dist+edi*4]
jae while_q_cont ; not better
mov [dist+edi*4], eax
mov [prev+edi*4], edx
while_q_cont:
jmp while_q
while_q_done:
call newline
; last dist values
mov eax, [dist+((((LINE_LEN-2)*(LINE_LEN*16))+((LINE_LEN-2)*16))+0b0000)*4]
call print_sign_dec
call space
mov eax, [dist+((((LINE_LEN-2)*(LINE_LEN*16))+((LINE_LEN-2)*16))+0b0001)*4]
call print_sign_dec
call space
mov eax, [dist+((((LINE_LEN-2)*(LINE_LEN*16))+((LINE_LEN-2)*16))+0b0010)*4]
call print_sign_dec
call newline
mov eax, [dist+((((LINE_LEN-2)*(LINE_LEN*16))+((LINE_LEN-2)*16))+0b0100)*4]
call print_sign_dec
call space
mov eax, [dist+((((LINE_LEN-2)*(LINE_LEN*16))+((LINE_LEN-2)*16))+0b0101)*4]
call print_sign_dec
call space
mov eax, [dist+((((LINE_LEN-2)*(LINE_LEN*16))+((LINE_LEN-2)*16))+0b0110)*4]
call print_sign_dec
call newline
mov eax, [dist+((((LINE_LEN-2)*(LINE_LEN*16))+((LINE_LEN-2)*16))+0b1000)*4]
call print_sign_dec
call space
mov eax, [dist+((((LINE_LEN-2)*(LINE_LEN*16))+((LINE_LEN-2)*16))+0b1001)*4]
call print_sign_dec
call space
mov eax, [dist+((((LINE_LEN-2)*(LINE_LEN*16))+((LINE_LEN-2)*16))+0b1010)*4]
call print_sign_dec
call newline
mov eax, [dist+((((LINE_LEN-2)*(LINE_LEN*16))+((LINE_LEN-2)*16))+0b1100)*4]
call print_sign_dec
call space
mov eax, [dist+((((LINE_LEN-2)*(LINE_LEN*16))+((LINE_LEN-2)*16))+0b1101)*4]
call print_sign_dec
call space
mov eax, [dist+((((LINE_LEN-2)*(LINE_LEN*16))+((LINE_LEN-2)*16))+0b1110)*4]
call print_sign_dec
call newline
game_over:
jmp exit
[section .data]
file: incbin FILENAME
.over:
[section .bss]
dist: resd LINE_LEN*LINE_LEN*16
prev: resd LINE_LEN*LINE_LEN*16
q: resb LINE_LEN*LINE_LEN*16
cost: resb LINE_LEN*LINE_LEN
new_file: resb len(file)

73
17/pseudo Normal file
View File

@@ -0,0 +1,73 @@
v@dir(u, dir) {
v.dir := dir
tmp := 32
bt dir, 4
if CF
tmp := LINE_LEN*32
bt dir, 3
if CF
tmp := -tmp
if dir & 0b0_111 = 0
v := u + tmp
CheckBounds(v)
Graph.Edges(u, v) := cost(v)
v := v + tmp
CheckBounds(v)
Graph.Edges(u, v) += cost(v)
v := v + tmp
CheckBounds(v)
Graph.Edges(u, v) += cost(v)
v := v + tmp
CheckBounds(v)
Graph.Edges(u, v) += cost(v)
else
v := u + tmp
CheckBounds(v)
Graph.Edges(u, v) := cost(v)
}
neighbors(u@dir) {
; can always turn
neighbors += v@dir(u, ~u.dir & 0b10_000)
neighbors += v@dir(u, (~u.dir & 0b10_000) | 0b01_000)
; can go forward if consec < 6
if u.dir & 0b00_111 < 6
neighbors += v@dir(u, u.dir + 1)
}
; 28 possibilities, use 32 so we can do bit hacks
; 00000 00001 00010 00011 00100 00101 00110 00111
; 0 1 2 3 4 5 6 7
dir = { R4, R5, R6, R7, R8, R9, RA, XX,
; 01000 01001 01010 01011 01100 01101 01110 01111
; 8 9 10 11 12 13 14 15
L4, L5, L6, L7, L8, L9, LA, XX,
; 10000 10001 10010 10011 10100 10101 10110 10111
; 16 17 18 19 20 21 22 23
D4, D5, D6, D7, D8, D9, DA, XX,
; 11000 11001 11010 11011 11100 11101 11110 11111
; 24 25 26 27 28 29 30 31
U4, U5, U6, U7, U8, U9, UA, XX}
dist[(x,y),dir]
prev[(x,y),dir]
q[(x,y),dir]
for each vertex v in Graph.Vertices:
dist[v] ← INFINITY
prev[v] ← UNDEFINED
add v to Q
for all real dir:
dist[source@dir] ← 0
while Q is not empty and any dist[u] in Q < inf:
u ← vertex in Q with min dist[u]
remove u from Q
for each neighbor v of u still in Q:
alt ← dist[u] + Graph.Edges(u, v)
if alt < dist[v]:
dist[v] ← alt
prev[v] ← u
done

285
17/utils.s Normal file
View File

@@ -0,0 +1,285 @@
[bits 32]
[section .text]
; call # val val2
; int $0x80 eax eax edx -
;
; arg1 arg2 arg3 arg4 arg5 arg6 arg7
; ebx ecx edx esi edi ebp -
exit:
mov eax, 1 ; exit
int 0x80
; filename in EBX
; return handle in EBX
; read only
open_file:
push eax
push ecx
mov eax, 5 ; open
xor ecx, ecx ; read only
int 0x80
mov ebx, eax
pop ecx
pop eax
ret
; file handle in EBX
; buffer in ECX
; count of bytes to read in EDX
; return bytes actually read in EAX
; exits on error
read_file:
mov eax, 3 ; read
int 0x80
test eax, eax
js .err
ret
.err:
mov eax, 4 ; write
mov ebx, 1 ; stdout
mov ecx, .err_str
mov edx, 21
int 0x80
jmp exit
.err_str: db `Could not read file.\n`
; string input in ESI
; value in EAX
; CF set if none, clear if some
; ESI set past checked area
dec_parse:
push ebx
push edx
push edi
xor eax, eax
xor edi, edi
mov ebx, 10 ; base
lodsb
sub al, '0'
js .no_input
cmp al, 9
jle .got_char
.no_input:
stc ; set CF
jmp .done
.loop:
xor eax,eax
lodsb
sub al, '0'
js .dec_done
cmp al, 9
jg .dec_done
.got_char:
xchg edi,eax
mul ebx
add edi,eax
jmp .loop
.dec_done:
clc ; clear CF
.done:
mov eax,edi
pop edi
pop edx
pop ebx
ret
; string input in ESI
; value in EAX
; CF set if none, clear if some
; ESI set past checked area
sign_dec_parse:
push ebx
push ecx
push edx
push edi
xor eax, eax
xor edi, edi
xor ecx, ecx ; neg flag
mov ebx, 10 ; base
cmp byte [esi], '-'
jne .no_minus
inc esi
mov cl, 1
.no_minus:
lodsb
sub al, '0'
js .no_input
cmp al, 9
jle .got_char
.no_input:
stc ; set CF
jmp .done
.loop:
xor eax,eax
lodsb
sub al, '0'
js .dec_done
cmp al, 9
jg .dec_done
.got_char:
xchg edi,eax
mul ebx
add edi,eax
jmp .loop
.dec_done:
test ecx, ecx
jz .not_neg
neg edi
.not_neg:
clc ; clear CF
.done:
mov eax,edi
pop edi
pop edx
pop ecx
pop ebx
ret
; modifies no regs
newline:
pushad
push 10
mov eax, 4 ; write
mov ebx, 1 ; stdout
mov ecx, esp ; string
mov edx, 1 ; length
int 0x80
add esp, 4
popad
ret
; modifies no regs
space:
pushad
push 9
mov eax, 4 ; write
mov ebx, 1 ; stdout
mov ecx, esp ; string
mov edx, 1 ; length
int 0x80
add esp, 4
popad
ret
; input in EAX, all regs unmodified
print_dec:
pushad ; save regs
; max 4294967296 is 10 chars
; round to nearest 32-bit boundary
sub esp, 12
; string in ECX, length in EDX
lea ecx, [esp+11] ; last possible byte
; check for 0
test eax, eax
jz .zero
mov ebx, 10 ; base 10
xor esi, esi ; counter
.div_shit:
xor edx, edx
; divide
div ebx
dec ecx ; next char
inc esi
; store
add dl, '0'
mov byte [ecx], dl
; check if done
test eax, eax
jnz .div_shit ; continue
mov edx, esi ; counter in edx
jmp .write
.zero:
mov byte [ecx], '0'
mov edx, 1 ; length
.write:
mov eax, 4 ; write
mov ebx, 1 ; stdout
int 0x80
add esp, 12 ; restore stack
popad ; restore regs
ret
; input in EAX, all regs unmodified
print_sign_dec:
pushad ; save regs
; range -2147483648 to 2147483647 is 11 chars
; round to nearest 32-bit boundary
sub esp, 12
; string in ECX, length in EDX
lea ecx, [esp+11] ; last possible byte
; check for 0, negative
xor ebp, ebp
test eax, eax
jz .zero
jns .positive
neg eax
mov ebp, 1
.positive:
mov ebx, 10 ; base 10
xor esi, esi ; counter
.div_shit:
xor edx, edx
; divide
div ebx
dec ecx ; next char
inc esi
; store
add dl, '0'
mov byte [ecx], dl
; check if done
test eax, eax
jnz .div_shit ; continue
mov edx, esi ; counter in edx
jmp .write
.zero:
mov byte [ecx], '0'
mov edx, 1 ; length
.write:
test ebp, ebp
jz .no_minus
dec ecx
inc edx
mov byte [ecx], '-'
.no_minus:
mov eax, 4 ; write
mov ebx, 1 ; stdout
int 0x80
add esp, 12 ; restore stack
popad ; restore regs
ret
; input in ESI, len in ECX, all regs unmodified
print_string:
pushad ; save regs
mov eax, 4 ; write
mov ebx, 1 ; stdout
mov edx, ecx ; length
mov ecx, esi ; string
int 0x80
popad ; restore regs
ret
; input in AL, all regs unmodified
print_char:
pushad ; save regs
push eax
mov eax, 4 ; write
mov ebx, 1 ; stdout
mov edx, 1 ; length
mov ecx, esp ; string
int 0x80
add esp, 4
popad ; restore regs
ret
; --- MACROS ---
%define len(x) x %+ .over - x
%macro p_string 1
push esi
push ecx
mov esi, %1
mov ecx, len(%1)
call print_string
pop ecx
pop esi
%endmacro

6
18/Makefile Normal file
View File

@@ -0,0 +1,6 @@
all:
nasm -g -felf64 main.s && ld -g main.o
part_1:
nasm -g -felf32 main_part1.s && ld -melf_i386 -g main_part1.o

784
18/input Normal file
View File

@@ -0,0 +1,784 @@
R 7 (#43c232)
U 6 (#1f0fa3)
R 7 (#18f980)
D 3 (#1c5a83)
R 13 (#2a4010)
D 8 (#10ed73)
R 6 (#43c470)
D 9 (#2c1c51)
L 12 (#372130)
D 6 (#2c1c53)
L 7 (#0e8680)
D 6 (#3c7e13)
R 7 (#2f0660)
D 4 (#187de3)
R 6 (#6f1062)
D 8 (#3e68d3)
R 14 (#0b0972)
U 7 (#3b8553)
R 10 (#1bbcd2)
U 8 (#5aa601)
R 9 (#59c0b2)
U 3 (#5aa603)
L 14 (#0c14c2)
U 2 (#1b79e3)
L 4 (#322f62)
U 6 (#416201)
R 5 (#366202)
U 12 (#416203)
R 13 (#3fd0d2)
U 3 (#331943)
L 9 (#0c5f82)
U 3 (#2f0303)
R 9 (#6f6222)
U 9 (#4fd8a3)
L 11 (#15eaf0)
U 14 (#374c63)
R 11 (#0c26f0)
U 6 (#3f7353)
L 6 (#125130)
U 7 (#51dae3)
L 8 (#382b30)
D 8 (#51dae1)
L 5 (#3cd4c0)
D 6 (#1a2ea3)
L 11 (#251d90)
D 14 (#0842b3)
L 5 (#55c8c0)
U 3 (#58dea3)
L 8 (#0b7bb0)
U 11 (#5b3af3)
L 4 (#382100)
U 9 (#47fe13)
L 6 (#01b2e0)
U 5 (#4e82f3)
L 7 (#6e3740)
U 14 (#1cb493)
R 9 (#2c13e2)
U 9 (#206be3)
R 2 (#422362)
U 8 (#3bcfb3)
R 9 (#35b660)
U 7 (#37b1c3)
R 5 (#0d2980)
U 5 (#38fae3)
R 9 (#33e870)
U 10 (#403e11)
R 8 (#400260)
D 6 (#225021)
L 5 (#716760)
D 7 (#0e1e71)
R 5 (#287120)
D 9 (#5a71b1)
R 4 (#015c40)
U 10 (#6d0161)
R 6 (#06ed20)
D 8 (#602ca3)
R 7 (#3ddc50)
D 5 (#1adef3)
L 4 (#51eca0)
D 4 (#1adef1)
L 8 (#167b90)
U 4 (#3c7553)
L 5 (#3651e0)
D 7 (#0ce671)
R 17 (#26fae0)
D 5 (#0ce673)
L 7 (#2216b0)
D 5 (#1ac753)
R 13 (#2585f0)
U 10 (#05c323)
R 4 (#6a5190)
D 4 (#0c9913)
R 4 (#53e6e0)
D 10 (#239103)
L 4 (#1a0b82)
D 4 (#217593)
R 7 (#117862)
U 8 (#0efd13)
R 11 (#3b6432)
U 7 (#0efd11)
L 11 (#449482)
U 3 (#4b4ab3)
R 7 (#400530)
U 7 (#093f03)
L 16 (#516be0)
U 8 (#529313)
L 2 (#1a0b80)
U 5 (#49b4e3)
R 13 (#388aa0)
U 11 (#268b13)
R 3 (#3ed060)
U 10 (#525fd1)
R 7 (#2dee20)
U 14 (#525fd3)
R 4 (#1c7120)
U 4 (#4b5dc3)
R 6 (#071870)
U 3 (#16bc91)
R 6 (#0f7ea0)
D 4 (#3c3a83)
R 5 (#40a2f0)
U 4 (#3c3a81)
R 8 (#322d90)
D 2 (#16bc93)
R 7 (#1a45b0)
D 3 (#0dda01)
R 2 (#002990)
D 14 (#3ce0a1)
R 6 (#09b080)
D 2 (#3f3411)
R 6 (#712ba0)
U 4 (#18fc01)
R 4 (#50ae42)
U 14 (#394c81)
L 8 (#5992d2)
U 9 (#2c5181)
R 8 (#485892)
U 5 (#304b41)
L 6 (#671760)
U 11 (#3b2833)
L 10 (#349250)
U 10 (#3b2831)
L 9 (#1fea10)
U 6 (#5a4581)
L 8 (#3705e0)
D 7 (#2140a1)
L 6 (#3e1360)
U 7 (#51bce1)
L 7 (#61f190)
U 2 (#105a71)
L 6 (#2f41f0)
U 7 (#2eb5a1)
L 8 (#6a2b10)
U 3 (#103f93)
L 8 (#358c70)
U 5 (#103f91)
L 4 (#44e3e0)
U 12 (#2eb5a3)
L 11 (#1d4ef0)
U 9 (#621753)
L 4 (#0a1d50)
U 4 (#249d51)
R 4 (#287d90)
U 12 (#539513)
L 13 (#4e0190)
U 3 (#539511)
R 9 (#2ff870)
U 5 (#47b5b1)
R 7 (#385e80)
D 6 (#319f31)
R 5 (#247600)
D 7 (#0546b1)
R 16 (#4ee172)
D 4 (#163921)
L 16 (#006a42)
D 9 (#5c7f61)
R 6 (#4f4bb0)
D 2 (#09d9f1)
R 12 (#2da090)
U 3 (#38a4a3)
R 6 (#233670)
U 12 (#411713)
R 7 (#44f222)
U 13 (#5936f3)
R 9 (#0846c2)
D 5 (#2495a3)
R 8 (#4d38e0)
U 8 (#284313)
R 2 (#004360)
U 9 (#591641)
R 9 (#249b10)
U 15 (#5dbd81)
R 10 (#542730)
D 12 (#0658a1)
R 8 (#202200)
D 13 (#63e481)
R 7 (#417100)
D 11 (#115831)
R 3 (#1308a0)
D 8 (#5d7591)
R 4 (#5bbe90)
U 7 (#1dc0a3)
R 5 (#051c50)
U 17 (#510d23)
R 3 (#2322f0)
D 15 (#020aa3)
R 6 (#47ea42)
D 9 (#09f123)
R 7 (#130062)
D 12 (#1a0523)
L 6 (#4a2022)
D 4 (#473b73)
L 6 (#6dfee0)
D 4 (#24c393)
L 7 (#6dfee2)
U 4 (#2cbcb3)
L 6 (#137852)
U 4 (#57d193)
L 8 (#2c6570)
D 9 (#2c2113)
L 5 (#30de90)
D 8 (#298141)
L 10 (#286a40)
D 2 (#298143)
R 10 (#2c7790)
D 8 (#2c2111)
L 4 (#065d40)
D 11 (#0ded33)
R 14 (#5189c0)
U 11 (#125f21)
R 7 (#183960)
U 10 (#280071)
R 3 (#1fe640)
D 5 (#2c8b81)
R 7 (#504d70)
D 9 (#532921)
R 4 (#03e252)
D 7 (#169441)
R 7 (#3d6792)
D 14 (#278961)
L 4 (#472332)
D 9 (#2c4981)
R 8 (#2df3a0)
D 5 (#2ca501)
R 13 (#06f2d0)
D 3 (#479821)
L 10 (#06f2d2)
D 14 (#0916f1)
L 4 (#3a21d0)
D 6 (#342e23)
L 7 (#143d52)
D 10 (#3de0a3)
R 4 (#143d50)
D 7 (#0b4553)
R 6 (#3578d0)
D 4 (#454381)
R 8 (#12b310)
D 15 (#5c55a1)
R 3 (#400ad2)
D 15 (#708e81)
R 4 (#44a4e2)
D 3 (#195891)
R 11 (#40cec2)
D 14 (#0bf6f1)
R 9 (#3f7c42)
D 7 (#44f361)
L 14 (#252c20)
D 7 (#219561)
R 14 (#252c22)
D 5 (#3b93f1)
R 5 (#3f7c40)
D 4 (#1b4631)
R 7 (#5a10e2)
U 10 (#403fe3)
L 6 (#1c0942)
U 5 (#166bd3)
R 6 (#0dfeb2)
U 10 (#2faa13)
R 9 (#442662)
D 11 (#430413)
R 5 (#24e8f2)
D 10 (#254ae1)
L 5 (#698c32)
D 4 (#450431)
R 10 (#698c30)
U 8 (#19b101)
R 7 (#280ab2)
U 3 (#207b01)
R 8 (#1056d2)
U 4 (#0188c1)
R 9 (#566192)
U 8 (#153a81)
R 8 (#0ff8a2)
D 12 (#50b171)
R 10 (#0611d2)
D 11 (#168a11)
R 11 (#0ac2c0)
D 8 (#27c361)
L 5 (#49f630)
D 17 (#27c363)
R 5 (#2809e0)
D 12 (#08f281)
R 8 (#5d4ed0)
D 5 (#60c0b3)
R 3 (#1281e0)
U 4 (#4ee241)
R 7 (#627020)
U 7 (#4ee243)
R 8 (#4cdbc0)
U 7 (#60c0b1)
R 7 (#425e30)
D 6 (#059533)
R 4 (#259d90)
D 12 (#059531)
R 8 (#5398f0)
D 5 (#0f94a1)
R 6 (#1f6202)
U 6 (#118ec1)
R 7 (#584412)
D 6 (#633d01)
R 8 (#15f142)
D 8 (#30fcf1)
R 3 (#545932)
D 7 (#2e3d11)
L 3 (#0e4c62)
D 15 (#029c53)
L 6 (#1c5592)
D 3 (#3d4a43)
R 2 (#139220)
D 3 (#526013)
R 5 (#139222)
D 11 (#12bd03)
R 11 (#3955d2)
D 7 (#2f0223)
R 7 (#301b12)
D 5 (#0639e3)
R 12 (#2dbde2)
D 7 (#0639e1)
L 15 (#368152)
D 3 (#035551)
L 4 (#504f00)
D 12 (#4daf51)
R 7 (#09a6a0)
D 4 (#4ade31)
L 8 (#5b7570)
D 12 (#2a8671)
L 10 (#0291f0)
D 2 (#0f4cd1)
L 7 (#6f41f0)
D 16 (#4c29f1)
L 9 (#135550)
D 7 (#227161)
L 11 (#0e4ab2)
D 12 (#5b4aa1)
L 6 (#3d25f2)
D 6 (#5b4aa3)
L 7 (#40ef22)
D 4 (#3c2521)
L 9 (#018b52)
U 7 (#19e481)
L 5 (#47bbf2)
U 7 (#088601)
L 10 (#21bf60)
U 6 (#3c1c71)
L 6 (#21bf62)
U 7 (#3df0a1)
L 11 (#45d380)
U 7 (#23fff1)
R 10 (#455c50)
U 4 (#2d4481)
R 7 (#4a7730)
D 4 (#20be61)
R 10 (#032890)
U 10 (#66a6e3)
L 6 (#174410)
U 12 (#31a043)
L 5 (#302140)
U 12 (#5240c1)
L 8 (#43c1e0)
U 11 (#5240c3)
L 6 (#498ad0)
U 12 (#31a041)
L 4 (#0612a0)
U 4 (#4cc393)
L 2 (#416240)
U 6 (#3f9c83)
L 4 (#6624a2)
U 6 (#2f4df3)
L 11 (#233af2)
U 7 (#67d713)
L 8 (#219562)
D 4 (#191fd3)
L 11 (#425670)
D 7 (#2f9aa1)
L 9 (#5826b0)
D 5 (#2f9aa3)
L 9 (#02b510)
D 5 (#1eee93)
L 7 (#0dc2c0)
D 9 (#5e5973)
R 7 (#3a3e70)
D 5 (#1a55b3)
L 3 (#5bc130)
D 11 (#3c03a3)
L 7 (#2add40)
D 8 (#2fd5e3)
L 7 (#140162)
D 8 (#11daa3)
L 8 (#5d1932)
D 11 (#11daa1)
L 9 (#1583e2)
D 8 (#4b35b3)
L 9 (#742210)
D 2 (#2cb393)
L 13 (#275e80)
U 3 (#5989e1)
L 5 (#04e2c2)
U 11 (#2865a1)
R 5 (#04e2c0)
U 13 (#7c28f1)
R 5 (#338d60)
U 3 (#6cb1a1)
R 3 (#33f4c0)
U 4 (#19a1a1)
L 13 (#404cc0)
U 3 (#4671a1)
L 4 (#467420)
D 14 (#4e3051)
L 11 (#2653e2)
D 5 (#2d21d1)
L 4 (#3fe972)
D 9 (#2d21d3)
L 6 (#547852)
D 9 (#523421)
L 8 (#61db40)
D 17 (#093c71)
L 7 (#013960)
D 9 (#5341d1)
L 11 (#137f70)
D 12 (#1f9541)
L 2 (#43d170)
D 3 (#3756f1)
R 2 (#1460c0)
D 16 (#5f6ae1)
R 3 (#3d9e12)
D 13 (#0e0541)
R 10 (#290712)
D 7 (#244a91)
R 3 (#08f492)
U 14 (#50e851)
R 9 (#319750)
U 6 (#50cce1)
R 9 (#3e0260)
D 6 (#133501)
R 4 (#3e7640)
U 4 (#5b11d1)
R 13 (#18ca50)
U 9 (#1bde41)
R 8 (#2f7fe0)
U 10 (#1d8fa1)
R 3 (#013520)
U 3 (#4a1001)
R 3 (#005960)
U 9 (#41de93)
R 10 (#5ac660)
U 7 (#25c113)
R 3 (#4a0ae0)
D 3 (#57bd11)
R 14 (#186ec2)
D 11 (#363301)
L 14 (#6f3c92)
D 5 (#30d021)
R 10 (#0b4520)
D 4 (#37c321)
R 5 (#64e710)
D 6 (#37c323)
R 8 (#352280)
D 13 (#3e6021)
R 5 (#023060)
D 3 (#34b0e1)
L 9 (#1134f2)
D 4 (#5ef331)
L 9 (#1a4052)
D 3 (#274471)
R 3 (#333bd2)
D 8 (#1e38a3)
R 12 (#3462b2)
D 4 (#67ff03)
R 3 (#146b52)
D 7 (#224ba1)
R 10 (#099452)
D 9 (#076ef1)
R 9 (#406312)
D 2 (#54eda1)
R 10 (#0fae42)
D 9 (#74d4a1)
L 4 (#220d72)
D 8 (#0b6731)
L 15 (#314cb2)
D 3 (#2541f1)
L 9 (#061062)
D 8 (#65c091)
L 8 (#220c02)
D 13 (#0e5b01)
L 11 (#4f0f62)
D 10 (#469d91)
L 14 (#31c612)
U 8 (#406ec1)
L 16 (#382f52)
U 5 (#479c53)
L 13 (#548c72)
U 8 (#4005f3)
L 9 (#610822)
U 2 (#02cfd3)
L 9 (#0d4c22)
U 4 (#4f4793)
L 5 (#2291b2)
U 7 (#53adc3)
R 6 (#3a5872)
U 4 (#25eaf3)
R 9 (#3dc5e0)
D 4 (#4cf953)
R 8 (#1e7810)
U 6 (#2fec63)
L 4 (#0c79f0)
U 10 (#144493)
L 8 (#39b740)
U 10 (#144491)
L 6 (#3a0830)
U 7 (#2c4793)
L 5 (#4213d2)
D 10 (#4aa983)
L 4 (#24f902)
D 8 (#3f1823)
L 6 (#4802f2)
D 8 (#253191)
L 3 (#19c2c2)
D 6 (#2818e1)
L 7 (#19c2c0)
D 16 (#3c7731)
R 7 (#2d6792)
D 6 (#4ef903)
R 4 (#336e42)
D 4 (#238ec3)
L 4 (#4ac572)
D 9 (#5427a3)
L 9 (#053882)
D 8 (#6bf101)
L 2 (#42c482)
D 16 (#044bf1)
L 3 (#1461c2)
U 12 (#0502c1)
L 8 (#74a2e2)
U 11 (#0502c3)
L 4 (#3e7212)
D 4 (#2bd771)
L 13 (#141c02)
D 5 (#6061d1)
L 3 (#5ca8e2)
D 8 (#04a951)
R 9 (#2b1342)
D 9 (#671121)
L 9 (#33afb2)
D 8 (#1eb701)
L 12 (#4db550)
U 7 (#609eb1)
R 8 (#4db552)
U 15 (#10ae91)
L 8 (#2b2572)
U 8 (#25c4f1)
L 8 (#605e82)
U 4 (#09af31)
L 9 (#4328a2)
U 9 (#09af33)
L 17 (#21d142)
U 2 (#11e5f1)
R 17 (#263f50)
U 9 (#152301)
R 7 (#18b880)
U 8 (#014a31)
R 5 (#42b160)
U 14 (#17c201)
R 7 (#5d7500)
D 7 (#17c203)
R 10 (#23e090)
D 10 (#014a33)
R 12 (#0a5140)
U 14 (#152303)
R 3 (#55f650)
U 3 (#1c1ec1)
R 9 (#3aec42)
U 6 (#03e4b1)
R 3 (#45b7a2)
U 10 (#5ce301)
L 10 (#223d12)
U 13 (#2330d1)
L 13 (#74b632)
U 9 (#411551)
L 7 (#22caa2)
D 5 (#429fb1)
L 6 (#28e492)
D 14 (#4b6a41)
L 5 (#60a302)
D 3 (#05e403)
L 3 (#70cdf2)
U 9 (#05e4a1)
L 3 (#004a12)
U 11 (#6ebca1)
L 9 (#2f5d62)
U 4 (#51e5e3)
L 9 (#33ef12)
U 13 (#22bb63)
L 9 (#400e42)
U 6 (#4e0bc3)
L 10 (#2efb82)
U 11 (#320cc3)
L 5 (#3f8372)
U 3 (#529693)
L 9 (#305d52)
U 3 (#356f73)
L 5 (#068d72)
U 7 (#7321f1)
R 5 (#46e4b2)
U 4 (#7321f3)
R 5 (#32a3a2)
D 11 (#4b2fe3)
R 5 (#20bd80)
U 11 (#65e3a3)
R 8 (#3b3e40)
U 6 (#139783)
L 15 (#7a1050)
U 9 (#139781)
L 8 (#3ad500)
U 11 (#1fc253)
L 3 (#0e10f0)
U 9 (#580d53)
L 4 (#195782)
U 8 (#170a13)
L 7 (#1cc302)
U 2 (#4641b1)
L 6 (#4ec5c2)
U 10 (#492003)
L 11 (#43f2e2)
U 3 (#754983)
L 5 (#47df02)
U 6 (#754981)
L 9 (#0b6ed2)
U 5 (#492001)
R 9 (#0fb482)
U 8 (#6c73c1)
R 5 (#2d8f52)
U 3 (#23de61)
L 8 (#325f00)
D 3 (#53e8e1)
L 6 (#325f02)
D 3 (#3715c1)
L 4 (#433092)
D 14 (#40d3b1)
R 10 (#681512)
D 3 (#57d843)
L 7 (#1af362)
D 4 (#107e23)
L 6 (#545a32)
D 12 (#4e9023)
L 6 (#0ff9f2)
D 8 (#4b29b3)
L 3 (#484e52)
D 8 (#0a1063)
L 15 (#32d802)
D 7 (#5003e3)
L 4 (#213d02)
D 11 (#190461)
L 2 (#357f92)
D 6 (#6b8611)
L 10 (#3990e0)
D 5 (#077dd1)
L 4 (#426220)
D 11 (#6536c1)
L 8 (#18d540)
U 11 (#034201)
L 8 (#5b3762)
D 3 (#0fa911)
L 3 (#3990e2)
U 6 (#21be11)
L 14 (#59c742)
U 6 (#384881)
L 4 (#4ebc42)
U 8 (#5ed321)
L 4 (#4ebc40)
U 12 (#1a8f21)
L 3 (#504172)
U 5 (#042cd3)
L 11 (#3913b2)
U 4 (#77f953)
R 14 (#328612)
U 9 (#0d33d3)
R 3 (#20be92)
U 3 (#377b23)
R 10 (#20be90)
U 10 (#439383)
R 4 (#156e80)
U 14 (#12bf53)
R 5 (#562b40)
U 10 (#220b93)
L 5 (#1c3732)
U 3 (#46b0d3)
R 9 (#03f4c2)
U 9 (#165873)
L 9 (#12b652)
U 6 (#4737a3)
L 6 (#3bae72)
U 2 (#4ca8b3)
L 11 (#422bc2)
D 7 (#4ca8b1)
R 4 (#090d02)
D 9 (#406043)
R 9 (#091222)
D 6 (#2fd4c3)
L 7 (#0e6352)
D 3 (#42d653)
L 6 (#4aa522)
D 13 (#287113)
L 7 (#145852)
U 5 (#4a75c1)
L 7 (#640962)
U 15 (#4a75c3)
R 7 (#506322)
U 10 (#482373)
L 11 (#75df22)
U 8 (#369ab3)
L 8 (#75df20)
U 11 (#390283)
R 7 (#52b932)
U 4 (#508653)
R 5 (#46bbc0)
U 11 (#56d983)
R 6 (#64efe0)
U 10 (#1482b3)
R 7 (#3d20d0)
D 6 (#1dad03)
R 4 (#5fb9f0)
D 7 (#490903)
L 4 (#2c0010)
D 12 (#662ae3)
R 3 (#30a052)
U 8 (#64f5f3)
R 15 (#30a050)
U 5 (#650093)
R 12 (#5a5bd2)
U 4 (#2b5033)
R 3 (#3a86c2)
D 7 (#5d1e83)
R 7 (#218372)
D 11 (#0bc483)
R 7 (#0dcaf2)
U 3 (#2d2f93)
L 4 (#653610)
U 11 (#422573)
R 4 (#653612)
U 4 (#479223)
R 3 (#0dcaf0)
D 8 (#202b53)
R 10 (#4f8ea0)
D 3 (#210eb3)
R 14 (#4f8ea2)
D 9 (#3c44b3)
R 12 (#458112)
U 9 (#12cf91)
R 8 (#413da2)
U 11 (#036641)
R 5 (#4e1fe0)
D 4 (#465131)
R 12 (#01c8c0)
U 4 (#2aa881)
R 10 (#4fe8a2)
U 3 (#341941)
R 6 (#55c252)
U 13 (#339dc3)
R 5 (#449340)
U 7 (#566e43)
R 3 (#449342)
U 10 (#313cc3)
L 10 (#1e28f2)
U 9 (#09d973)

14
18/input_test Normal file
View File

@@ -0,0 +1,14 @@
R 6 (#70c710)
D 5 (#0dc571)
L 2 (#5713f0)
D 2 (#d2c081)
R 2 (#59c680)
D 2 (#411b91)
L 5 (#8ceee2)
U 2 (#caa173)
L 1 (#1b58a2)
U 2 (#caa171)
R 2 (#7807d2)
U 3 (#a77fa3)
L 2 (#015232)
U 2 (#7a21e3)

65
18/main.s Normal file
View File

@@ -0,0 +1,65 @@
%include "utils64.s"
global _start
[bits 64]
[section .text]
%define FILENAME "input"
;%define FILENAME "input_test"
_start:
mov rsi, file
mov rbp, 11_000_000_000 ; vert
mov rdi, 1 ; area
proc_line:
cmp rsi, file.over
jae .done
mov al, '#'
mov rcx, 32
xchg rdi, rsi
repne scasb
xchg rdi, rsi
call hex_parse
mov rbx, rax
and bl, 3
shr rax, 4
inc rsi ; \n
; process shit
cmp bl, 0
je .r
cmp bl, 1
je .d
cmp bl, 2
je .l
cmp bl, 3
je .u
.r:
add rdi, rax
mul rbp
add rdi, rax
jmp proc_line
.l:
mul rbp
sub rdi, rax
jmp proc_line
.d:
add rdi, rax
sub rbp, rax
jmp proc_line
.u:
add rbp, rax
jmp proc_line
.done:
hlt:
hlt ; go get a debugger, answer in rdi
jmp hlt
[section .data]
final_value: dq 0
file: incbin FILENAME
.over:
[section .bss]
[section .rodata]

149
18/main_part1.s Normal file
View File

@@ -0,0 +1,149 @@
%include "utils.s"
global _start
[bits 32]
[section .text]
%define FILENAME "input"
;%define FILENAME "input_test"
;%define PRINT
_start:
mov esi, file
mov edi, array+1024*512+512 ; like, the middle idk
mov byte [edi], 1 ; filled!
proc_line:
cmp esi, file.over
jae .done
lodsb ; RDLU
%ifdef PRINT
call print_char
call space
%endif
mov ebx, eax
inc esi ; space
call dec_parse ; count
%ifdef PRINT
call print_dec
call newline
%endif
; skip to next line
add esi, 10
; put in array
cmp bl, 'R'
mov ecx, 1
cmove edx, ecx
cmp bl, 'L'
mov ecx, -1
cmove edx, ecx
cmp bl, 'D'
mov ecx, 1024
cmove edx, ecx
cmp bl, 'U'
mov ecx, -1024
cmove edx, ecx
mov ecx, eax
.draw:
add edi, edx
mov byte [edi], 1
loop .draw
jmp proc_line
.done:
%ifdef PRINT
print_array:
call newline
mov esi, array
xor ecx, ecx
.inner:
mov bl, '.'
lodsb
test al, al
mov dl, '#'
cmovnz bx, dx
mov al, bl
call print_char
inc ecx
cmp ecx, 1024*1024
jae .done
mov ebx, ecx
and ebx, 1023
jnz .inner
call newline
jmp .inner
.done:
call newline
%endif
xor ecx, ecx ; x = 0
xor ebx, ebx ; y = 0
mov ebp, 1024*1024 ; count
call flood_fill
jmp flood_done
flood_fill:
mov eax, ebx
shl eax, 10
cmp byte [array+eax+ecx], 0
je .zero
ret
.zero:
dec ebp
mov byte [array+eax+ecx], 1
sub esp, 8
mov [esp+4], ecx
mov [esp+0], ebx
.t_right:
cmp ecx, 1023
je .t_left
inc ecx
call flood_fill
mov ecx, [esp+4]
.t_left:
cmp ecx, 0
je .t_down
dec ecx
call flood_fill
mov ecx, [esp+4]
.t_down:
cmp ebx, 1023
je .t_up
inc ebx
call flood_fill
mov ebx, [esp+0]
.t_up:
cmp ebx, 0
je .ret
dec ebx
call flood_fill
mov ebx, [esp+0]
.ret:
add esp, 8
ret
flood_done:
mov [final_value], ebp
game_over:
mov eax, [final_value]
call print_dec
call newline
jmp exit
PANIC:
p_string panic_str
jmp exit
[section .data]
final_value: dd 0
file: incbin FILENAME
.over:
[section .bss]
array: resb 1024*1024
[section .rodata]
panic_str: db 10, "AAAAAAAAAAAAAAAAAAAAAA!!!!!!!!!!11111111", 10
.over:

285
18/utils.s Normal file
View File

@@ -0,0 +1,285 @@
[bits 32]
[section .text]
; call # val val2
; int $0x80 eax eax edx -
;
; arg1 arg2 arg3 arg4 arg5 arg6 arg7
; ebx ecx edx esi edi ebp -
exit:
mov eax, 1 ; exit
int 0x80
; filename in EBX
; return handle in EBX
; read only
open_file:
push eax
push ecx
mov eax, 5 ; open
xor ecx, ecx ; read only
int 0x80
mov ebx, eax
pop ecx
pop eax
ret
; file handle in EBX
; buffer in ECX
; count of bytes to read in EDX
; return bytes actually read in EAX
; exits on error
read_file:
mov eax, 3 ; read
int 0x80
test eax, eax
js .err
ret
.err:
mov eax, 4 ; write
mov ebx, 1 ; stdout
mov ecx, .err_str
mov edx, 21
int 0x80
jmp exit
.err_str: db `Could not read file.\n`
; string input in ESI
; value in EAX
; CF set if none, clear if some
; ESI set past checked area
dec_parse:
push ebx
push edx
push edi
xor eax, eax
xor edi, edi
mov ebx, 10 ; base
lodsb
sub al, '0'
js .no_input
cmp al, 9
jle .got_char
.no_input:
stc ; set CF
jmp .done
.loop:
xor eax,eax
lodsb
sub al, '0'
js .dec_done
cmp al, 9
jg .dec_done
.got_char:
xchg edi,eax
mul ebx
add edi,eax
jmp .loop
.dec_done:
clc ; clear CF
.done:
mov eax,edi
pop edi
pop edx
pop ebx
ret
; string input in ESI
; value in EAX
; CF set if none, clear if some
; ESI set past checked area
sign_dec_parse:
push ebx
push ecx
push edx
push edi
xor eax, eax
xor edi, edi
xor ecx, ecx ; neg flag
mov ebx, 10 ; base
cmp byte [esi], '-'
jne .no_minus
inc esi
mov cl, 1
.no_minus:
lodsb
sub al, '0'
js .no_input
cmp al, 9
jle .got_char
.no_input:
stc ; set CF
jmp .done
.loop:
xor eax,eax
lodsb
sub al, '0'
js .dec_done
cmp al, 9
jg .dec_done
.got_char:
xchg edi,eax
mul ebx
add edi,eax
jmp .loop
.dec_done:
test ecx, ecx
jz .not_neg
neg edi
.not_neg:
clc ; clear CF
.done:
mov eax,edi
pop edi
pop edx
pop ecx
pop ebx
ret
; modifies no regs
newline:
pushad
push 10
mov eax, 4 ; write
mov ebx, 1 ; stdout
mov ecx, esp ; string
mov edx, 1 ; length
int 0x80
add esp, 4
popad
ret
; modifies no regs
space:
pushad
push 9
mov eax, 4 ; write
mov ebx, 1 ; stdout
mov ecx, esp ; string
mov edx, 1 ; length
int 0x80
add esp, 4
popad
ret
; input in EAX, all regs unmodified
print_dec:
pushad ; save regs
; max 4294967296 is 10 chars
; round to nearest 32-bit boundary
sub esp, 12
; string in ECX, length in EDX
lea ecx, [esp+11] ; last possible byte
; check for 0
test eax, eax
jz .zero
mov ebx, 10 ; base 10
xor esi, esi ; counter
.div_shit:
xor edx, edx
; divide
div ebx
dec ecx ; next char
inc esi
; store
add dl, '0'
mov byte [ecx], dl
; check if done
test eax, eax
jnz .div_shit ; continue
mov edx, esi ; counter in edx
jmp .write
.zero:
mov byte [ecx], '0'
mov edx, 1 ; length
.write:
mov eax, 4 ; write
mov ebx, 1 ; stdout
int 0x80
add esp, 12 ; restore stack
popad ; restore regs
ret
; input in EAX, all regs unmodified
print_sign_dec:
pushad ; save regs
; range -2147483648 to 2147483647 is 11 chars
; round to nearest 32-bit boundary
sub esp, 12
; string in ECX, length in EDX
lea ecx, [esp+11] ; last possible byte
; check for 0, negative
xor ebp, ebp
test eax, eax
jz .zero
jns .positive
neg eax
mov ebp, 1
.positive:
mov ebx, 10 ; base 10
xor esi, esi ; counter
.div_shit:
xor edx, edx
; divide
div ebx
dec ecx ; next char
inc esi
; store
add dl, '0'
mov byte [ecx], dl
; check if done
test eax, eax
jnz .div_shit ; continue
mov edx, esi ; counter in edx
jmp .write
.zero:
mov byte [ecx], '0'
mov edx, 1 ; length
.write:
test ebp, ebp
jz .no_minus
dec ecx
inc edx
mov byte [ecx], '-'
.no_minus:
mov eax, 4 ; write
mov ebx, 1 ; stdout
int 0x80
add esp, 12 ; restore stack
popad ; restore regs
ret
; input in ESI, len in ECX, all regs unmodified
print_string:
pushad ; save regs
mov eax, 4 ; write
mov ebx, 1 ; stdout
mov edx, ecx ; length
mov ecx, esi ; string
int 0x80
popad ; restore regs
ret
; input in AL, all regs unmodified
print_char:
pushad ; save regs
push eax
mov eax, 4 ; write
mov ebx, 1 ; stdout
mov edx, 1 ; length
mov ecx, esp ; string
int 0x80
add esp, 4
popad ; restore regs
ret
; --- MACROS ---
%define len(x) x %+ .over - x
%macro p_string 1
push esi
push ecx
mov esi, %1
mov ecx, len(%1)
call print_string
pop ecx
pop esi
%endmacro

117
18/utils64.s Normal file
View File

@@ -0,0 +1,117 @@
[bits 64]
[section .text]
; string input in RSI
; value in RAX
; CF set if none, clear if some
; RSI set past checked area
dec_parse:
sub rsp, 24
mov [rsp+16], rbx
mov [rsp+8], rdx
mov [rsp+0], rdi
xor rax, rax
xor rdi, rdi
mov rbx, 10 ; base
lodsb
sub al, '0'
js .no_input
cmp al, 9
jle .got_char
.no_input:
stc ; set CF
jmp .done
.loop:
xor rax,rax
lodsb
sub al, '0'
js .dec_done
cmp al, 9
jg .dec_done
.got_char:
xchg rdi,rax
mul rbx
add rdi,rax
jmp .loop
.dec_done:
clc ; clear CF
.done:
mov rax, rdi
mov rdi, [rsp+0]
mov rdx, [rsp+8]
mov rbx, [rsp+16]
add rsp, 24
ret
; string input in RSI
; value in RAX
; CF set if none, cear if some
; RSI set past checked area
hex_parse:
sub rsp, 24
mov [rsp+16], rbx
mov [rsp+8], rdx
mov [rsp+0], rdi
xor rax, rax
xor rdi, rdi
lodsb
cmp al, '0'
jb .no_input
cmp al, '9'
jbe .got_dec_char
cmp al, 'A'
jb .no_input
cmp al, 'F'
jbe .got_ualpha_char
cmp al, 'a'
jb .no_input
cmp al, 'f'
jbe .got_ualpha_char
.no_input:
stc ; set CF
jmp .done
.loop:
xor rax,rax
lodsb
cmp al, '0'
jb .hex_done
cmp al, '9'
jbe .got_dec_char
cmp al, 'A'
jb .hex_done
cmp al, 'F'
jbe .got_ualpha_char
cmp al, 'a'
jb .hex_done
cmp al, 'f'
jbe .got_ualpha_char
jmp .hex_done
.got_dec_char:
sub al, '0'
xchg rdi,rax
shl rax, 4
add rdi,rax
jmp .loop
.got_alpha_char:
sub al, 'A'-10
xchg rdi,rax
shl rax, 4
add rdi,rax
jmp .loop
.got_ualpha_char:
sub al, 'a'-10
xchg rdi,rax
shl rax, 4
add rdi,rax
jmp .loop
.hex_done:
clc ; clear CF
.done:
mov rax, rdi
mov rdi, [rsp+0]
mov rdx, [rsp+8]
mov rbx, [rsp+16]
add rsp, 24
ret
; --- MACROS ---
%define len(x) x %+ .over - x

3
19/Makefile Normal file
View File

@@ -0,0 +1,3 @@
all:
nasm -g -felf32 main.s && ld -melf_i386 -g main.o

780
19/input Normal file
View File

@@ -0,0 +1,780 @@
fr{a>2845:A,m<2004:A,A}
lxs{s<2192:R,R}
jhz{x<442:A,A}
zm{x<1231:R,A}
jz{s<2913:A,x<2108:R,R}
cqv{a>2101:R,A}
hsx{m<1426:xxn,s<1619:sq,qqb}
sdm{x>1360:A,A}
zbb{a>3503:R,s>2984:R,A}
skk{x>1878:A,s>1548:R,R}
mn{x>576:R,x<195:A,s<303:R,A}
hbj{a>728:hqq,ggl}
lq{x>1539:A,m>950:A,m>611:A,R}
gx{a>3590:zmc,tg}
xpr{a<3371:R,s<3114:A,R}
nf{m>2252:A,m<1915:A,x<1541:A,R}
mfl{m<1608:vk,m>2471:mp,x<1842:A,A}
md{x<1958:A,A}
bt{s>2495:R,x<2051:R,a<3362:R,R}
zp{m>1849:R,m>1720:A,s<2907:A,R}
kp{x>2295:R,x>2106:R,A}
dm{a>3142:rk,x<996:kc,m>2686:lxc,svc}
cq{a<1392:xkx,s>2114:czc,R}
xlc{m>3640:xh,s<1981:ck,x<1275:R,tv}
qhp{a>2255:R,m<2909:A,R}
zz{x>158:A,A}
bmg{s>3584:A,R}
tp{m>1848:vrs,mds}
mds{a<3473:A,a>3501:A,s<3009:A,R}
kdm{s<3771:zx,vq}
xxn{a>1741:fq,m<899:bkf,vm}
lbm{m>3455:A,R}
bq{x>2598:R,A}
vlr{m>1824:rsn,a<3330:mr,x<1229:ch,gfp}
rfd{x<1380:vxx,m>2215:A,jbz}
fnp{s<2124:bh,a<1450:A,A}
pvh{s>1623:A,x<3503:A,s<1454:R,R}
dhh{s>1900:A,R}
cv{m>2619:gvq,zbb}
gz{a<2237:R,A}
hrf{a>1467:shg,A}
kqp{m>2434:qst,x>1969:kgz,gr}
xlg{s<1949:tj,x<1948:czj,R}
xf{s<2587:A,m>2612:R,a>381:A,R}
fdj{a>3545:A,a<3532:R,s<2736:R,R}
shn{m>2612:R,m<1284:jlp,A}
xx{a>3575:jzf,a<3518:A,s>2638:fdj,A}
sd{a<3248:R,m<3422:js,s>1555:A,lz}
vd{s>1745:txb,fs}
hm{a>1763:pg,s<3711:dvf,xpp}
xhj{a<1056:A,m>3355:A,ntz}
td{x>705:A,R}
znz{a>3929:xg,fcf}
kk{s>2920:A,m>3806:R,ng}
mx{m>987:R,m<500:A,A}
rk{s<2159:ph,s<2256:dxp,m<2823:jq,km}
lb{a>2647:A,s<1457:A,x>3452:R,R}
svc{s<2017:kgt,xff}
nk{x>1466:A,s<2004:lxg,s>2073:sgd,mnx}
cn{x<3437:R,R}
shg{m<2072:R,R}
xbh{s>1178:R,R}
czj{m>873:R,x>1527:R,x>1352:R,A}
dj{s<3859:nsk,x<3298:ktl,a>730:ll,bx}
lzq{m<3709:A,a>758:R,a<697:R,R}
xjn{a>2302:A,m>2041:A,s>3482:R,A}
zcb{a<276:R,m<2219:R,s>2027:A,A}
hmn{x<2560:A,m<2069:R,x>3240:R,A}
dxp{x<1615:R,a<3653:A,R}
thv{m>1443:fnp,dnc}
bpq{a>2566:R,s>2238:ndq,a>2202:R,A}
xkv{s<1708:R,s<1764:A,m<2486:A,A}
xrs{s>2780:vn,hvh}
tkq{s<3890:R,s>3905:A,s<3900:R,A}
cxv{m>3326:zl,x<1480:mz,x<2829:rv,lt}
kzn{m<2943:A,x<3690:A,R}
gd{s>1936:A,x>3201:R,m>3130:A,R}
qqb{x>858:rf,x<392:vd,mh}
mmb{s>1505:vl,m>2260:zzn,jd}
zlb{m<2754:A,m>2824:R,R}
gf{s>2007:zhl,x>742:mzn,a<2531:nm,R}
th{s<3579:A,A}
nsk{s<3700:A,crp}
jc{x>770:A,A}
ln{x>970:xzr,s>3048:ccr,lfn}
lnf{m<2433:ds,m>3234:lzq,gkn}
crp{s>3759:A,x<3534:A,A}
thj{s<2817:R,R}
rpn{m<463:R,s>1546:R,s>1448:A,R}
lf{a<3216:R,x<1505:gkh,s>1758:R,bxz}
jg{m>552:vxm,a<3207:nq,fz}
rsn{a>3358:R,gzj}
nn{x>2059:qq,a>159:dhl,gfc}
skv{s<1728:A,a<1776:A,x<555:R,R}
ktv{s>3176:R,s>3065:A,A}
zq{m>3113:A,x<3424:A,R}
tqv{x>3879:A,x>3815:A,A}
vp{a<1366:lgh,m>1586:nl,jpj}
cz{x>1163:R,A}
dxn{m>3105:R,m<2018:skv,x<548:R,xkv}
xtn{a>3160:rd,s>2740:tl,xj}
dv{a<3922:bv,s<2651:rl,R}
glg{s>3870:R,m>3122:R,R}
mls{a>2798:R,x>2352:A,R}
ztq{a<2008:jhc,m>862:tbl,A}
rqk{a>1311:R,R}
nlx{a<2137:A,s>2037:nnf,a<2838:R,vkh}
jvd{s>1469:A,m<3294:zm,s<1435:R,mcb}
dmf{m<3734:A,A}
zl{m<3721:zf,A}
hvh{x<1599:fcp,a>256:xth,x<2400:nn,bpx}
sf{x>1556:ztq,mzl}
lcq{m>635:mjp,s>2859:A,m>413:R,hbt}
xn{m>2426:jvd,x<858:pfz,mfv}
zgf{a>1378:R,m<1291:ptd,R}
qhv{m>1852:A,m>1719:R,s<3007:R,A}
ph{a<3497:vv,R}
mps{s<2806:zps,kbd}
bz{s>2864:R,A}
ll{s<3917:tkq,x<3703:R,R}
tbl{m<1295:A,A}
tm{s<3029:sl,a>3664:dg,a>3563:crg,dcm}
xxr{x<2995:A,s>1322:R,a>3132:A,A}
kgz{x>2235:R,A}
pfz{x<300:A,R}
pb{m>3682:lpv,A}
ps{m>2481:xvp,x>3501:thv,bk}
dvf{s>3547:shn,hc}
gkh{s>1768:A,s<1736:A,A}
kbd{x>827:A,A}
zhj{s<2126:xlc,a<734:pb,x>1387:qcz,rn}
xg{a<3969:A,m<2656:A,R}
sm{s>2585:A,R}
zhl{a<2775:R,m<712:A,A}
df{x<2518:R,A}
lfn{s<2787:mfc,m<3120:A,bmf}
sdx{m>2324:R,A}
qcz{a>1412:gxd,R}
tq{m>1287:A,m<798:A,s>3148:R,R}
gq{a<2067:R,a>2180:gz,m<2530:R,lbm}
lmv{m>1460:A,A}
jqz{x>800:A,m<2431:R,a<1059:A,A}
hzl{m<3210:A,R}
fqd{s<3517:A,dd}
xpp{m<1921:kfl,x>716:kv,x>273:ntk,vmd}
st{a>2725:R,A}
pd{m<3138:A,x<3799:R,A}
cx{m<2622:cn,x>3616:A,m<3404:zq,dcs}
vkh{s>1912:R,x>2874:R,R}
dpm{a>2728:fr,a<2543:qzb,m>2249:vs,fhh}
zjn{m<1731:R,s>1599:A,A}
dg{s<3279:A,m<899:R,a<3806:lrq,R}
qj{a<2324:A,R}
bm{a<2544:A,m<973:A,m<1233:R,R}
dmm{x>420:R,a<3938:A,m<1567:A,A}
nxd{m>1378:gkl,gps}
fcf{a<3859:R,s>3094:R,A}
km{m<3292:db,s>2311:nlh,x>949:nkt,R}
fz{m>224:A,s>427:A,s>193:R,R}
jgn{x>3689:tqv,a>3896:rhx,ktq}
jcz{m<964:fcc,lmv}
dqt{x>1042:R,A}
xs{x>2301:np,m>2490:A,A}
dnc{a>2667:ltx,R}
pm{m>1660:R,R}
xkx{x<1469:A,s<2105:A,A}
zqk{s>2813:zs,m>2905:xx,a<3613:dzc,cms}
qh{m>2483:R,a<1940:R,A}
nm{a>2194:A,R}
dhl{a>214:R,R}
kr{x>2730:A,A}
nzs{a<3692:R,R}
hc{s<3500:R,jqz}
mt{s<1112:dgs,cs}
jnc{x>2611:A,x>2231:R,R}
txn{x>2227:A,s<2060:R,R}
tvz{a<2131:A,m<3205:R,m<3641:R,A}
bsh{a<439:R,a<528:R,s>2648:A,A}
hb{m<340:pmp,x>1343:smn,R}
gxh{m<1015:A,x<1686:A,x<2151:R,R}
xxf{x>3458:A,x>3396:R,A}
ks{s<3753:A,s<3790:R,a<1055:A,A}
bdb{m>1085:kql,qk}
gkn{s<3173:A,R}
qq{m<1365:R,s>2565:A,m<2907:R,A}
dzc{m<2655:vng,zlb}
hdq{s<878:R,A}
vxm{s>304:A,a>3262:R,a>2961:R,R}
jfr{a<3476:qt,m<2328:tm,a<3734:zqk,nhh}
zzx{m>3167:R,a>2911:R,s>1986:R,R}
cj{s<2777:mkt,m<1946:R,x<2175:A,R}
nlh{m<3735:A,x<878:R,a>3519:R,R}
bs{s<2559:R,s<2678:A,R}
jzx{a<2939:A,A}
mhd{a>3461:lbp,x>1754:dn,R}
bf{x<1514:A,R}
qzg{m>765:R,x<1881:A,m<429:A,A}
tzj{m<3544:A,A}
lt{a>3048:R,s<241:ht,s>399:dk,R}
sjv{s<303:A,A}
gv{x>1712:A,x>1145:R,A}
hx{x>2863:A,A}
bbv{x<3854:xjn,a>2553:A,R}
rd{m>1904:A,a>3229:rb,a>3201:zbq,qzx}
xdc{s<3559:qkk,x<2257:A,R}
jpj{a<2122:pxj,m<815:R,R}
hpx{x<3160:A,R}
vkp{m<3498:vc,kk}
vq{s>3849:A,R}
kc{a<2487:lxs,s>2074:ffm,zzx}
nhj{s<1677:R,x<754:A,kkh}
jmv{s>3095:R,m>2659:A,A}
ngp{x>318:A,R}
rn{m>3717:mv,ld}
rr{x>2077:lcs,a<2564:vp,x<1783:kdm,xd}
vv{m<2492:A,R}
jgs{x<1311:td,x>1970:fkr,lkd}
zbq{x>1251:A,x>741:R,a<3214:R,A}
vr{s>1490:fkj,s>1418:R,a<3021:rdh,A}
js{m>3168:R,m>3015:A,A}
mh{x<676:dxn,s>1709:jzc,nhj}
rv{a>3103:sjv,s<282:kvc,vns}
sg{x>1921:rqz,m<1545:xt,fdx}
bdv{s>3015:A,x>563:R,a<2129:R,A}
kb{a<2399:dnv,a<3059:mmb,m<1918:mrc,gx}
ht{a<2799:A,x>3399:A,A}
vrs{a<3462:A,A}
ch{s<2743:R,m>1149:tfz,m<558:xpr,A}
lrq{x<3098:R,s<3332:R,R}
mzn{s<1938:R,R}
jq{m>2374:A,x<1425:A,R}
nhh{x<3487:gnz,s>3018:jgn,tk}
kqv{a>1168:R,R}
mfv{a>1367:R,a>767:gv,njr}
tn{x<1082:R,s<1473:A,A}
cl{a<2428:cqv,skk}
smn{m<704:R,s>1557:R,A}
vs{s<2752:jtg,A}
ndp{m>1613:R,a>1668:tqk,a>756:A,rtk}
mm{x<2841:A,x>2991:R,R}
gfc{s<2651:A,a>87:A,R}
fc{s<3768:A,x>2927:A,s>3872:R,A}
qd{s<1986:A,a<562:A,R}
vtv{x<2948:cj,s<2996:gq,mfk}
pc{m<2563:R,s>308:R,A}
db{x>1182:R,s>2330:A,R}
lj{a>1208:A,sn}
vxv{s<3093:R,R}
pkk{s<3012:A,m>2572:A,a>3749:R,R}
phs{s<3862:R,m<1390:R,kcm}
xt{m<784:R,s<3171:R,R}
gkl{x>556:A,R}
gvq{a<3510:A,m>3254:A,A}
qx{s<248:jjm,kp}
jjm{x<2448:A,m>2222:A,R}
kt{s>1768:ps,kb}
std{a>1196:R,a>1080:R,a>1034:R,R}
lhp{m<2508:xtc,x>1732:vkp,a>1157:ln,xq}
pxj{m>793:R,a>1699:R,A}
bpf{s<2850:A,A}
fkr{x>2275:A,m<2337:A,x<2147:zls,A}
mv{m>3870:A,m>3778:A,R}
zh{m<1090:rmv,zt}
pj{s>2079:R,gd}
tl{a<3073:A,m>2621:A,lq}
mcb{x>890:A,s<1455:A,R}
nqk{a<2608:A,m<3138:mls,bgh}
sr{m<2392:R,m>2540:A,s<1933:R,A}
jzc{a<2239:ptk,a<3339:A,a>3605:A,zcf}
tfz{x<779:A,a<3380:A,m<1541:A,R}
pvj{x<2020:R,x>2348:A,R}
bv{a<3884:R,x>825:A,A}
hcf{a<3816:jgs,s<2909:rbd,x>1198:sg,nvv}
nl{a>1904:tzv,R}
rl{s>2541:A,m>2863:R,m>2346:A,R}
bg{x>524:R,m>927:R,a>2391:R,R}
xsp{m>2367:zg,a>3232:zp,x>2987:qhv,A}
nv{m>1136:jr,x<974:mn,s<299:qg,bf}
dnv{x<3133:xz,s>1612:cx,fxp}
tv{s<2030:A,A}
bvx{x>3807:A,m<1978:A,a<829:R,kzn}
fg{x>1393:A,s<1322:A,m>3693:A,A}
vn{x>1743:bmx,s>3133:pjc,x>797:rfd,dtf}
sn{a<720:R,m>2407:A,s>2263:R,R}
dn{a>3435:A,A}
pxn{s<3897:A,a<3216:A,R}
bkf{a>800:rzg,hb}
bpx{a<141:A,jhh}
zls{x>2037:R,m>2919:R,A}
xzr{a>1432:A,m>3471:A,m>2878:rqk,R}
png{s<3217:R,A}
lzp{s>2935:lnf,hbj}
fxs{m<2298:A,m>3023:R,A}
rds{x<2136:jcz,gxf}
mc{s>3407:jb,a>1580:tks,dhr}
lh{m<777:A,s>959:A,R}
fq{a>3243:zzg,x<1126:rht,m<680:cl,cpk}
cgs{m<3539:R,R}
dtf{x<432:A,m<2598:zb,A}
sgd{m<377:R,a<1360:A,s>2105:A,A}
fxp{s<1476:A,a>1446:R,A}
cgv{s>2832:A,a>3725:R,a<3721:R,R}
rb{x>1583:R,A}
sxb{s<2865:mhd,a<3463:tgc,s>3096:ngz,cv}
flz{a<3242:A,A}
hf{s<1198:A,m<1745:A,R}
xff{a<2470:R,a<2902:R,brk}
pq{m<1019:R,a<3493:xbh,tcn}
qxh{s<3830:jx,a<3002:xcg,a<3523:pxn,dqt}
ccr{a>1369:A,x<540:ngp,R}
lx{a>3856:R,A}
gls{s>2827:R,x>1450:A,m>760:R,R}
fs{m>2698:hd,m<1866:A,R}
qt{m>1524:xsp,a>3264:bz,x<2990:lcq,ddp}
zsb{s<1967:R,x>1869:txn,s>2038:R,nf}
xz{a>1278:A,A}
brk{s<2250:R,A}
xcg{a>2310:A,x>589:A,m<1935:A,A}
gxd{a>1760:R,x<1932:R,R}
vt{s>2550:R,std}
mjp{a>3129:R,x>2733:R,s<2923:A,R}
zzg{m>522:zrf,x<1493:R,x>2078:ff,A}
fkj{x>1280:R,m>2156:R,A}
jhc{m>746:R,a>1003:A,R}
lz{x<2241:A,x>2443:R,A}
cb{s<3619:cfc,a>1549:mdc,dj}
qm{s<3512:zc,R}
cpk{s<1607:bm,A}
fhh{a>2658:jz,s<2865:R,s>3109:A,R}
tgc{m>1755:A,s<3212:qzg,cp}
cgm{s<2172:pfs,m>3075:R,A}
jgf{a>1369:R,a>1337:A,s>2964:R,R}
cms{m<2570:A,m<2752:vg,m<2837:R,nzs}
jx{x>548:R,m<2561:R,x<242:A,R}
mrc{x<3340:hx,m<1213:rpn,hvc}
mnx{x>791:A,A}
qzx{x>1193:A,R}
mdc{x<3104:jdd,x<3684:hjb,phs}
cf{m<2776:vr,x<1619:fnq,s<1471:dnf,sd}
ds{a<815:A,tq}
vmd{s>3862:bj,qb}
mfc{m>3159:R,s>2590:A,s<2498:A,A}
jrk{m<3157:sp,zhj}
vng{m>2487:R,a<3537:A,R}
pjc{s<3295:R,x>730:cz,R}
pp{m>1152:R,a>708:R,A}
lkd{a<3716:A,a>3760:bcs,a>3739:pkk,cgv}
tks{a<2969:pxf,x>2465:jfr,a<3555:gp,hcf}
mp{x>1865:A,R}
jbz{a<220:A,A}
ltx{x<3669:A,m<611:R,R}
fb{x>527:R,m<1341:A,a<2542:R,th}
gzj{a<3308:A,R}
kbg{a<2673:A,x>3099:A,R}
rtk{x<1207:R,s<322:R,m>673:R,A}
jd{s<1420:kbg,sxd}
bxz{m<2876:R,R}
dfs{a<3210:A,x>3369:R,x<3277:A,A}
np{a>2152:R,A}
hbt{x<2680:R,a<3145:R,R}
tx{a>3904:R,m>746:A,a>3848:R,R}
fdx{x<1567:vxv,a<3936:ktv,jmv}
mjv{m<2079:A,a>2843:A,x>3591:A,qhp}
zps{m>3233:A,m<2936:R,A}
vm{s<1569:tn,bdb}
pch{m<1670:sms,a>1946:dm,jrk}
br{x>3300:zxx,R}
zf{s>242:A,R}
ntk{s<3864:R,jhz}
hs{s>2686:gls,x>1247:A,tx}
xth{m<1407:bsh,a>466:hpx,xf}
kv{m>2674:kqv,m<2325:A,x<1277:rzt,lhz}
hfh{s<3895:A,A}
lxc{x<1519:jjt,s<2121:zn,x<2064:bpq,nqk}
xvp{a<1815:pj,cgm}
rbd{m<1497:hs,dv}
pdn{a<3048:st,s>1293:mj,s<1267:A,R}
pxt{m<1410:R,dx}
lg{s>413:A,s<242:A,a<1899:A,R}
bgh{s>2275:A,R}
gr{x<1477:R,R}
bj{a>787:R,m<3108:A,s<3930:A,R}
zs{m<3026:dfv,x>3208:R,s<3193:gt,R}
vg{x<3353:R,s<2614:R,x<3633:R,R}
lpv{s>2284:A,m<3804:A,s<2215:A,R}
frf{a<1568:R,pf}
lhz{x>1406:A,s>3831:R,m>2485:A,R}
kfl{s>3825:hfh,x<675:ks,x>1039:A,pp}
bmf{a<1331:A,R}
sms{s>2156:sf,a>1737:rpb,a>748:lcp,zh}
qb{s>3774:R,s<3744:A,s>3763:R,R}
ggl{a>648:R,a>619:A,pm}
pn{a>2902:A,s<1543:R,A}
fkp{a>782:R,zcb}
kgt{a<2588:pvj,m<2228:A,sr}
fh{m<3554:R,A}
ktl{s<3936:A,A}
pxf{a>2341:dpm,x>1629:vtv,nxd}
zb{m>1090:R,x<661:A,s<2926:A,A}
bk{m>1591:hrf,m>843:frf,x<3052:nlx,br}
xv{s<419:A,x<508:R,R}
ngz{s>3296:fvk,A}
jp{x<1768:R,m<1125:R,a<3381:R,R}
rzh{s>2837:R,m>1393:A,A}
dcs{a>1227:A,x<3362:R,R}
fcc{m>419:A,m>228:A,A}
ddp{a>3072:A,R}
chk{x>988:R,lrb}
bcs{a<3795:A,R}
nq{x<2015:R,s>362:R,m<203:A,R}
jhh{a<214:A,A}
crg{a>3600:A,x>3090:sj,x<2861:R,R}
gt{m>3484:A,R}
jr{s>251:A,x<711:A,R}
sp{s>2177:lj,x<890:fkp,a<1241:hgz,zsb}
ntz{s>2967:R,x>686:R,A}
lk{x<1915:ndp,x>2905:rks,a>1647:fd,qx}
mr{a<3298:A,a<3316:kls,crs}
dfv{a<3566:A,x>3241:A,a>3665:A,R}
ncf{a>1373:R,a>908:R,R}
dd{m>2969:A,s>3581:R,R}
vxx{a<251:R,A}
hgz{s>1957:kh,a<472:sdx,m<2611:A,R}
jdd{a<2697:fc,m<1777:A,glg}
xq{a>1074:chk,a<1022:mps,xhj}
ts{x>3265:A,m<3294:R,A}
zc{s>3447:A,s>3429:R,m<2140:A,R}
bx{x<3604:xxf,a<484:fxs,R}
hjb{s>3819:A,x<3453:R,x<3591:kz,A}
njr{x>1531:A,s<1460:R,R}
lhx{a<2491:mt,m>1715:dl,s<1110:rds,sz}
jlp{m>455:R,s<3610:R,R}
rhx{m<2943:A,R}
ptn{a<2505:lk,m<2031:lbz,cxv}
ndq{s<2335:R,R}
ng{s>2739:A,x>3185:A,R}
lbp{s<2669:R,m<1543:R,x>1794:R,R}
zxx{m>350:A,s>2187:A,x<3431:A,R}
hqq{a<808:A,s>2584:ms,A}
czc{x<1439:R,R}
pf{s>2070:A,a>2463:R,m<1154:R,A}
mfk{a<1948:R,png}
vns{m<2846:R,s>422:R,A}
jmk{x<2178:A,a>3930:R,A}
ss{s>1952:R,x>1315:A,A}
bc{x<1955:A,a>119:R,m<1469:A,R}
kvc{a>2746:R,a>2606:A,R}
ptd{x<1467:A,x<2037:A,A}
svb{s>1963:md,dhh}
zmc{s>1542:lx,m<3249:R,a>3822:R,dmf}
dcm{x>3146:sv,x>2890:R,bsv}
dnf{m<3282:R,s>1413:A,fh}
qg{m<1048:R,s>179:A,R}
tf{x>2891:A,A}
pg{s>3693:qxh,m<2372:fb,fqd}
sxd{x>3164:R,A}
lgh{m>2281:R,A}
fnq{s<1485:A,a<3295:pn,A}
jb{x<1564:hm,x>2605:cb,rr}
sz{s<1235:pq,m>756:lnz,pdn}
zt{x<1498:R,a>306:qd,a<198:bc,A}
fvk{a<3520:A,R}
mfn{x<2646:A,A}
gfp{s>2804:jp,s<2578:bt,A}
jmb{a<3416:R,R}
tzv{a<2166:R,m<2437:A,R}
vc{a<1314:R,a<1410:jgf,a>1491:A,A}
vk{m<995:A,m<1328:R,R}
pt{m>1440:R,x>1184:A,m<1238:A,A}
txb{s>1786:zz,x<172:R,s<1766:A,qh}
llc{s>1503:R,s>1417:A,x>2946:R,R}
tj{x>1826:A,a>2662:A,A}
xh{s<1993:R,a>1164:R,R}
jzf{x>3174:A,x<2760:A,A}
zn{a<2350:tvz,x<2058:bb,A}
pfs{x<3298:R,s>1993:R,R}
pmp{a<531:A,R}
xtc{x<1755:lcn,s>2778:jnc,vt}
kql{s>1670:A,R}
ktq{s<3229:A,s<3320:A,m<3284:A,A}
zcf{a>3429:R,m<2504:A,R}
kz{m>1758:A,A}
gps{a>1924:bdv,s<2811:bs,R}
ms{a<887:R,A}
sh{m>1213:A,m<628:R,a<278:A,A}
jtg{a<2615:A,x<1428:R,A}
qkk{s<3538:R,A}
sj{a>3576:A,s>3252:R,x>3403:A,R}
lnz{x>2017:flz,a>3320:R,a<3030:R,R}
svk{s<1269:A,x<2459:fg,x>3335:R,xxr}
dk{x>3445:A,m>2894:A,a>2714:R,A}
ck{a>820:R,s<1878:R,A}
mzl{m<1102:qj,x<626:rcn,s<2282:A,pt}
cm{m>2496:R,A}
in{s<2403:pxm,mc}
mgr{x>1261:A,s<2247:A,s>2332:R,R}
rpb{x<1235:gf,a>3150:svb,xlg}
rzt{s<3861:R,R}
fcp{a<391:sm,x>658:R,x<235:A,R}
mz{a>3217:R,x<568:pc,a<2806:R,R}
gnz{m>3220:R,x>3030:bpf,m>2804:R,kr}
lcn{a<1364:bfc,x>713:mx,R}
ld{a>1185:R,A}
tk{x<3736:hzl,a>3880:R,x<3854:pd,A}
qst{s<1649:R,x>1581:A,s>1662:R,A}
zzn{s>1422:lb,a>2822:ts,A}
sq{a>2419:cf,xn}
dl{s<1027:hdq,m<3118:jmb,s>1207:svk,cgs}
dgs{s>933:R,a>1219:hmn,R}
tcn{m<1316:R,A}
dx{m<2691:R,R}
mj{a>3607:R,a<3295:R,R}
cp{x>1744:R,R}
gp{a<3265:xtn,a<3409:vlr,x<874:vj,sxb}
ffm{m<2925:A,tzj}
sv{x<3623:R,x<3865:A,x>3953:A,A}
vjh{s<696:ptn,lhx}
kh{m<2223:A,x>1640:A,R}
sl{x>3116:R,m<1100:A,m<1681:mm,tf}
jv{x>3205:R,A}
rf{a<2331:tzd,s<1687:kqp,lf}
zg{m>3278:A,m<2822:R,x>3249:R,R}
nkt{m<3763:R,a<3625:R,a>3767:R,R}
lcp{m<816:nk,s<2030:zgf,cq}
hvc{x<3758:pvh,m<1480:A,s<1575:R,A}
rks{x<3595:R,m<2372:A,A}
lrb{x<621:A,x<843:A,x>898:A,A}
zx{m>2405:A,x>1653:R,bmg}
nnf{m>536:A,A}
bfc{x<991:A,R}
hd{a>2374:R,R}
zrf{x<1430:R,A}
qk{m<1019:R,x<994:R,m<1047:R,A}
bsv{s<3158:R,x<2672:R,a>3513:R,A}
ff{x<2379:A,A}
pxm{s<1369:vjh,x>2564:kt,s>1811:pch,hsx}
gxf{a>3398:A,x<3277:bq,lh}
kls{m<1031:A,s>2876:R,s>2644:A,R}
qqh{x<3795:A,R}
nvv{s<3241:znz,bnl}
cqk{s<3859:R,ncf}
jjt{s<2037:ss,mgr}
qzb{s>2804:R,df}
rht{s>1650:R,bg}
rmv{a<459:A,m>488:A,A}
bmx{m>1850:A,sh}
ptk{m>2955:R,R}
tg{x<3192:llc,a>3346:R,x<3633:dfs,qqh}
bnl{s>3326:dmm,m>2318:jc,a<3895:R,R}
cfc{x<3480:qm,a<1363:bvx,x<3745:mjv,bbv}
xlp{x>460:A,m<2590:rzh,R}
bb{s<1924:R,A}
shq{x>1246:A,a>3207:tpb,x<826:xv,jzx}
lp{s>1698:R,a<1429:R,R}
kkh{a<1643:A,A}
rzg{s<1629:sdm,a>1245:lp,a>1083:R,A}
xgv{x<2900:R,xb}
bh{m>2126:R,s<1916:A,x>3791:A,A}
cs{s>1272:mfn,a<1174:hf,R}
lbz{m<921:jg,x>2079:xgv,m<1295:nv,shq}
lxg{x<826:R,A}
rdh{x>982:R,A}
kcm{x>3875:A,m>2918:A,m>2407:A,R}
rqz{a<3893:A,m>1449:jmk,x>2106:A,A}
vl{x>3363:zjn,x>3065:jv,A}
tt{x>1484:R,m>2484:A,a<1512:A,A}
dhr{a<597:xrs,a>941:lhp,lzp}
crs{a>3323:R,m>1119:A,x>1452:R,A}
rcn{m>1445:R,x>347:A,a>1485:A,R}
tzd{x<1859:tt,A}
lcs{s>3607:cqk,s<3524:xs,xdc}
tqk{x>1006:R,a<2151:A,A}
tpb{a>3497:R,A}
xj{a<3083:A,m>1619:R,x<1091:A,gxh}
xd{x>1933:pxt,mfl}
fd{x<2466:cm,a>2195:R,x<2715:lg,R}
xb{m<1347:A,A}
mkt{x>2312:A,R}
vj{x<379:tp,x>561:thj,xlp}
{x=380,m=329,a=917,s=255}
{x=486,m=681,a=11,s=452}
{x=893,m=376,a=51,s=1662}
{x=1223,m=1194,a=1038,s=92}
{x=267,m=299,a=9,s=2591}
{x=65,m=557,a=1437,s=1063}
{x=1147,m=46,a=258,s=1255}
{x=198,m=1186,a=151,s=291}
{x=2758,m=1247,a=177,s=616}
{x=470,m=1001,a=876,s=79}
{x=704,m=2422,a=1273,s=2345}
{x=927,m=2901,a=95,s=2889}
{x=1241,m=221,a=1151,s=444}
{x=1604,m=1310,a=58,s=160}
{x=229,m=438,a=548,s=733}
{x=1024,m=946,a=406,s=1582}
{x=1083,m=277,a=1599,s=1926}
{x=472,m=612,a=638,s=925}
{x=1344,m=833,a=276,s=2381}
{x=6,m=2045,a=1033,s=3120}
{x=1204,m=699,a=1281,s=310}
{x=262,m=689,a=314,s=2847}
{x=526,m=107,a=1469,s=1423}
{x=475,m=723,a=485,s=1011}
{x=114,m=1049,a=2058,s=885}
{x=254,m=1238,a=401,s=1120}
{x=1259,m=1158,a=113,s=889}
{x=802,m=43,a=1178,s=1081}
{x=93,m=1964,a=849,s=27}
{x=1657,m=24,a=480,s=94}
{x=609,m=198,a=2318,s=682}
{x=341,m=435,a=228,s=347}
{x=3411,m=15,a=739,s=575}
{x=360,m=2780,a=322,s=3534}
{x=106,m=295,a=3151,s=993}
{x=121,m=292,a=24,s=1042}
{x=464,m=246,a=377,s=662}
{x=1060,m=919,a=992,s=631}
{x=562,m=1532,a=1579,s=2957}
{x=484,m=61,a=500,s=1107}
{x=551,m=2370,a=515,s=146}
{x=370,m=248,a=519,s=1796}
{x=1945,m=299,a=49,s=921}
{x=2324,m=2780,a=2268,s=17}
{x=267,m=223,a=871,s=786}
{x=66,m=3536,a=1272,s=446}
{x=1450,m=591,a=14,s=1961}
{x=1107,m=1181,a=2033,s=451}
{x=1197,m=519,a=1782,s=561}
{x=1174,m=548,a=1494,s=123}
{x=496,m=3050,a=812,s=407}
{x=2824,m=638,a=2378,s=508}
{x=1215,m=1033,a=1816,s=607}
{x=768,m=2648,a=2255,s=1314}
{x=1518,m=2155,a=2,s=1036}
{x=1923,m=83,a=661,s=409}
{x=2019,m=850,a=1935,s=477}
{x=27,m=1351,a=1634,s=530}
{x=488,m=356,a=310,s=16}
{x=1321,m=533,a=814,s=519}
{x=393,m=625,a=3304,s=1848}
{x=1286,m=111,a=1070,s=1201}
{x=991,m=704,a=195,s=2104}
{x=3191,m=42,a=888,s=195}
{x=13,m=2580,a=1811,s=417}
{x=27,m=373,a=126,s=559}
{x=280,m=1062,a=681,s=445}
{x=894,m=1350,a=670,s=3477}
{x=100,m=290,a=236,s=255}
{x=1809,m=2398,a=239,s=1972}
{x=678,m=222,a=1015,s=990}
{x=1821,m=547,a=46,s=142}
{x=852,m=316,a=3201,s=43}
{x=19,m=1365,a=49,s=1051}
{x=451,m=302,a=2964,s=591}
{x=1505,m=1563,a=565,s=38}
{x=1799,m=299,a=241,s=475}
{x=157,m=1206,a=341,s=30}
{x=2577,m=893,a=2531,s=1317}
{x=499,m=1354,a=613,s=1068}
{x=3862,m=302,a=640,s=681}
{x=22,m=1499,a=2658,s=837}
{x=1168,m=2431,a=36,s=1560}
{x=982,m=954,a=523,s=506}
{x=637,m=1894,a=1012,s=47}
{x=2671,m=53,a=164,s=2067}
{x=87,m=1059,a=3603,s=1182}
{x=144,m=506,a=3266,s=292}
{x=25,m=1339,a=2362,s=567}
{x=2684,m=286,a=287,s=16}
{x=493,m=1200,a=1136,s=549}
{x=115,m=2243,a=1228,s=1609}
{x=1142,m=155,a=2571,s=2808}
{x=1129,m=66,a=1762,s=1055}
{x=2105,m=1083,a=579,s=286}
{x=90,m=1196,a=1372,s=2115}
{x=198,m=2277,a=794,s=1768}
{x=87,m=2331,a=707,s=654}
{x=2068,m=112,a=230,s=1648}
{x=612,m=716,a=66,s=124}
{x=1935,m=256,a=2203,s=251}
{x=2117,m=1,a=71,s=255}
{x=1244,m=842,a=1714,s=1013}
{x=91,m=186,a=909,s=3282}
{x=1062,m=614,a=285,s=2007}
{x=1414,m=1555,a=781,s=3500}
{x=109,m=568,a=1996,s=50}
{x=96,m=1032,a=876,s=1297}
{x=2351,m=516,a=2179,s=89}
{x=385,m=1162,a=1858,s=6}
{x=1035,m=8,a=27,s=2352}
{x=1604,m=201,a=14,s=273}
{x=5,m=304,a=809,s=170}
{x=1806,m=690,a=87,s=1015}
{x=1277,m=609,a=2236,s=3938}
{x=1687,m=834,a=2969,s=28}
{x=288,m=1255,a=457,s=60}
{x=363,m=2289,a=333,s=1596}
{x=334,m=233,a=1967,s=806}
{x=239,m=23,a=1101,s=1689}
{x=536,m=1102,a=317,s=3}
{x=710,m=755,a=206,s=2276}
{x=458,m=2985,a=20,s=2107}
{x=1582,m=785,a=594,s=888}
{x=188,m=3154,a=337,s=1770}
{x=148,m=1575,a=2032,s=434}
{x=1240,m=134,a=431,s=2672}
{x=884,m=539,a=1963,s=206}
{x=1418,m=1822,a=3680,s=261}
{x=1240,m=1333,a=901,s=248}
{x=601,m=3123,a=1399,s=374}
{x=314,m=63,a=325,s=256}
{x=911,m=1106,a=146,s=70}
{x=1003,m=3328,a=608,s=1374}
{x=180,m=415,a=2814,s=1821}
{x=330,m=411,a=982,s=1378}
{x=3315,m=8,a=505,s=2292}
{x=312,m=2130,a=168,s=574}
{x=690,m=762,a=348,s=691}
{x=1483,m=81,a=2107,s=16}
{x=1390,m=60,a=1620,s=3}
{x=1612,m=38,a=776,s=1259}
{x=138,m=12,a=145,s=1061}
{x=350,m=571,a=22,s=1209}
{x=488,m=1476,a=1086,s=1916}
{x=1223,m=3412,a=1776,s=1521}
{x=1509,m=11,a=1185,s=756}
{x=14,m=965,a=350,s=3055}
{x=342,m=38,a=1161,s=818}
{x=1423,m=745,a=613,s=365}
{x=552,m=508,a=1445,s=2403}
{x=54,m=543,a=1924,s=157}
{x=172,m=59,a=1575,s=1378}
{x=2066,m=818,a=2385,s=1163}
{x=2368,m=1694,a=465,s=1568}
{x=1266,m=133,a=2497,s=240}
{x=663,m=683,a=2924,s=2232}
{x=537,m=1355,a=187,s=1305}
{x=2555,m=2010,a=177,s=845}
{x=1065,m=209,a=49,s=264}
{x=840,m=102,a=2234,s=2890}
{x=137,m=144,a=1454,s=5}
{x=39,m=63,a=2040,s=281}
{x=92,m=331,a=3823,s=1301}
{x=1017,m=2377,a=147,s=2734}
{x=2217,m=1176,a=1067,s=704}
{x=2061,m=1184,a=1660,s=375}
{x=580,m=3270,a=1203,s=637}
{x=1445,m=1059,a=181,s=1158}
{x=374,m=311,a=206,s=76}
{x=2672,m=2024,a=441,s=2436}
{x=63,m=32,a=26,s=3041}
{x=579,m=603,a=129,s=195}
{x=2619,m=235,a=867,s=730}
{x=452,m=250,a=1665,s=1948}
{x=1592,m=117,a=2253,s=1474}
{x=567,m=1601,a=559,s=263}
{x=3698,m=156,a=115,s=3232}
{x=149,m=1580,a=302,s=61}
{x=165,m=702,a=2321,s=822}
{x=1158,m=991,a=1549,s=1155}
{x=793,m=689,a=1205,s=2663}
{x=81,m=1059,a=1142,s=1921}
{x=1414,m=946,a=860,s=1350}
{x=1521,m=1125,a=359,s=1496}
{x=250,m=1164,a=3446,s=594}
{x=1580,m=41,a=164,s=130}
{x=2469,m=1196,a=1060,s=472}
{x=98,m=1444,a=1226,s=2154}
{x=86,m=1948,a=1124,s=1944}
{x=1592,m=618,a=1459,s=22}
{x=866,m=1120,a=1696,s=508}
{x=371,m=1236,a=1553,s=1166}
{x=2679,m=2544,a=1114,s=2995}
{x=761,m=1377,a=1002,s=24}
{x=2122,m=2991,a=883,s=75}
{x=685,m=687,a=516,s=214}
{x=1014,m=1270,a=263,s=1107}
{x=153,m=209,a=16,s=946}
{x=1529,m=191,a=865,s=2634}

17
19/input_test Normal file
View File

@@ -0,0 +1,17 @@
px{a<2006:qkq,m>2090:A,rfg}
pv{a>1716:R,A}
lnx{m>1548:A,A}
rfg{s<537:gd,x>2440:R,A}
qs{s>3448:A,lnx}
qkq{x<1416:A,crn}
crn{x>2662:A,R}
in{s<1351:px,qqz}
qqz{s>2770:qs,m<1801:hdj,R}
gd{a>3333:R,R}
hdj{m>838:A,pv}
{x=787,m=2655,a=1222,s=2876}
{x=1679,m=44,a=2067,s=496}
{x=2036,m=264,a=79,s=2244}
{x=2461,m=1339,a=466,s=291}
{x=2127,m=1623,a=2188,s=1013}

407
19/main.s Normal file
View File

@@ -0,0 +1,407 @@
%include "utils.s"
global _start
[bits 32]
[section .text]
%define FILENAME "input"
;%define FILENAME "input_test"
_start:
mov esi, file
load_rule:
xor ebx, ebx ; id
.get_id:
lodsb
cmp al, '{'
je .got_id
shl ebx, 8
mov bl, al ; add new byte
jmp .get_id
.got_id:
call id_to_idx ; idx in EDX
shl edx, 4 ; *16
lea edi, [rules+edx] ; rule ptr
.get_rules:
; --- rule format ---
; [ 16 ]
; [ 4 ][ 4 ][ 4 ][ 4 ]
; [ 2 ] [ 2 ][ 2 ] [ 2 ][ 2 ] [ 2 ][ 2 ] [ 2 ]
; [bound] [ vdr ][bound] [ vdr ][bound] [ vdr ][bound] [ vdr ]
; var, dir, & res
; FEDCBA9876543210
; --- var --- 76543210
; ...............1 -> Always
; .............00. -> a (ASCII .1100...)
; .............01. -> m (ASCII .1101...)
; .............10. -> s (ASCII .1110...)
; .............11. -> x (ASCII .1111...)
; --- dir ---
; ............0... -> < (ASCII .0....0.)
; ............1... -> > (ASCII .0....1.)
; --- res ---
; 111111111111.... -> R (ASCII .10....0 bit 0 - 1 -> ..111)
; 000000000000.... -> A (ASCII .10....1 bit 0 - 1 -> ..000)
; NNNNNNNNNNNN.... -> eval
xor ecx, ecx ; output vdr & bound
xor eax, eax ; input byte
lodsb ; lowercase alpha or RA
bt ax, 5 ; low for RA, high for alpha
jc .alpha
; immediately finish with R or A
or cx, 1 ; Always
and ax, 1 ; bit 0 of ASCII
dec ax ; R -> -1, A -> 0
shl ax, 4 ; correct position
or cx, ax
jmp .done
.alpha: ; either [xmas][><] or a multi-char ID
mov ebx, eax ; save last input
lodsb ; next byte
bt ax, 6 ; bit 6 low for ><
jnc .is_check
; immediately finish by evaluating ID
.imm_got_id_byte:
shl ebx, 8
mov bl, al
.imm_get_full_id:
lodsb
cmp al, ',' ; ends , or }
je .imm_got_id
cmp al, '}'
jne .imm_got_id_byte
.imm_got_id:
call id_to_idx ; idx in EDX
or cx, 1 ; out.var <- Always
shl edx, 4 ; correct position
or cx, dx ; out.res <- idx
jmp .done
.is_check:
and bx, 3<<3
shr bx, 2
or cx, bx ; out.var <- bits 3&4 of last
and ax, 1<<1
shl ax, 2
or cx, ax ; out.dir <- bit 1 of ASCII
call dec_parse
mov bx, cx
mov cx, ax
shl ecx, 16
mov cx, bx ; out.bound <- parse_dec
; parse_dec skips the : so get the res
lodsb
bt ax, 5
jc .chk_id
; res is R or A
and ax, 1
dec ax
shl ax, 4
or cx, ax ; out.res <- bit 0 of ASCII - 1
jmp .done
.chk_id: ; res is ID
xor ebx, ebx
jmp .chk_got_id_byte
.chk_next_byte:
lodsb
cmp al, ',' ; ends ,
je .chk_got_id
.chk_got_id_byte:
shl ebx, 8
mov bl, al
jmp .chk_next_byte
.chk_got_id:
call id_to_idx ; idx in EDX
shl edx, 4
or cx, dx ; out.res <- idx
.done:
mov eax, ecx
stosd
cmp byte [esi-1], ','
je .get_rules
cmp byte [esi], ','
je .next_rule
cmp byte [esi-1], '}'
je .next_line
cmp byte [esi], '}'
je .next_line
cmp byte [esi-1], 10
je .check_rules_over
call newline
.wtf: p_string wtf
jmp .wtf
.next_rule:
inc esi
jmp .get_rules
.next_line:
lodsb
cmp al, 10 ; \n
jne .next_line
.check_rules_over:
cmp byte [esi], 10
jne load_rule
rules_over:
mov eax, [next_rule_idx]
dec eax
call print_dec
call newline
; find rule 'in'
mov ebx, 'ni'
call id_to_idx
mov [in_idx], edx
mov eax, edx
call print_dec
call space
shl edx, 4
movzx eax, word [rules+edx]
call print_dec
call space
movzx eax, word [rules+edx+2]
call print_dec
call newline
proc_next_input:
; go through the rules
mov ebx, [in_idx]
push 1 ; x min
push 4001 ; x max (exclusive)
push 1 ; m min
push 4001 ; m max (exclusive)
push 1 ; a min
push 4001 ; a max (exclusive)
push 1 ; s min
push 4001 ; s max (exclusive)
call check_rule
jmp game_over
; rule idx in EBX, xmas ranges on stack (args)
; ebp+36 x min
; ebp+32 x max (exclusive)
; ebp+28 m min
; ebp+24 m max (exclusive)
; ebp+20 a min
; ebp+16 a max (exclusive)
; ebp+12 s min
; ebp+ 8 s max (exclusive)
; ebp+ 4 return loc
; ebp+ 0 ebp
; ebp- 4 rule ptr
check_rule:
push ebp
mov ebp, esp ; a proper C-like stackframe!? egads!
sub esp, 4
.inner:
shl ebx, 4
lea esi, [rules+ebx] ; rule ptr
mov [esp], esi
.next_rule:
mov esi, [esp]
lodsd ; rule
mov [esp], esi
bt ax, 0 ; always
jc .always
; .............00. -> a
; .............01. -> m
; .............10. -> s
; .............11. -> x
; ............0... -> <
; ............1... -> >
mov esi, eax
shr esi, 16 ; bound
mov ebx, eax
and bl, 0b1110 ; dir & var
cmp bl, 0b0110
je .xl
cmp bl, 0b0010
je .ml
cmp bl, 0b0000
je .al
cmp bl, 0b0100
je .sl
cmp bl, 0b1110
je .xg
cmp bl, 0b1010
je .mg
cmp bl, 0b1000
je .ag
cmp bl, 0b1100
je .sg
mov eax, [0] ; something is horribly wrong
.xl: ; matched x range is x min to bound, inverse is bound to x max
xchg esi, [ebp+32] ; bound -> our max, our old max -> esi
call .internal_thing
xchg esi, [ebp+32] ; restore old max
mov [ebp+36], esi ; bound -> our min
jmp .next_rule
.ml: ; matched m range is m min to bound, inverse is bound to m max
xchg esi, [ebp+24] ; bound -> our max, our old max -> esi
call .internal_thing
xchg esi, [ebp+24] ; restore old max
mov [ebp+28], esi ; bound -> our min
jmp .next_rule
.al: ; matched a range is a min to bound, inverse is bound to a max
xchg esi, [ebp+16] ; bound -> our max, our old max -> esi
call .internal_thing
xchg esi, [ebp+16] ; restore old max
mov [ebp+20], esi ; bound -> our min
jmp .next_rule
.sl: ; matched s range is s min to bound, inverse is bound to s max
xchg esi, [ebp+ 8] ; bound -> our max, our old max -> esi
call .internal_thing
xchg esi, [ebp+ 8] ; restore old max
mov [ebp+12], esi ; bound -> our min
jmp .next_rule
.xg: ; matched x range is bound+1 to x max, inverse is x min to bound+1
inc esi
xchg esi, [ebp+36] ; bound+1 -> our min, our old min -> esi
call .internal_thing
xchg esi, [ebp+36] ; restore old min
mov [ebp+32], esi ; bound+1 -> our max
jmp .next_rule
.mg: ; matched m range is bound+1 to m max, inverse is m min to bound+1
inc esi
xchg esi, [ebp+28] ; bound+1 -> our min, our old min -> esi
call .internal_thing
xchg esi, [ebp+28] ; restore old min
mov [ebp+24], esi ; bound+1 -> our max
jmp .next_rule
.ag: ; matched a range is bound+1 to a max, inverse is a min to bound+1
inc esi
xchg esi, [ebp+20] ; bound+1 -> our min, our old min -> esi
call .internal_thing
xchg esi, [ebp+20] ; restore old min
mov [ebp+16], esi ; bound+1 -> our max
jmp .next_rule
.sg: ; matched a range is bound+1 to s max, inverse is s min to bound+1
inc esi
xchg esi, [ebp+12] ; bound+1 -> our min, our old min -> esi
call .internal_thing
xchg esi, [ebp+12] ; restore old min
mov [ebp+ 8], esi ; bound+1 -> our max
jmp .next_rule
.always:
shr ax, 4 ; rule.res
test ax, ax
jz .return_res_A
cmp ax, 0x0FFF
je .return_res_R
; nested rule
movzx ebx, ax
jmp .inner
.return_res_A:
call .A
.return_res_R:
add esp, 4 ; stackframe gone :c
pop ebp
ret
.internal_thing:
mov ebx, eax
shr ax, 4 ; rule.res
test ax, ax
jz .A
cmp ax, 0x0FFF
je .R
; we need to make a recursive call, set up args
push esi
movzx ebx, ax
push dword [ebp+36] ; x min
push dword [ebp+32] ; x max
push dword [ebp+28] ; m min
push dword [ebp+24] ; m max
push dword [ebp+20] ; a min
push dword [ebp+16] ; a max
push dword [ebp+12] ; s min
push dword [ebp+ 8] ; s max
call check_rule
add esp, 4*8
pop esi
jmp .R
.A:
pushad
sub esp, 8 ; scratch memory
; final_value += (xMax-xMin)*
; (mMax-mMin)*
; (aMax-aMin)*
; (sMax-sMin);
mov eax, [ebp+32]
sub eax, [ebp+36]
js .no_add
xor edx, edx
mov ecx, [ebp+24]
sub ecx, [ebp+28]
js .no_add
imul edx, ecx
mov [esp], edx
mul ecx
mov ecx, edx
mov edx, [esp]
add ecx, edx
mov edx, [ebp+16]
sub edx, [ebp+20]
js .no_add
imul ecx, edx
mul edx
add edx, ecx
mov ecx, [ebp+ 8]
sub ecx, [ebp+12]
js .no_add
imul edx, ecx
mov [esp+4], edx
mul ecx
mov esi, eax
mov eax, [esp+4]
add edx, eax
add [final_value], esi
adc [final_value+4], edx
.no_add:
add esp,8
popad
.R: ; done, return to place to inverse range
ret
game_over:
mov eax, [final_value]
call print_dec
call space
mov eax, [final_value+4]
call print_dec
call newline
jmp exit
; ID in EBX, IDX return in EDX
id_to_idx:
xor edx, edx
.test:
cmp [rule_idx_to_id+edx*4], ebx
je .found
inc edx
cmp edx, [next_rule_idx]
jb .test
; new ID
mov [rule_idx_to_id+edx*4], ebx
inc dword [next_rule_idx]
.found:
ret
[section .data]
next_rule_idx: dd 1
in_idx: dd 0
final_value: dd 0, 0
file: incbin FILENAME
.over:
[section .bss]
rules: resd 1024*4
rule_idx_to_id: resd 1024
[section .rodata]
wtf: db "WTF"
.over:

304
19/main_part1.s Normal file
View File

@@ -0,0 +1,304 @@
%include "utils.s"
global _start
[bits 32]
[section .text]
%define FILENAME "input"
;%define FILENAME "input_test"
_start:
mov esi, file
load_rule:
xor ebx, ebx ; id
.get_id:
lodsb
cmp al, '{'
je .got_id
shl ebx, 8
mov bl, al ; add new byte
jmp .get_id
.got_id:
call id_to_idx ; idx in EDX
shl edx, 4 ; *16
lea edi, [rules+edx] ; rule ptr
.get_rules:
; --- rule format ---
; [ 16 ]
; [ 4 ][ 4 ][ 4 ][ 4 ]
; [ 2 ] [ 2 ][ 2 ] [ 2 ][ 2 ] [ 2 ][ 2 ] [ 2 ]
; [bound] [ vdr ][bound] [ vdr ][bound] [ vdr ][bound] [ vdr ]
; var, dir, & res
; FEDCBA9876543210
; --- var --- 76543210
; ...............1 -> Always
; .............00. -> a (ASCII .1100...)
; .............01. -> m (ASCII .1101...)
; .............10. -> s (ASCII .1110...)
; .............11. -> x (ASCII .1111...)
; --- dir ---
; ............0... -> < (ASCII .0....0.)
; ............1... -> > (ASCII .0....1.)
; --- res ---
; 111111111111.... -> R (ASCII .10....0 bit 0 - 1 -> ..111)
; 000000000000.... -> A (ASCII .10....1 bit 0 - 1 -> ..000)
; NNNNNNNNNNNN.... -> eval
xor ecx, ecx ; output vdr & bound
xor eax, eax ; input byte
lodsb ; lowercase alpha or RA
bt ax, 5 ; low for RA, high for alpha
jc .alpha
; immediately finish with R or A
or cx, 1 ; Always
and ax, 1 ; bit 0 of ASCII
dec ax ; R -> -1, A -> 0
shl ax, 4 ; correct position
or cx, ax
jmp .done
.alpha: ; either [xmas][><] or a multi-char ID
mov ebx, eax ; save last input
lodsb ; next byte
bt ax, 6 ; bit 6 low for ><
jnc .is_check
; immediately finish by evaluating ID
.imm_got_id_byte:
shl ebx, 8
mov bl, al
.imm_get_full_id:
lodsb
cmp al, ',' ; ends , or }
je .imm_got_id
cmp al, '}'
jne .imm_got_id_byte
.imm_got_id:
call id_to_idx ; idx in EDX
or cx, 1 ; out.var <- Always
shl edx, 4 ; correct position
or cx, dx ; out.res <- idx
jmp .done
.is_check:
and bx, 3<<3
shr bx, 2
or cx, bx ; out.var <- bits 3&4 of last
and ax, 1<<1
shl ax, 2
or cx, ax ; out.dir <- bit 1 of ASCII
call dec_parse
mov bx, cx
mov cx, ax
shl ecx, 16
mov cx, bx ; out.bound <- parse_dec
; parse_dec skips the : so get the res
lodsb
bt ax, 5
jc .chk_id
; res is R or A
and ax, 1
dec ax
shl ax, 4
or cx, ax ; out.res <- bit 0 of ASCII - 1
jmp .done
.chk_id: ; res is ID
xor ebx, ebx
jmp .chk_got_id_byte
.chk_next_byte:
lodsb
cmp al, ',' ; ends ,
je .chk_got_id
.chk_got_id_byte:
shl ebx, 8
mov bl, al
jmp .chk_next_byte
.chk_got_id:
call id_to_idx ; idx in EDX
shl edx, 4
or cx, dx ; out.res <- idx
.done:
mov eax, ecx
stosd
cmp byte [esi-1], ','
je .get_rules
cmp byte [esi], ','
je .next_rule
cmp byte [esi-1], '}'
je .next_line
cmp byte [esi], '}'
je .next_line
cmp byte [esi-1], 10
je .check_rules_over
call newline
.wtf: p_string wtf
jmp .wtf
.next_rule:
inc esi
jmp .get_rules
.next_line:
lodsb
cmp al, 10 ; \n
jne .next_line
.check_rules_over:
cmp byte [esi], 10
jne load_rule
rules_over:
mov eax, [next_rule_idx]
dec eax
call print_dec
call newline
; find rule 'in'
mov ebx, 'ni'
call id_to_idx
mov [in_idx], edx
mov eax, edx
call print_dec
call space
shl edx, 4
movzx eax, word [rules+edx]
call print_dec
call space
movzx eax, word [rules+edx+2]
call print_dec
call newline
; we're now reading in the inputs to test
; find the next {
proc_next_input:
mov ecx, 32
mov al, '{'
xchg edi, esi
repne scasb
xchg edi, esi
cmp esi, file.over
jae game_over
; get 4 nums, x m a s (ecx edx edi ebp)
.get_x:
call dec_parse
jc .get_x
mov ecx, eax
.get_m:
call dec_parse
jc .get_m
mov edx, eax
.get_a:
call dec_parse
jc .get_a
mov edi, eax
.get_s:
call dec_parse
jc .get_s
mov ebp, eax
; go through the rules
push esi
mov ebx, [in_idx]
call check_rule
add ecx, edx
add ecx, edi
add ecx, ebp
not eax
movzx eax, al
test eax, eax
cmovnz eax, ecx
add [final_value], eax
pop esi
jmp proc_next_input
; rule idx in EBX, xmas in ecx edx edi ebp
; return in EAX
check_rule:
sub esp, 4
.inner:
shl ebx, 4
lea esi, [rules+ebx] ; rule ptr
mov [esp], esi
.next_rule:
mov esi, [esp]
lodsd ; rule
mov [esp], esi
bt ax, 0 ; always
jc .always
; .............00. -> a
; .............01. -> m
; .............10. -> s
; .............11. -> x
; ............0... -> <
; ............1... -> >
mov esi, eax
mov ebx, eax
and bl, 0b110 ; var
cmp bl, 0b000
cmove eax, edi
cmp bl, 0b010
cmove eax, edx
cmp bl, 0b100
cmove eax, ebp
cmp bl, 0b110
cmove eax, ecx
mov ebx, esi
shr ebx, 16 ; rule.bound
bt esi, 3 ; rule.dir
jnc .less
cmp eax, ebx
jg .match
jmp .next_rule
.less:
cmp eax, ebx
jge .next_rule
.match:
mov eax, esi
.always:
shr ax, 4 ; rule.res
test ax, ax
jz .return_res
cmp ax, 0x0FFF
je .return_res
; nested rule
movzx ebx, ax
jmp .inner
.return_res:
movzx eax, ax
add esp, 4
ret
game_over:
mov eax, [final_value]
call print_dec
call newline
jmp exit
; ID in EBX, IDX return in EDX
id_to_idx:
xor edx, edx
.test:
cmp [rule_idx_to_id+edx*4], ebx
je .found
inc edx
cmp edx, [next_rule_idx]
jb .test
; new ID
mov [rule_idx_to_id+edx*4], ebx
inc dword [next_rule_idx]
.found:
ret
[section .data]
next_rule_idx: dd 1
final_value: dd 0
in_idx: dd 0
file: incbin FILENAME
.over:
[section .bss]
rule_idx_to_id: resd 1024
rules: resd 1024*4
[section .rodata]
wtf: db "WTF"
.over:

285
19/utils.s Normal file
View File

@@ -0,0 +1,285 @@
[bits 32]
[section .text]
; call # val val2
; int $0x80 eax eax edx -
;
; arg1 arg2 arg3 arg4 arg5 arg6 arg7
; ebx ecx edx esi edi ebp -
exit:
mov eax, 1 ; exit
int 0x80
; filename in EBX
; return handle in EBX
; read only
open_file:
push eax
push ecx
mov eax, 5 ; open
xor ecx, ecx ; read only
int 0x80
mov ebx, eax
pop ecx
pop eax
ret
; file handle in EBX
; buffer in ECX
; count of bytes to read in EDX
; return bytes actually read in EAX
; exits on error
read_file:
mov eax, 3 ; read
int 0x80
test eax, eax
js .err
ret
.err:
mov eax, 4 ; write
mov ebx, 1 ; stdout
mov ecx, .err_str
mov edx, 21
int 0x80
jmp exit
.err_str: db `Could not read file.\n`
; string input in ESI
; value in EAX
; CF set if none, clear if some
; ESI set past checked area
dec_parse:
push ebx
push edx
push edi
xor eax, eax
xor edi, edi
mov ebx, 10 ; base
lodsb
sub al, '0'
js .no_input
cmp al, 9
jle .got_char
.no_input:
stc ; set CF
jmp .done
.loop:
xor eax,eax
lodsb
sub al, '0'
js .dec_done
cmp al, 9
jg .dec_done
.got_char:
xchg edi,eax
mul ebx
add edi,eax
jmp .loop
.dec_done:
clc ; clear CF
.done:
mov eax,edi
pop edi
pop edx
pop ebx
ret
; string input in ESI
; value in EAX
; CF set if none, clear if some
; ESI set past checked area
sign_dec_parse:
push ebx
push ecx
push edx
push edi
xor eax, eax
xor edi, edi
xor ecx, ecx ; neg flag
mov ebx, 10 ; base
cmp byte [esi], '-'
jne .no_minus
inc esi
mov cl, 1
.no_minus:
lodsb
sub al, '0'
js .no_input
cmp al, 9
jle .got_char
.no_input:
stc ; set CF
jmp .done
.loop:
xor eax,eax
lodsb
sub al, '0'
js .dec_done
cmp al, 9
jg .dec_done
.got_char:
xchg edi,eax
mul ebx
add edi,eax
jmp .loop
.dec_done:
test ecx, ecx
jz .not_neg
neg edi
.not_neg:
clc ; clear CF
.done:
mov eax,edi
pop edi
pop edx
pop ecx
pop ebx
ret
; modifies no regs
newline:
pushad
push 10
mov eax, 4 ; write
mov ebx, 1 ; stdout
mov ecx, esp ; string
mov edx, 1 ; length
int 0x80
add esp, 4
popad
ret
; modifies no regs
space:
pushad
push 9
mov eax, 4 ; write
mov ebx, 1 ; stdout
mov ecx, esp ; string
mov edx, 1 ; length
int 0x80
add esp, 4
popad
ret
; input in EAX, all regs unmodified
print_dec:
pushad ; save regs
; max 4294967296 is 10 chars
; round to nearest 32-bit boundary
sub esp, 12
; string in ECX, length in EDX
lea ecx, [esp+11] ; last possible byte
; check for 0
test eax, eax
jz .zero
mov ebx, 10 ; base 10
xor esi, esi ; counter
.div_shit:
xor edx, edx
; divide
div ebx
dec ecx ; next char
inc esi
; store
add dl, '0'
mov byte [ecx], dl
; check if done
test eax, eax
jnz .div_shit ; continue
mov edx, esi ; counter in edx
jmp .write
.zero:
mov byte [ecx], '0'
mov edx, 1 ; length
.write:
mov eax, 4 ; write
mov ebx, 1 ; stdout
int 0x80
add esp, 12 ; restore stack
popad ; restore regs
ret
; input in EAX, all regs unmodified
print_sign_dec:
pushad ; save regs
; range -2147483648 to 2147483647 is 11 chars
; round to nearest 32-bit boundary
sub esp, 12
; string in ECX, length in EDX
lea ecx, [esp+11] ; last possible byte
; check for 0, negative
xor ebp, ebp
test eax, eax
jz .zero
jns .positive
neg eax
mov ebp, 1
.positive:
mov ebx, 10 ; base 10
xor esi, esi ; counter
.div_shit:
xor edx, edx
; divide
div ebx
dec ecx ; next char
inc esi
; store
add dl, '0'
mov byte [ecx], dl
; check if done
test eax, eax
jnz .div_shit ; continue
mov edx, esi ; counter in edx
jmp .write
.zero:
mov byte [ecx], '0'
mov edx, 1 ; length
.write:
test ebp, ebp
jz .no_minus
dec ecx
inc edx
mov byte [ecx], '-'
.no_minus:
mov eax, 4 ; write
mov ebx, 1 ; stdout
int 0x80
add esp, 12 ; restore stack
popad ; restore regs
ret
; input in ESI, len in ECX, all regs unmodified
print_string:
pushad ; save regs
mov eax, 4 ; write
mov ebx, 1 ; stdout
mov edx, ecx ; length
mov ecx, esi ; string
int 0x80
popad ; restore regs
ret
; input in AL, all regs unmodified
print_char:
pushad ; save regs
push eax
mov eax, 4 ; write
mov ebx, 1 ; stdout
mov edx, 1 ; length
mov ecx, esp ; string
int 0x80
add esp, 4
popad ; restore regs
ret
; --- MACROS ---
%define len(x) x %+ .over - x
%macro p_string 1
push esi
push ecx
mov esi, %1
mov ecx, len(%1)
call print_string
pop ecx
pop esi
%endmacro

3
20/Makefile Normal file
View File

@@ -0,0 +1,3 @@
all:
nasm -g -felf32 main.s && ld -melf_i386 -g main.o

58
20/input Normal file
View File

@@ -0,0 +1,58 @@
%cd -> jx, gh
%bk -> jp, cn
%px -> xc, hg
%tv -> gh, xl
&xc -> bm, zq, jf, hg, bd, hn
%bd -> px
&bh -> mf
%dx -> cn, rb
%vv -> pp, gh
broadcaster -> cx, zq, tv, rh
%rb -> cn, qr
&jf -> mf
%jd -> mm
%cx -> xd, cn
%zs -> cz
%hn -> bm
%xr -> bd, xc
&mf -> rx
%zq -> kg, xc
&cn -> sh, jd, cx, tc, xd
%cs -> xj
%fb -> tc, cn
%mm -> cn, bk
%sq -> th, hz
%sz -> vx
%xl -> gh, sz
%vm -> gh, vv
%jp -> cn
%qr -> cn, jd
%bq -> xc, zv
&sh -> mf
%gz -> gs, hz
%qc -> qg, xc
%hg -> bq
%dt -> sq, hz
%xj -> fz
%qs -> gh
%fz -> hz, zs
%qg -> xc
%pp -> qs, gh
%zv -> xc, qc
%rh -> hz, mr
&gh -> tv, lk, sz, bh, vx
%th -> hz
&mz -> mf
%bm -> xr
%lk -> pg
%jx -> lk, gh
&hz -> xj, cs, zs, rh, mz
%tc -> dx
%mr -> hz, gz
%xd -> jk
%pg -> vm, gh
%kg -> hn, xc
%gs -> cs, hz
%vx -> cd
%cz -> hz, dt
%jk -> cn, fb

5
20/input_test Normal file
View File

@@ -0,0 +1,5 @@
broadcaster -> aa, bb, cc
%aa -> bb
%bb -> cc
%cc -> iv
&iv -> aa

5
20/input_test2 Normal file
View File

@@ -0,0 +1,5 @@
broadcaster -> aa
%aa -> iv, cn
&iv -> bb
%bb -> cn
&cn -> ou

278
20/main.s Normal file
View File

@@ -0,0 +1,278 @@
%include "utils.s"
global _start
[bits 32]
[section .text]
%define FILENAME "input"
;%define FILENAME "input_test"
;%define FILENAME "input_test2"
;%define DBG
_start:
; read in modules
; module data (16 bytes):
; 0
; bit 1: type (0: flipflop, 1: conj) bit 0: state (0: low, 1: high)
; 1 2 3 4 5 6
; destination IDX list
; 7 8 9 A B C D E F
; input states (for conj modules)
; bit 0 is remembered state, higher is index
mov esi, file
read_modules:
lodsb
cmp al, '%'
je .flipflop
cmp al, '&'
je .conjunc
; broadcaster
%ifdef DBG
mov al, 'B'
call print_char
mov al, 'R'
call print_char
call space
%endif
mov ch, 1<<1
mov al, 1
%ifdef DBG
call print_hex_byte
call space
%endif
mov cl, -1 ; broadcaster is special
add esi, 14
mov edi, modules+16 ; module 1 is broadcast
jmp .get_dests
.flipflop:
mov cl, 0b00 ; low, flipflop
jmp .get_idx
.conjunc:
mov cl, 0b10 ; low, conj
jmp .get_idx
.get_idx:
; get ID
lodsb
%ifdef DBG
call print_char
%endif
mov bh, al
lodsb
%ifdef DBG
call print_char
call space
%endif
mov bl, al
call id_to_idx ; idx in edx
mov ch, dl
%ifdef DBG
mov al, dl
call print_hex_byte
call space
%endif
shl ch, 1
shl edx, 4 ; * 16
lea edi, [modules+edx]
add esi, 4
.get_dests:
; type/state in CL
mov [edi], cl
inc edi
.next_dest:
; get dest ID
lodsb
%ifdef DBG
call print_char
%endif
mov bh, al
lodsb
%ifdef DBG
call print_char
call space
%endif
mov bl, al
call id_to_idx
cmp bx, 'fm'
jne .not_rx
mov [mf_idx], dx
.not_rx:
mov al, dl
%ifdef DBG
call print_hex_byte
call space
%endif
stosb
; store our idx<<1 in dest inputs
shl edx, 4 ; * 16
lea edx, [modules+edx+7]
.store_input:
cmp byte [edx], 0
jnz .check_next_input
mov byte [edx], ch
jmp .input_stored
.check_next_input:
inc edx
jmp .store_input
.input_stored:
; check if more
lodsb
cmp al, ','
jne .cont ; no more
inc esi ; space
jmp .next_dest
.cont:
%ifdef DBG
call newline
%endif
cmp esi, file.over
jb read_modules
main:
; start an iteration, broadcaster (1) sends low to everything
mov dword [queue_head], 0
mov dword [queue_tail], 2
mov word [queue], 0b10 ; low to index 1
call do_iters
inc dword [final_value]
jmp main
do_iters:
; get head of queue
mov eax, [queue_head]
mov ax, [eax+queue]
%ifdef DBG
call print_hex_word
call newline
%endif
mov cl, ah ; sender
movzx eax, al
shr eax, 1 ; get pulse
setc bl
jnc .not_high
cmp al, [mf_idx]
jne .not_high
push eax
mov al, cl
call print_hex_byte
call space
mov eax, [final_value]
call print_dec
call newline
pop eax
.not_high:
; get module
mov bh, al ; idx
shl eax, 4 ; * 16
lea edi, [modules+eax]
mov al, [edi]
cmp al, -1
je .broadcast
bt ax, 1
jc .conj
.flipflop:
; if high, do nothing
test bl, bl
jnz .cont
; if low, flip and send result
xor al, 1
bt ax, 0
setc bl
mov [edi], al
jmp add_cmds
.conj:
mov dl, 1
mov esi, 7
.check_mem:
mov al, [edi+esi]
test al, al
jz .mem_done
shr al, 1
setc dh
cmp al, cl
jne .mem_cont
shr bl, 1
setc dh
rcl al, 1
mov [edi+esi], al
.mem_cont:
and dl, dh
inc esi
cmp esi, 0xF
jbe .check_mem
.mem_done:
; send high if not all were high
xor dl, 1
mov bl, dl
jmp add_cmds
.broadcast:
jmp add_cmds ; just add commands with same pulse
.cont:
mov eax, [queue_head]
add eax, 2
and eax, 511
mov [queue_head], eax
cmp eax, [queue_tail]
jne do_iters
ret
; BH: module IDX, BL: pulse, EDI: *module
add_cmds:
mov dx, bx ; save
mov ecx, 1
.loop:
mov al, [edi+ecx]
test al, al
jz .done
mov bx, dx
shl al, 1
or bl, al
%ifdef DBG
call space
mov ax, bx
call print_hex_word
call newline
%endif
; add to queue
mov eax, [queue_tail]
mov [eax+queue], bx
add eax, 2
and eax, 511
mov [queue_tail], eax
inc ecx
cmp ecx, 6
jbe .loop
.done:
jmp do_iters.cont
; ID in BX, IDX return in EDX
id_to_idx:
xor edx, edx
.test:
cmp [module_idx_to_id+edx*2], bx
je .found
inc dx
cmp dx, [next_module_idx]
jb .test
; new ID
mov [module_idx_to_id+edx*2], bx
inc word [next_module_idx]
.found:
ret
[section .data]
final_value: dd 1
next_module_idx: dw 2 ; 1 reserved for broadcaster
mf_idx: dw 0
queue_head: dd queue
queue_tail: dd queue
file: incbin FILENAME
.over: db 0 ; EOF
[section .bss]
modules: resb 64*16
module_idx_to_id: resw 64
queue: resw 64*8
[section .rodata]

296
20/main_part1.s Normal file
View File

@@ -0,0 +1,296 @@
%include "utils.s"
global _start
[bits 32]
[section .text]
%define FILENAME "input"
;%define FILENAME "input_test"
;%define FILENAME "input_test2"
;%define DBG
;%define DBG_ITERS 1000
_start:
; read in modules
; module data (16 bytes):
; 0
; bit 1: type (0: flipflop, 1: conj) bit 0: state (0: low, 1: high)
; 1 2 3 4 5 6
; destination IDX list
; 7 8 9 A B C D E F
; input states (for conj modules)
; bit 0 is remembered state, higher is index
mov esi, file
read_modules:
lodsb
cmp al, '%'
je .flipflop
cmp al, '&'
je .conjunc
; broadcaster
%ifdef DBG
mov al, 'B'
call print_char
mov al, 'R'
call print_char
call space
%endif
mov ch, 1<<1
mov al, 1
%ifdef DBG
call print_hex_byte
call space
%endif
mov cl, -1 ; broadcaster is special
add esi, 14
mov edi, modules+16 ; module 1 is broadcast
jmp .get_dests
.flipflop:
mov cl, 0b00 ; low, flipflop
jmp .get_idx
.conjunc:
mov cl, 0b10 ; low, conj
jmp .get_idx
.get_idx:
; get ID
lodsb
%ifdef DBG
call print_char
%endif
mov bh, al
lodsb
%ifdef DBG
call print_char
call space
%endif
mov bl, al
call id_to_idx ; idx in edx
mov ch, dl
%ifdef DBG
mov al, dl
call print_hex_byte
call space
%endif
shl ch, 1
shl edx, 4 ; * 16
lea edi, [modules+edx]
add esi, 4
.get_dests:
; type/state in CL
mov [edi], cl
inc edi
.next_dest:
; get dest ID
lodsb
%ifdef DBG
call print_char
%endif
mov bh, al
lodsb
%ifdef DBG
call print_char
call space
%endif
mov bl, al
call id_to_idx
mov al, dl
%ifdef DBG
call print_hex_byte
call space
%endif
stosb
; store our idx<<1 in dest inputs
shl edx, 4 ; * 16
lea edx, [modules+edx+7]
.store_input:
cmp byte [edx], 0
jnz .check_next_input
mov byte [edx], ch
jmp .input_stored
.check_next_input:
inc edx
jmp .store_input
.input_stored:
; check if more
lodsb
cmp al, ','
jne .cont ; no more
inc esi ; space
jmp .next_dest
.cont:
%ifdef DBG
call newline
%endif
cmp esi, file.over
jb read_modules
main:
mov ecx, 1000
%ifdef DBG
mov ecx, DBG_ITERS
%endif
.loop:
push ecx
; start an iteration, broadcaster (1) sends low to everything
mov dword [queue_head], 0
mov dword [queue_tail], 2
mov word [queue], 0b10 ; low to index 1
call do_iters
pop ecx
loop .loop
jmp game_over
do_iters:
; get head of queue
mov eax, [queue_head]
mov ax, [eax+queue]
%ifdef DBG
call print_hex_word
call newline
%endif
mov cl, ah ; sender
movzx eax, al
shr eax, 1 ; get pulse
setc bl
jc .got_high
inc dword [low_count]
jmp .add_done
.got_high:
inc dword [high_count]
.add_done:
; get module
mov bh, al ; idx
shl eax, 4 ; * 16
lea edi, [modules+eax]
mov al, [edi]
cmp al, -1
je .broadcast
bt ax, 1
jc .conj
.flipflop:
; if high, do nothing
test bl, bl
jnz .cont
; if low, flip and send result
xor al, 1
bt ax, 0
setc bl
mov [edi], al
jmp add_cmds
.conj:
mov dl, 1
mov esi, 7
.check_mem:
mov al, [edi+esi]
test al, al
jz .mem_done
shr al, 1
setc dh
cmp al, cl
jne .mem_cont
shr bl, 1
setc dh
rcl al, 1
mov [edi+esi], al
.mem_cont:
and dl, dh
inc esi
cmp esi, 0xF
jbe .check_mem
.mem_done:
; send high if not all were high
xor dl, 1
mov bl, dl
jmp add_cmds
.broadcast:
jmp add_cmds ; just add commands with same pulse
.cont:
mov eax, [queue_head]
add eax, 2
and eax, 511
mov [queue_head], eax
cmp eax, [queue_tail]
jne do_iters
ret
; BH: module IDX, BL: pulse, EDI: *module
add_cmds:
mov dx, bx ; save
mov ecx, 1
.loop:
mov al, [edi+ecx]
test al, al
jz .done
mov bx, dx
shl al, 1
or bl, al
%ifdef DBG
call space
mov ax, bx
call print_hex_word
call newline
%endif
; add to queue
mov eax, [queue_tail]
mov [eax+queue], bx
add eax, 2
and eax, 511
mov [queue_tail], eax
inc ecx
cmp ecx, 6
jbe .loop
.done:
jmp do_iters.cont
game_over:
mov eax, [low_count]
call print_dec
call space
mov eax, [high_count]
call print_dec
call newline
p_string info
mul dword [low_count]
call print_dec
mov al, ':'
call print_char
mov eax, edx
call print_dec
call newline
jmp exit
; ID in BX, IDX return in EDX
id_to_idx:
xor edx, edx
.test:
cmp [module_idx_to_id+edx*2], bx
je .found
inc dx
cmp dx, [next_module_idx]
jb .test
; new ID
mov [module_idx_to_id+edx*2], bx
inc word [next_module_idx]
.found:
ret
[section .data]
low_count: dd 0
high_count: dd 0
next_module_idx: dw 2 ; 1 reserved for broadcaster
in_idx: dw 0
queue_head: dd queue
queue_tail: dd queue
file: incbin FILENAME
.over: db 0 ; EOF
[section .bss]
modules: resb 64*16
module_idx_to_id: resw 64
queue: resw 64*8
[section .rodata]
info: db `LOW:HIGH\n`
.over:

336
20/utils.s Normal file
View File

@@ -0,0 +1,336 @@
[bits 32]
[section .text]
; call # val val2
; int $0x80 eax eax edx -
;
; arg1 arg2 arg3 arg4 arg5 arg6 arg7
; ebx ecx edx esi edi ebp -
exit:
mov eax, 1 ; exit
int 0x80
; filename in EBX
; return handle in EBX
; read only
open_file:
push eax
push ecx
mov eax, 5 ; open
xor ecx, ecx ; read only
int 0x80
mov ebx, eax
pop ecx
pop eax
ret
; file handle in EBX
; buffer in ECX
; count of bytes to read in EDX
; return bytes actually read in EAX
; exits on error
read_file:
mov eax, 3 ; read
int 0x80
test eax, eax
js .err
ret
.err:
mov eax, 4 ; write
mov ebx, 1 ; stdout
mov ecx, .err_str
mov edx, 21
int 0x80
jmp exit
.err_str: db `Could not read file.\n`
; string input in ESI
; value in EAX
; CF set if none, clear if some
; ESI set past checked area
dec_parse:
push ebx
push edx
push edi
xor eax, eax
xor edi, edi
mov ebx, 10 ; base
lodsb
sub al, '0'
js .no_input
cmp al, 9
jle .got_char
.no_input:
stc ; set CF
jmp .done
.loop:
xor eax,eax
lodsb
sub al, '0'
js .dec_done
cmp al, 9
jg .dec_done
.got_char:
xchg edi,eax
mul ebx
add edi,eax
jmp .loop
.dec_done:
clc ; clear CF
.done:
mov eax,edi
pop edi
pop edx
pop ebx
ret
; string input in ESI
; value in EAX
; CF set if none, clear if some
; ESI set past checked area
sign_dec_parse:
push ebx
push ecx
push edx
push edi
xor eax, eax
xor edi, edi
xor ecx, ecx ; neg flag
mov ebx, 10 ; base
cmp byte [esi], '-'
jne .no_minus
inc esi
mov cl, 1
.no_minus:
lodsb
sub al, '0'
js .no_input
cmp al, 9
jle .got_char
.no_input:
stc ; set CF
jmp .done
.loop:
xor eax,eax
lodsb
sub al, '0'
js .dec_done
cmp al, 9
jg .dec_done
.got_char:
xchg edi,eax
mul ebx
add edi,eax
jmp .loop
.dec_done:
test ecx, ecx
jz .not_neg
neg edi
.not_neg:
clc ; clear CF
.done:
mov eax,edi
pop edi
pop edx
pop ecx
pop ebx
ret
; modifies no regs
newline:
pushad
push 10
mov eax, 4 ; write
mov ebx, 1 ; stdout
mov ecx, esp ; string
mov edx, 1 ; length
int 0x80
add esp, 4
popad
ret
; modifies no regs
space:
pushad
push 9
mov eax, 4 ; write
mov ebx, 1 ; stdout
mov ecx, esp ; string
mov edx, 1 ; length
int 0x80
add esp, 4
popad
ret
; input in EAX, all regs unmodified
print_dec:
pushad ; save regs
; max 4294967296 is 10 chars
; round to nearest 32-bit boundary
sub esp, 12
; string in ECX, length in EDX
lea ecx, [esp+11] ; last possible byte
; check for 0
test eax, eax
jz .zero
mov ebx, 10 ; base 10
xor esi, esi ; counter
.div_shit:
xor edx, edx
; divide
div ebx
dec ecx ; next char
inc esi
; store
add dl, '0'
mov byte [ecx], dl
; check if done
test eax, eax
jnz .div_shit ; continue
mov edx, esi ; counter in edx
jmp .write
.zero:
mov byte [ecx], '0'
mov edx, 1 ; length
.write:
mov eax, 4 ; write
mov ebx, 1 ; stdout
int 0x80
add esp, 12 ; restore stack
popad ; restore regs
ret
; input in EAX, all regs unmodified
print_sign_dec:
pushad ; save regs
; range -2147483648 to 2147483647 is 11 chars
; round to nearest 32-bit boundary
sub esp, 12
; string in ECX, length in EDX
lea ecx, [esp+11] ; last possible byte
; check for 0, negative
xor ebp, ebp
test eax, eax
jz .zero
jns .positive
neg eax
mov ebp, 1
.positive:
mov ebx, 10 ; base 10
xor esi, esi ; counter
.div_shit:
xor edx, edx
; divide
div ebx
dec ecx ; next char
inc esi
; store
add dl, '0'
mov byte [ecx], dl
; check if done
test eax, eax
jnz .div_shit ; continue
mov edx, esi ; counter in edx
jmp .write
.zero:
mov byte [ecx], '0'
mov edx, 1 ; length
.write:
test ebp, ebp
jz .no_minus
dec ecx
inc edx
mov byte [ecx], '-'
.no_minus:
mov eax, 4 ; write
mov ebx, 1 ; stdout
int 0x80
add esp, 12 ; restore stack
popad ; restore regs
ret
; input in EAX, all regs unmodified
print_hex:
pushad
mov ebx, eax
shr eax, 16
call print_hex_word
mov eax, ebx
call print_hex_word
popad
ret
; input in AX, all regs unmodified
print_hex_word:
pushad
mov bx, ax
mov al, ah
call print_hex_byte
mov ax, bx
call print_hex_byte
popad
ret
; input in AL, all regs unmodified
print_hex_byte:
pushad
push '0000'
mov bl, al
shr bl, 4
mov dx, '0'
mov cx, 'A' - 10
cmp bl, 9
cmovg dx, cx
add bl, dl
mov [esp], bl
mov bl, al
and bl, 0xF
mov dx, '0'
mov cx, 'A' - 10
cmp bl, 9
cmovg dx, cx
add bl, dl
mov [esp+1], bl
mov eax, 4 ; write
mov ebx, 1 ; stdout
mov edx, 2 ; length
mov ecx, esp ; string
int 0x80
add esp, 4
popad
ret
; input in ESI, len in ECX, all regs unmodified
print_string:
pushad ; save regs
mov eax, 4 ; write
mov ebx, 1 ; stdout
mov edx, ecx ; length
mov ecx, esi ; string
int 0x80
popad ; restore regs
ret
; input in AL, all regs unmodified
print_char:
pushad ; save regs
push eax
mov eax, 4 ; write
mov ebx, 1 ; stdout
mov edx, 1 ; length
mov ecx, esp ; string
int 0x80
add esp, 4
popad ; restore regs
ret
; --- MACROS ---
%define len(x) x %+ .over - x
%macro p_string 1
push esi
push ecx
mov esi, %1
mov ecx, len(%1)
call print_string
pop ecx
pop esi
%endmacro