From c21d7118996ab26143640afcc2ffb8cf9d3d0c37 Mon Sep 17 00:00:00 2001 From: ChillerDragon Date: Thu, 8 Aug 2024 08:32:23 +0800 Subject: [PATCH] Fix bubble sort not dereferencing pointers --- src/huffman/bubble_sort.asm | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/huffman/bubble_sort.asm b/src/huffman/bubble_sort.asm index c978a12..0859888 100644 --- a/src/huffman/bubble_sort.asm +++ b/src/huffman/bubble_sort.asm @@ -51,9 +51,14 @@ _huff_bubble_sort: ; if(ppList[i]->m_Frequency < ppList[i+1]->m_Frequency) ; i frequency mov rbx, rcx - imul rbx, HUFF_CCONSTRUCTION_NODE_SIZE + ; array of pointer offset + imul rbx, 8 + ; ppList[i] + ; r8 is pointer to the construction node + mov r8, [rax + rbx] + ; ppList[i]->m_Frequency mov r10, 0 - mov r10d, [rax + rbx + HUFF_CCONSTRUCTION_NODE_FREQUENCY_OFFSET] + mov r10d, [r8 + HUFF_CCONSTRUCTION_NODE_FREQUENCY_OFFSET] ; ppList[i] = lea rsi, [rax + rbx] mov [rbp-28], rsi @@ -61,9 +66,14 @@ _huff_bubble_sort: ; i+1 frequency mov rbx, rcx inc rbx - imul rbx, HUFF_CCONSTRUCTION_NODE_SIZE + ; array of pointer offset + imul rbx, 8 + ; ppList[i+1] + ; r8 is pointer to the construction node + mov r8, [rax + rbx] + ; ppList[i+1]->m_Frequency mov r11, 0 - mov r11d, [rax + rbx + HUFF_CCONSTRUCTION_NODE_FREQUENCY_OFFSET] + mov r11d, [r8 + HUFF_CCONSTRUCTION_NODE_FREQUENCY_OFFSET] ; ppList[i+1] = lea rsi, [rax + rbx] mov [rbp-20], rsi