day 4 part 2
This commit is contained in:
parent
0f255d93a1
commit
1b8ebe2ba9
60
04/main.s
60
04/main.s
@ -18,7 +18,7 @@ add eax, read_buff
|
|||||||
mov [file_lim], eax
|
mov [file_lim], eax
|
||||||
mov byte [eax], 10 ; add a newline at the end
|
mov byte [eax], 10 ; add a newline at the end
|
||||||
|
|
||||||
; 1. get to :, checking for file_lim
|
; 1. get number, save in id, checking for file_lim
|
||||||
; 2. repeat WINNING_COUNT times
|
; 2. repeat WINNING_COUNT times
|
||||||
; get the next number
|
; get the next number
|
||||||
; record in winning list
|
; record in winning list
|
||||||
@ -27,19 +27,24 @@ mov byte [eax], 10 ; add a newline at the end
|
|||||||
; get the next number
|
; get the next number
|
||||||
; check against the winning list
|
; check against the winning list
|
||||||
; if match then
|
; if match then
|
||||||
; shl points, 1
|
; increment matches
|
||||||
; cmovz points, 1 ???
|
|
||||||
; end
|
; end
|
||||||
; end
|
; end
|
||||||
; 4. add to final value
|
; 4. add copies + 1 (original) to final value
|
||||||
; 5. goto 1
|
; 5. repeat while copies > 0
|
||||||
|
; tmp := id + 1
|
||||||
|
; repeat matches times
|
||||||
|
; increment copies_list@tmp
|
||||||
|
; increment tmp
|
||||||
|
; end
|
||||||
|
; end
|
||||||
|
; 6. goto 1
|
||||||
|
|
||||||
mov esi, read_buff
|
mov esi, read_buff
|
||||||
; 1. get to :, checking for file_lim
|
; 1. get number, save in id, checking for file_lim
|
||||||
find_colon:
|
find_colon:
|
||||||
lodsb
|
call dec_parse
|
||||||
cmp al, ':'
|
jnc start_round
|
||||||
je start_round
|
|
||||||
cmp esi, [file_lim]
|
cmp esi, [file_lim]
|
||||||
jge game_over
|
jge game_over
|
||||||
jmp find_colon
|
jmp find_colon
|
||||||
@ -49,6 +54,7 @@ jmp find_colon
|
|||||||
; record in winning list
|
; record in winning list
|
||||||
; end
|
; end
|
||||||
start_round:
|
start_round:
|
||||||
|
push eax ; save game id
|
||||||
mov ecx, WINNING_COUNT
|
mov ecx, WINNING_COUNT
|
||||||
.get_next_number:
|
.get_next_number:
|
||||||
call dec_parse
|
call dec_parse
|
||||||
@ -61,12 +67,11 @@ loop .get_next_number
|
|||||||
; get the next number
|
; get the next number
|
||||||
; check against the winning list
|
; check against the winning list
|
||||||
; if match then
|
; if match then
|
||||||
; shl points, 1
|
; increment matches
|
||||||
; cmovz points, 1 ???
|
|
||||||
; end
|
; end
|
||||||
; end
|
; end
|
||||||
check_wins:
|
check_wins:
|
||||||
xor ebx, ebx ; points
|
xor ebx, ebx ; matches
|
||||||
.get_next_number:
|
.get_next_number:
|
||||||
call dec_parse
|
call dec_parse
|
||||||
jc .get_next_number
|
jc .get_next_number
|
||||||
@ -77,8 +82,7 @@ mov edx, 1
|
|||||||
cmp [(winning_list-4)+ecx*4], eax
|
cmp [(winning_list-4)+ecx*4], eax
|
||||||
jne .continue
|
jne .continue
|
||||||
; matched!
|
; matched!
|
||||||
shl ebx, 1
|
inc ebx
|
||||||
cmovz ebx, edx
|
|
||||||
.continue:
|
.continue:
|
||||||
loop .check_winning
|
loop .check_winning
|
||||||
; check for \n
|
; check for \n
|
||||||
@ -86,8 +90,31 @@ dec esi
|
|||||||
lodsb
|
lodsb
|
||||||
cmp al, 10 ; \n
|
cmp al, 10 ; \n
|
||||||
jne .get_next_number
|
jne .get_next_number
|
||||||
; round done
|
|
||||||
add dword [final_value], ebx ; round points
|
; 4. add copies + 1 (original) to final value
|
||||||
|
pop edx ; game id
|
||||||
|
mov eax, [copies_list+edx*4]
|
||||||
|
inc eax ; copies+1
|
||||||
|
add [final_value], eax
|
||||||
|
|
||||||
|
; if there's no matches, skip 5
|
||||||
|
test ebx, ebx
|
||||||
|
jz find_colon ; restart
|
||||||
|
|
||||||
|
; 5. tmp := id + 1
|
||||||
|
; repeat matches times
|
||||||
|
; copies_list@tmp += instances
|
||||||
|
; increment tmp
|
||||||
|
; end
|
||||||
|
add_copies:
|
||||||
|
inc edx ; tmp
|
||||||
|
mov ecx, ebx ; matches
|
||||||
|
.loop:
|
||||||
|
add [copies_list+edx*4], eax ; instances
|
||||||
|
inc edx
|
||||||
|
loop .loop
|
||||||
|
|
||||||
|
; 6. goto 1
|
||||||
jmp find_colon ; restart
|
jmp find_colon ; restart
|
||||||
|
|
||||||
; print everything out
|
; print everything out
|
||||||
@ -103,4 +130,5 @@ filename: db "input",0
|
|||||||
|
|
||||||
[section .bss]
|
[section .bss]
|
||||||
winning_list: resd WINNING_COUNT
|
winning_list: resd WINNING_COUNT
|
||||||
|
copies_list: resd 256
|
||||||
read_buff: resb BUFF_LIM
|
read_buff: resb BUFF_LIM
|
||||||
|
106
04/main_part1.s
Normal file
106
04/main_part1.s
Normal file
@ -0,0 +1,106 @@
|
|||||||
|
%define BUFF_LIM 32768
|
||||||
|
|
||||||
|
%define WINNING_COUNT 10
|
||||||
|
|
||||||
|
global _start
|
||||||
|
[bits 32]
|
||||||
|
[section .text]
|
||||||
|
|
||||||
|
%include "utils.s"
|
||||||
|
|
||||||
|
_start:
|
||||||
|
mov ebx, filename
|
||||||
|
call open_file
|
||||||
|
mov ecx, read_buff
|
||||||
|
mov edx, BUFF_LIM
|
||||||
|
call read_file
|
||||||
|
add eax, read_buff
|
||||||
|
mov [file_lim], eax
|
||||||
|
mov byte [eax], 10 ; add a newline at the end
|
||||||
|
|
||||||
|
; 1. get to :, checking for file_lim
|
||||||
|
; 2. repeat WINNING_COUNT times
|
||||||
|
; get the next number
|
||||||
|
; record in winning list
|
||||||
|
; end
|
||||||
|
; 3. repeat until \n
|
||||||
|
; get the next number
|
||||||
|
; check against the winning list
|
||||||
|
; if match then
|
||||||
|
; shl points, 1
|
||||||
|
; cmovz points, 1 ???
|
||||||
|
; end
|
||||||
|
; end
|
||||||
|
; 4. add to final value
|
||||||
|
; 5. goto 1
|
||||||
|
|
||||||
|
mov esi, read_buff
|
||||||
|
; 1. get to :, checking for file_lim
|
||||||
|
find_colon:
|
||||||
|
lodsb
|
||||||
|
cmp al, ':'
|
||||||
|
je start_round
|
||||||
|
cmp esi, [file_lim]
|
||||||
|
jge game_over
|
||||||
|
jmp find_colon
|
||||||
|
|
||||||
|
; 2. repeat WINNING_COUNT times
|
||||||
|
; get the next number
|
||||||
|
; record in winning list
|
||||||
|
; end
|
||||||
|
start_round:
|
||||||
|
mov ecx, WINNING_COUNT
|
||||||
|
.get_next_number:
|
||||||
|
call dec_parse
|
||||||
|
jc .get_next_number
|
||||||
|
; record in list (backward since loop)
|
||||||
|
mov [(winning_list-4)+ecx*4], eax
|
||||||
|
loop .get_next_number
|
||||||
|
|
||||||
|
; 3. repeat until \n
|
||||||
|
; get the next number
|
||||||
|
; check against the winning list
|
||||||
|
; if match then
|
||||||
|
; shl points, 1
|
||||||
|
; cmovz points, 1 ???
|
||||||
|
; end
|
||||||
|
; end
|
||||||
|
check_wins:
|
||||||
|
xor ebx, ebx ; points
|
||||||
|
.get_next_number:
|
||||||
|
call dec_parse
|
||||||
|
jc .get_next_number
|
||||||
|
; check against winning list
|
||||||
|
mov ecx, WINNING_COUNT
|
||||||
|
mov edx, 1
|
||||||
|
.check_winning:
|
||||||
|
cmp [(winning_list-4)+ecx*4], eax
|
||||||
|
jne .continue
|
||||||
|
; matched!
|
||||||
|
shl ebx, 1
|
||||||
|
cmovz ebx, edx
|
||||||
|
.continue:
|
||||||
|
loop .check_winning
|
||||||
|
; check for \n
|
||||||
|
dec esi
|
||||||
|
lodsb
|
||||||
|
cmp al, 10 ; \n
|
||||||
|
jne .get_next_number
|
||||||
|
; round done
|
||||||
|
add dword [final_value], ebx ; round points
|
||||||
|
jmp find_colon ; restart
|
||||||
|
|
||||||
|
; print everything out
|
||||||
|
game_over:
|
||||||
|
mov eax, [final_value]
|
||||||
|
call print_dec
|
||||||
|
jmp exit
|
||||||
|
|
||||||
|
[section .data]
|
||||||
|
file_lim: dd 0
|
||||||
|
final_value: dd 0
|
||||||
|
filename: db "input",0
|
||||||
|
|
||||||
|
[section .bss]
|
||||||
|
winning_list: resd WINNING_COUNT
|
||||||
|
read_buff: resb BUFF_LIM
|
Loading…
Reference in New Issue
Block a user