Question
CONVERTING HLA PROGRAMMING TO PURE ASSEMBLY I had a previous project that select sorted through an array and ran perfectly, but for this project I'm
CONVERTING HLA PROGRAMMING TO PURE ASSEMBLY
I had a previous project that select sorted through an array and ran perfectly, but for this project I'm supposed to convert that exact code to pure assembly without changing the actual logic (only changing the while/if/for statements). I've looked at this 100 times over and back and I don't know what could be wrong with it but currently my output looks like this when it should have an output like this
Please please help me if you have any idea what might be wrong with my code/how to fix it. I think it has to do with the chunk right after the quitFor but I'm not sure. Thank you so much in advance!
program selectSort;
#include("stdlib.hhf")
const numElements := 17;
static data: int32[numElements] := [ 12, 16, 21, 54, 78, 92, 32, 46, 82, 64, 11, 38, 19, 99, 18, 51, 49 ];
begin selectSort; stdout.put(nl, "Selection Sort, Number of Array Elements: 17 ", nl); stdout.put("Original Array Elements: ", nl); stdout.put(" 12 16 21 54 78 92 32 46 82 64 11 38 19 99 18 51 49 ", nl );
//Tells user the program is starting to sort through the array stdout.newln(); stdout.put("Sorting...", nl);
//References the selectArray mov( &data, esi ); mov( @elements( data ), edi );
//While loop that finds the largest number and moves to the last element. //The last element is switched with the largest number's place and this repeats, //except instead of last element, it's stored to second last, third to last, etc.
startWhile: cmp(edi, 0); //Compare the terms jna quitWhile; //Quit while if comparison is wrong mov(0, edx); //Otherwise set edx to 0
mov(0, ecx); //Set exc to 0 to create a for loop
startFor: cmp(ecx, edi); //Compare the terms jnb quitFor; //Quite for if comparison is wrong mov( [esi+edx*4], eax ); //Otherwise execute this line
cmp( [esi+ecx*4], eax); //Compares the terms jnae quitIf; //Quit if only if comparison is wrong mov( ecx, edx ); //Set edx to ecx
inc(ecx); //Increase ecx value jmp startFor; //Redo for loop
quitIf:
quitFor: dec(edi); //Decrement edi mov([esi+edi*4], eax); //Code assigning values mov([esi+edx*4], ebx); mov(ebx, [esi+edi*4]); mov(eax, [esi+edx*4]);
mov(0, ebx); //Set ebx value to 0
startFor2: cmp(ebx, numElements); //Compare the terms jnb quitFor2; //EndFor2 if comparison is wrong stdout.puti32Size(data[ebx * 4], 4, ' ');
inc(ebx); //Increment ebx jmp startFor2; //Loops through startFor2
quitFor2: stdout.put(nl); jmp startWhile;
quitWhile:
end selectSort;
Original Array Elements: 12 16 21 54 78 923246 82 64 11 38 19 9918 51 49 Sorting... 12 16 21 54 78 493246 82 64 11 38 19 9918 51 92 12 16 21 54 51 493246 82 64 11 38 19 9918 78 92 12 16 21 18 51 493246 82 64 11 38 19 9954 78 92 12 16 9918 51 493246 82 64 11 38 19 21 54 78 92 12 16 19 18 51 493246 82 64 11 38 99 21 54 78 92 12 16 38 18 51 493246 82 64 11 19 9921 54 78 92 12 16 11 18 51 493246 82 64 38 19 9921 54 78 92 12 64 11 18 51 493246 82 16 38 19 9921 54 78 92 12 82 11 18 51 493246 64 16 38 19 9921 54 78 92 12 46 11 18 51 4932 82 64 16 38 19 9921 54 78 92 12 32 11 18 51 4946 82 64 16 38 19 9921 54 78 92 12 49 11 18 51 32 46 82 64 16 38 19 9921 54 78 92 12 51 11 18 49 3246 82 64 16 38 19 9921 54 78 92 12 18 11 51 49 3246 82 64 16 38 19 9921 54 78 92 12 11 18 51 49 3246 82 64 16 38 19 9921 54 78 92 11 12 18 51 49 3246 82 64 16 38 19 9921 54 78 92 11 12 18 51 49 3246 82 64 16 38 19 9921 54 78 92 Original Array Elements: 12 16 21 54 78 923246 82 64 11 38 19 9918 51 49 Sorting... 12 16 21 54 78 493246 82 64 11 38 19 9918 51 92 12 16 21 54 51 493246 82 64 11 38 19 9918 78 92 12 16 21 18 51 493246 82 64 11 38 19 9954 78 92 12 16 9918 51 493246 82 64 11 38 19 21 54 78 92 12 16 19 18 51 493246 82 64 11 38 99 21 54 78 92 12 16 38 18 51 493246 82 64 11 19 9921 54 78 92 12 16 11 18 51 493246 82 64 38 19 9921 54 78 92 12 64 11 18 51 493246 82 16 38 19 9921 54 78 92 12 82 11 18 51 493246 64 16 38 19 9921 54 78 92 12 46 11 18 51 4932 82 64 16 38 19 9921 54 78 92 12 32 11 18 51 4946 82 64 16 38 19 9921 54 78 92 12 49 11 18 51 32 46 82 64 16 38 19 9921 54 78 92 12 51 11 18 49 3246 82 64 16 38 19 9921 54 78 92 12 18 11 51 49 3246 82 64 16 38 19 9921 54 78 92 12 11 18 51 49 3246 82 64 16 38 19 9921 54 78 92 11 12 18 51 49 3246 82 64 16 38 19 9921 54 78 92 11 12 18 51 49 3246 82 64 16 38 19 9921 54 78 92Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started