Type of Instruction Assembly Language Register Transfer Language

Description

Memory Access

(Load and Store)

lw $4, Mem
sw $4, Mem Mem$4
lw $4, 16($3)
sw $4, Mem  
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
mul $10, $12, $8 $10 $12 * $8 (32-bit product)
sub $4, $2, $3 $4 $2 - $3
Arithmetic with Immediates

(last operand must be an integer)

addi $4, $2, 100 $4 $2 + 100
mul $4, $2, 100 $4 $2 * 100 (32-bit product)
Conditional Branch bgt $4, $2, LABEL Branch to LABEL if $4 > $2
Unconditional Branch j LABEL Always Branch to LABEL

sum = 0;

for i = 0 to length-1 do sum = sum + numbers[i] end for

1. Write MIPS Assembly Language code for the above algorithm that sums the array's elements.

.data numbers: .word 20, 30, 10, 40, 50, 60, 30, 25, 10, 5 length: .word 10 .text .globl main

main: 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

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

.data numbers: .word 20, 30, 10, 40, 50, 60, 30, 25, 10, 5 length: .word 10 .text .globl main main: