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

integer 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

2) Trace the execution of the recursive function Power by showing the run-time stack.

3) What is the most number of call frames on the stack for the whole program?

Addressing Mode Assembler Syntax Example Addressing Function
Immediate #55 Operand is the Value
Register R2 Operand is [R2]
Absolute/Direct MEM EA = LOC
Indirect (R2) EA = [R2]
Index 4(R2) EA = [R2] + 4
PC Relative 4(PC) EA = [PC] + 4
Base with Index (R2, R3) EA = [R2] + [R3]
Base with Index and Offset 4(R2, R3) EA = [R2] + [R3] + 4
Autoincrement (R2)+ EA = [R2], then increment R2
Autodecrement -(R2) Decrement R2, then EA = [R2]

  Register File     Memory
R0:     (Label X:) 0 4
R1: 16   4 5
R2: 17   8 6
R3: 18   12 7
R4: 19   16 8
R5: 20   20 9
R6: 21   24 10
      28 11
      32 12
      36 13
PC: 36   40 14

1) What value would get moved into register R0 in each of the following?

a) Move R0, #32

b) Move R0, X

c) Move R0, (R1)

c2) Move R0, (X)

d) Move R0, 4(R5)

e) Move R0, 4(PC)

f) Move R0, (R1, R5)

g) Move R0, 4(R1, R5)

h) Move R0, (R5)+

i) Move R0, -(R6)