Lab 0
Lab 0
Assignment 3:
As we can see in the data segment, Memory Locations Before Sorting (Initial Array)
• 0x10010000: 0x00000007 → 7
• 0x10010004: 0xFFFFFFFE → -2 (as a signed integer)
• 0x10010008: 0x00000005 → 5
• 0x1001000C: 0x00000001 → 1
• 0x10010010: 0x00000006 → 6
This represents the original unsorted array: [7, -2, 5, 1, 6].
Program Output: The program sorts the input array. In this case, it sorts [7, -2, 5, 1, 6] into [-2, 1,
5, 6, 7].
Data Segment After Sorting: Check memory starting at 0x10010000. After sorting, these memory
locations will hold the sorted array values.
Registers: As the program runs, registers like t4 and t5 will show which elements are being
compared and swapped. You can track the sorting process by looking at these registers.
Assignment 4:
Key Sections:
1. Data Section:
o Strings like "Iteration", space, newline are stored.
o The array A (to be sorted) is defined.
2. Main Section:
o Initializes pointers to the array (a0, a1, a2), iteration counter (a3), and a flag (t5 to
track if sorting is complete).
o Jumps to the insertion_sort section.
3. Insertion Sort:
o Compares and inserts elements like in the insertion sort algorithm.
o Inner while loop shifts elements to the right if necessary.
o The sorted element is inserted back when correct.
4. Print Phase:
o After every iteration, the array is printed.
o Each element is printed followed by a space. After printing the whole array, a
newline is printed.
o The program checks if sorting is complete; if yes, it ends, otherwise it continues
sorting.