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 |
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:
High-level Language Programmer's View
main:
maxNum = 3
maxPower = 4
CalculatePowers(maxNum, maxPower)
(*)
. . .
end main
CalculatePowers(In: integer numLimit,
integer powerLimit)
integer num, pow, result
for num := 1 to numLimit do
for pow := 1 to powerLimit do
Power(num, pow, result)
(**) print num " raised to " pow " power is "
result
end for pow
end for num
end CalculatePowers
Power( In: integer n, integer e, Out: result)
if e = 0 then
result = 1
else if e = 1 then
result = n
else
Power(n, e - 1, result)
result = result * n (***)
end if
end Power
1) Trace the next execution of the recursive function Power by showing the run-time stack.
2) What is the most number of call frames on the stack at any one time for the whole program?