I am trying to run this code I have for a project, which is supposed to sort some hexadecimal numbers from least to greatest using the bubblesort algorithm. I went through my code and I don’t really know where there could be any errors even with syntax. I am using the MARIE simulator to run these instructions, along with an online MARIE simulator as well just to make sure it is not a problem with my IDE. Another issue I have with this is that my Assembly Listing tab is completely blank whenever I try to pull up the error with my code. The only thing that it says on my MARIE editor is that I have one error and does not even specify the line. I narrowed it down to my attempt of making an array comprised of hexadecimals, should be line 4 in the code. The online MARIE simulator I use highlights the error on line 4 as well. I also cannot use anything like x86 to try and work this because the project has to be done on MARIE. Please help extremely confused and new to assembly code and how it works with regards to memory location. Here is the prompt:
Write an assembly code in MARIE to sort the following numbers (Hexadecimal) from maximum to minimum.
Numbers (HEX): 5, 35, 75, 45, 85, 25, 95, 55, 15, 65
· You must store given values in the memory in the same order as given and as a hex value.
· You must sort the values and store them in the same memory location where the original values are stored.
· Your code should not ask any input value.
ORG 1000 // Start of memory allocation
// Define variables
NUMBERS, HEX 5, 35, 75, 45, 85, 25, 95, 55, 15, 65
FLAG, DEC 0
// Constants
One, DEC 1
// Start of the program
Main, Load NUMBERS // Load the first number into AC
Store 2000 // Store it in a temporary location for swapping
Add One // Move to next number
Store X // Store the address of the next number
Loop1, Load X // Load the next number into AC
Skipcond 400 // If end of array is reached, exit the loop
Jump EndLoop1 // Jump to end of outer loop if end of array is reached
Load 2000 // Reload the first number into AC
Subt X // Compare the two numbers
Skipcond 800 // If AC is greater than or equal to X, jump
Jump Swap // Jump to swap the numbers
Jump Loop1 // Continue outer loop
Swap, Load X // Load the next number into AC
Store 3000 // Store it in a temporary location
Load 2000 // Load the first number into AC
Store X // Store it in the location of the next number
Load 3000 // Load the next number from the temporary location
Store 2000 // Store it in the location of the first number
Store FLAG // Set flag indicating a swap was made
Jump Loop1 // Continue outer loop
EndLoop1, Load FLAG // Load flag value
Skipcond 400 // If flag is 0 (no swaps), exit outer loop
Jump Main // Otherwise, repeat outer loop
// End of program
Halt // Halt the program
// Variables and constants allocation
X, DEC 0
Line 4 error:
NUMBERS, HEX 5, 35, 75, 45, 85, 25, 95, 55, 15, 65
Tyler Chetty is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.