integer firstUnsortedIndex, testIndex, elementToInsert;

for firstUnsortedIndex = 1 to (length-1) do

testIndex = firstUnsortedIndex-1;

elementToInsert = numbers[firstUnsortedIndex];

while (testIndex >=0) AND (numbers[testIndex] > elementToInsert ) do

numbers[ testIndex + 1 ] = numbers[ testIndex ];

testIndex = testIndex - 1;
end while

numbers[ testIndex + 1 ] = elementToInsert;

end for

1. Write MIPS Assembly Language code for the above insertion sort algorithm

Type of Instruction Assembly Language Register Transfer Language

Description

Memory Access

(Load and Store)

lw $4, Mem
sw $4, Mem Mem$4
Move move $4, $2 $4 $2
li $4, 100 $4 100
Load Address la $5, mem $4 load address of mem
Arithmetic Instruction

(reg. operands only)

add $4, $2, $3 $4 $2 + $3
addi $4, $2, 100 $4 $2 + 100
mul $10, $12, $8 $10 $12 * $8
sub $4, $2, $3 $4 $2 - $3
Conditional Branch bgt $4, $2, LABEL Branch to LABEL if $4 > $2
Unconditional Branch j LABEL Always Branch to LABEL

.data

numbers: .word 20, 30, 10, 40, 50, 60, 30, 25, 10, 5

length: .word 10

.text

.globl main

main: