From b1921a765652577910710c149d45ea182540a0e5 Mon Sep 17 00:00:00 2001 From: Lucia Ceionia Date: Sun, 3 Dec 2023 02:52:09 -0600 Subject: [PATCH] day 3 part 2 --- 03/input_test2 | 10 +++++++ 03/main.s | 80 ++++++++++++++++++++++++++++---------------------- 2 files changed, 55 insertions(+), 35 deletions(-) create mode 100644 03/input_test2 diff --git a/03/input_test2 b/03/input_test2 new file mode 100644 index 0000000..b20187f --- /dev/null +++ b/03/input_test2 @@ -0,0 +1,10 @@ +467..114.. +...*...... +..35..633. +......#... +617*...... +.....+.58. +..592..... +......755. +...$.*.... +.664.598.. diff --git a/03/main.s b/03/main.s index ebd7b7f..aa45570 100644 --- a/03/main.s +++ b/03/main.s @@ -87,7 +87,10 @@ add esp, 4 ; no more cur num idx ; 3. go through array, checking the neighbors of ; numbers for symbols, skip *last added index*, -; adding numbers with sym neighbors to final_value +; if has * as neighbor, replace the index of the * +; with the current number index if it has no index currently, +; otherwise multiply by the number its index points to +; and add to final_value, setting last added index to current index check_neighbors: xor ecx, ecx ; index dec ecx ; gets incremented immediately @@ -110,53 +113,60 @@ je .check_next_number ; is last added idx, skip .check_symbols: lea edx, [ecx+array] ; current char ; right -cmp byte [edx+1], '.' -je .r_nsym -jmp .has_sym_neighbor -.r_nsym: +lea ebp, [ecx+1] +cmp byte [edx+1], '*' +je .has_sym_neighbor ; left -cmp byte [edx-1], '.' -je .l_nsym -jmp .has_sym_neighbor -.l_nsym: +lea ebp, [ecx-1] +cmp byte [edx-1], '*' +je .has_sym_neighbor ; top -cmp byte [edx-(GRID_X+2)], '.' -je .t_nsym -jmp .has_sym_neighbor -.t_nsym: +lea ebp, [ecx-(GRID_X+2)] +cmp byte [edx-(GRID_X+2)], '*' +je .has_sym_neighbor ; bottom -cmp byte [edx+(GRID_X+2)], '.' -je .b_nsym -jmp .has_sym_neighbor -.b_nsym: +lea ebp, [ecx+(GRID_X+2)] +cmp byte [edx+(GRID_X+2)], '*' +je .has_sym_neighbor ; top left -cmp byte [edx-((GRID_X+2)+1)], '.' -je .tl_nsym -jmp .has_sym_neighbor -.tl_nsym: +lea ebp, [ecx-((GRID_X+2)+1)] +cmp byte [edx-((GRID_X+2)+1)], '*' +je .has_sym_neighbor ; top right -cmp byte [edx-((GRID_X+2)-1)], '.' -je .tr_nsym -jmp .has_sym_neighbor -.tr_nsym: +lea ebp, [ecx-((GRID_X+2)-1)] +cmp byte [edx-((GRID_X+2)-1)], '*' +je .has_sym_neighbor ; bottom left -cmp byte [edx+((GRID_X+2)-1)], '.' -je .bl_nsym -jmp .has_sym_neighbor -.bl_nsym: +lea ebp, [ecx+((GRID_X+2)-1)] +cmp byte [edx+((GRID_X+2)-1)], '*' +je .has_sym_neighbor ; bottom right -cmp byte [edx+((GRID_X+2)+1)], '.' -je .br_nsym -jmp .has_sym_neighbor -.br_nsym: +lea ebp, [ecx+((GRID_X+2)+1)] +cmp byte [edx+((GRID_X+2)+1)], '*' +je .has_sym_neighbor ; there's no symbol neighbor ; get next number jmp .check_next_number .has_sym_neighbor: ; we have a symbol neighbor! +; get its id +movzx edx, word [index+ebp*2] +test edx, edx +jz .no_sym_number ; * doesn't have a number assigned yet +; multiply by its number! +pushad ; out of registers lol +mov eax, [numbers+eax*4] ; our number +mul dword [numbers+edx*4] ; * number ; add to final value -mov edx, [numbers+eax*4] -add [final_value], edx +add [final_value], eax +popad ; get back values :3 +; set last added idx +mov ebx, eax +; get next number +jmp .check_next_number +.no_sym_number: +; save our index in the * index +mov [index+ebp*2], ax ; set last added idx mov ebx, eax ; get next number