SlideShare ist ein Scribd-Unternehmen logo
1 von 56
main 
factorial 
store 
to stack 
recursive case 
load 
from stack 
base 
case 
Trace what happens for an input of 3... 
r1 
r13 
r14 
CPU Registers Memory 
100 
101 
102 
103 
104 
105 
r15 
"the stack" 
input: x 
return value (the "result") 
return address (line #) 
the stack pointer 
00 read r1 
01 setn r15 100 
02 call r14 06 
03 write r13 
04 halt 
05 nop 
06 jnez r1 09 
07 setn r13 1 
08 jumpr r14 
09 addn r15 1 
10 storer r1 r15 
11 addn r15 1 
12 storer r14 r15 
13 addn r1 -1 
14 call r14 06 
15 loadr r14 r15 
16 addn r15 -1 
17 loadr r1 r15 
18 addn r15 -1 
19 mul r13 r13 r1 
20 jumpr r14 
106 
107 
It's easy to get lost! 
Follow the line numbers below to stay on track... 
0, 1, 2, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 7, 8, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 3, 4
main 
factorial 
store 
to stack 
recursive case 
load 
from stack 
base 
case 
Trace what happens for an input of 3... 
r1 3 
r13 
r14 
CPU Registers Memory 
100 
101 
102 
103 
104 
105 
r15 
"the stack" 
input: x 
return value (the "result") 
return address (line #) 
the stack pointer 
00 read r1 
01 setn r15 100 
02 call r14 06 
03 write r13 
04 halt 
05 nop 
06 jnez r1 09 
07 setn r13 1 
08 jumpr r14 
09 addn r15 1 
10 storer r1 r15 
11 addn r15 1 
12 storer r14 r15 
13 addn r1 -1 
14 call r14 06 
15 loadr r14 r15 
16 addn r15 -1 
17 loadr r1 r15 
18 addn r15 -1 
19 mul r13 r13 r1 
20 jumpr r14 
106 
107 
It's easy to get lost! 
Follow the line numbers below to stay on track... 
0, 1, 2, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 7, 8, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 3, 4
main 
factorial 
store 
to stack 
recursive case 
load 
from stack 
base 
case 
Trace what happens for an input of 3... 
r1 3 
r13 
r14 
CPU Registers Memory 
100 
101 
102 
103 
104 
105 
r15 100 
"the stack" 
input: x 
return value (the "result") 
return address (line #) 
the stack pointer 
r15 
00 read r1 
01 setn r15 100 
02 call r14 06 
03 write r13 
04 halt 
05 nop 
06 jnez r1 09 
07 setn r13 1 
08 jumpr r14 
09 addn r15 1 
10 storer r1 r15 
11 addn r15 1 
12 storer r14 r15 
13 addn r1 -1 
14 call r14 06 
15 loadr r14 r15 
16 addn r15 -1 
17 loadr r1 r15 
18 addn r15 -1 
19 mul r13 r13 r1 
20 jumpr r14 
106 
107 
It's easy to get lost! 
Follow the line numbers below to stay on track... 
0, 1, 2, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 7, 8, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 3, 4
main 
factorial 
store 
to stack 
recursive case 
load 
from stack 
base 
case 
Trace what happens for an input of 3... 
3 
CPU Registers Memory 
??? 
r1 
r13 
r14 
100 
101 
102 
103 
104 
105 
r15 100 
"the stack" 
input: x 
return value (the "result") 
return address (line #) 
the stack pointer 
r15 
00 read r1 
01 setn r15 100 
02 call r14 06 
03 write r13 
04 halt 
05 nop 
06 jnez r1 09 
07 setn r13 1 
08 jumpr r14 
09 addn r15 1 
10 storer r1 r15 
11 addn r15 1 
12 storer r14 r15 
13 addn r1 -1 
14 call r14 06 
15 loadr r14 r15 
16 addn r15 -1 
17 loadr r1 r15 
18 addn r15 -1 
19 mul r13 r13 r1 
20 jumpr r14 
106 
107 
It's easy to get lost! 
Follow the line numbers below to stay on track... 
0, 1, 2, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 7, 8, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 3, 4
main 
factorial 
store 
to stack 
recursive case 
load 
from stack 
base 
case 
Trace what happens for an input of 3... 
3 
03 
r1 
r13 
r14 
CPU Registers Memory 
100 
101 
102 
103 
104 
105 
r15 100 
"the stack" 
input: x 
return value (the "result") 
return address (line #) 
the stack pointer 
r15 
00 read r1 
01 setn r15 100 
02 call r14 06 
03 write r13 
04 halt 
05 nop 
06 jnez r1 09 
07 setn r13 1 
08 jumpr r14 
09 addn r15 1 
10 storer r1 r15 
11 addn r15 1 
12 storer r14 r15 
13 addn r1 -1 
14 call r14 06 
15 loadr r14 r15 
16 addn r15 -1 
17 loadr r1 r15 
18 addn r15 -1 
19 mul r13 r13 r1 
20 jumpr r14 
106 
107 
It's easy to get lost! 
Follow the line numbers below to stay on track... 
0, 1, 2, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 7, 8, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 3, 4
main 
factorial 
store 
to stack 
recursive case 
load 
from stack 
base 
case 
Trace what happens for an input of 3... 
3 
03 
r1 
r13 
r14 
CPU Registers Memory 
100 
101 
102 
103 
104 
105 
r15 100 
"the stack" 
input: x 
return value (the "result") 
return address (line #) 
the stack pointer 
r15 
00 read r1 
01 setn r15 100 
02 call r14 06 
03 write r13 
04 halt 
05 nop 
06 jnez r1 09 
07 setn r13 1 
08 jumpr r14 
09 addn r15 1 
10 storer r1 r15 
11 addn r15 1 
12 storer r14 r15 
13 addn r1 -1 
14 call r14 06 
15 loadr r14 r15 
16 addn r15 -1 
17 loadr r1 r15 
18 addn r15 -1 
19 mul r13 r13 r1 
20 jumpr r14 
106 
107 
It's easy to get lost! 
Follow the line numbers below to stay on track... 
0, 1, 2, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 7, 8, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 3, 4
main 
factorial 
store 
to stack 
recursive case 
load 
from stack 
base 
case 
Trace what happens for an input of 3... 
3 
03 
r1 
r13 
r14 
CPU Registers Memory 
100 
101 
102 
103 
104 
105 
r15 100 
"the stack" 
input: x 
return value (the "result") 
return address (line #) 
the stack pointer 
r15 
00 read r1 
01 setn r15 100 
02 call r14 06 
03 write r13 
04 halt 
05 nop 
06 jnez r1 09 
07 setn r13 1 
08 jumpr r14 
09 addn r15 1 
10 storer r1 r15 
11 addn r15 1 
12 storer r14 r15 
13 addn r1 -1 
14 call r14 06 
15 loadr r14 r15 
16 addn r15 -1 
17 loadr r1 r15 
18 addn r15 -1 
19 mul r13 r13 r1 
20 jumpr r14 
106 
107 
It's easy to get lost! 
Follow the line numbers below to stay on track... 
0, 1, 2, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 7, 8, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 3, 4
main 
factorial 
store 
to stack 
recursive case 
load 
from stack 
base 
case 
Trace what happens for an input of 3... 
3 
03 
r1 
r13 
r14 
CPU Registers Memory 
100 
101 
102 
103 
104 
105 
r15 100 
"the stack" 
input: x 
return value (the "result") 
return address (line #) 
the stack pointer 
r15 
00 read r1 
01 setn r15 100 
02 call r14 06 
03 write r13 
04 halt 
05 nop 
06 jnez r1 09 
07 setn r13 1 
08 jumpr r14 
09 addn r15 1 
10 storer r1 r15 
11 addn r15 1 
12 storer r14 r15 
13 addn r1 -1 
14 call r14 06 
15 loadr r14 r15 
16 addn r15 -1 
17 loadr r1 r15 
18 addn r15 -1 
19 mul r13 r13 r1 
20 jumpr r14 
106 
107 
It's easy to get lost! 
Follow the line numbers below to stay on track... 
0, 1, 2, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 7, 8, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 3, 4
main 
factorial 
store 
to stack 
recursive case 
load 
from stack 
base 
case 
Trace what happens for an input of 3... 
3 
03 
r1 
r13 
r14 
CPU Registers Memory 
100 
101 
102 
103 
104 
105 
r15 100,101 
"the stack" 
input: x 
return value (the "result") 
return address (line #) 
the stack pointer 
r15 
00 read r1 
01 setn r15 100 
02 call r14 06 
03 write r13 
04 halt 
05 nop 
06 jnez r1 09 
07 setn r13 1 
08 jumpr r14 
09 addn r15 1 
10 storer r1 r15 
11 addn r15 1 
12 storer r14 r15 
13 addn r1 -1 
14 call r14 06 
15 loadr r14 r15 
16 addn r15 -1 
17 loadr r1 r15 
18 addn r15 -1 
19 mul r13 r13 r1 
20 jumpr r14 
106 
107 
It's easy to get lost! 
Follow the line numbers below to stay on track... 
0, 1, 2, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 7, 8, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 3, 4
main 
factorial 
store 
to stack 
recursive case 
load 
from stack 
base 
case 
Trace what happens for an input of 3... 
3 
03 
r1 
r13 
r14 
CPU Registers Memory 
100 
101 
102 
103 
104 
105 
r15 100,101 
"the stack" 
input: x 
return value (the "result") 
return address (line #) 
the stack pointer 
r15 
00 read r1 
01 setn r15 100 
02 call r14 06 
03 write r13 
04 halt 
05 nop 
06 jnez r1 09 
07 setn r13 1 
08 jumpr r14 
09 addn r15 1 
10 storer r1 r15 
11 addn r15 1 
12 storer r14 r15 
13 addn r1 -1 
14 call r14 06 
15 loadr r14 r15 
16 addn r15 -1 
17 loadr r1 r15 
18 addn r15 -1 
19 mul r13 r13 r1 
20 jumpr r14 
106 
107 
It's easy to get lost! 
Follow the line numbers below to stay on track... 
0, 1, 2, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 7, 8, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 3, 4
main 
factorial 
store 
to stack 
recursive case 
load 
from stack 
base 
case 
Trace what happens for an input of 3... 
3 
03 
r1 
r13 
r14 
CPU Registers Memory 
3 
100 
101 
102 
103 
104 
105 
r15 100,101 
"the stack" 
input: x 
return value (the "result") 
return address (line #) 
the stack pointer 
r15 
00 read r1 
01 setn r15 100 
02 call r14 06 
03 write r13 
04 halt 
05 nop 
06 jnez r1 09 
07 setn r13 1 
08 jumpr r14 
09 addn r15 1 
10 storer r1 r15 
11 addn r15 1 
12 storer r14 r15 
13 addn r1 -1 
14 call r14 06 
15 loadr r14 r15 
16 addn r15 -1 
17 loadr r1 r15 
18 addn r15 -1 
19 mul r13 r13 r1 
20 jumpr r14 
106 
107 
It's easy to get lost! 
Follow the line numbers below to stay on track... 
0, 1, 2, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 7, 8, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 3, 4
main 
factorial 
store 
to stack 
recursive case 
load 
from stack 
base 
case 
Trace what happens for an input of 3... 
3 
03 
r1 
r13 
r14 
CPU Registers Memory 
3 
100 
101 
102 
103 
104 
105 
r15 100,101,102 
"the stack" 
input: x 
return value (the "result") 
return address (line #) 
the stack pointer 
r15 
00 read r1 
01 setn r15 100 
02 call r14 06 
03 write r13 
04 halt 
05 nop 
06 jnez r1 09 
07 setn r13 1 
08 jumpr r14 
09 addn r15 1 
10 storer r1 r15 
11 addn r15 1 
12 storer r14 r15 
13 addn r1 -1 
14 call r14 06 
15 loadr r14 r15 
16 addn r15 -1 
17 loadr r1 r15 
18 addn r15 -1 
19 mul r13 r13 r1 
20 jumpr r14 
106 
107 
It's easy to get lost! 
Follow the line numbers below to stay on track... 
0, 1, 2, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 7, 8, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 3, 4
main 
factorial 
store 
to stack 
recursive case 
load 
from stack 
base 
case 
Trace what happens for an input of 3... 
3 
03 
r1 
r13 
r14 
CPU Registers Memory 
3 
03 
100 
101 
102 
103 
104 
105 
r15 100,101,102 
"the stack" 
input: x 
return value (the "result") 
return address (line #) 
the stack pointer 
00 read r1 
01 setn r15 100 
02 call r14 06 
03 write r13 
04 halt 
05 nop 
06 jnez r1 09 
07 setn r13 1 
08 jumpr r14 
09 addn r15 1 
10 storer r1 r15 
11 addn r15 1 
12 storer r14 r15 
13 addn r1 -1 
14 call r14 06 
15 loadr r14 r15 
16 addn r15 -1 
17 loadr r1 r15 
18 addn r15 -1 
19 mul r13 r13 r1 
20 jumpr r14 
106 
107 
It's easy to get lost! 
Follow the line numbers below to stay on track... 
r15 
0, 1, 2, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 7, 8, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 3, 4
main 
factorial 
store 
to stack 
recursive case 
load 
from stack 
base 
case 
Trace what happens for an input of 3... 
CPU Registers Memory 
3, 2 
03 
r1 
r13 
r14 
3 
03 
100 
101 
102 
103 
104 
105 
r15 100,101,102 
"the stack" 
input: x 
return value (the "result") 
return address (line #) 
the stack pointer 
00 read r1 
01 setn r15 100 
02 call r14 06 
03 write r13 
04 halt 
05 nop 
06 jnez r1 09 
07 setn r13 1 
08 jumpr r14 
09 addn r15 1 
10 storer r1 r15 
11 addn r15 1 
12 storer r14 r15 
13 addn r1 -1 
14 call r14 06 
15 loadr r14 r15 
16 addn r15 -1 
17 loadr r1 r15 
18 addn r15 -1 
19 mul r13 r13 r1 
20 jumpr r14 
106 
107 
It's easy to get lost! 
Follow the line numbers below to stay on track... 
r15 
0, 1, 2, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 7, 8, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 3, 4
main 
factorial 
store 
to stack 
recursive case 
load 
from stack 
base 
case 
Trace what happens for an input of 3... 
CPU Registers Memory 
3,2 
03 
r1 
r13 
r14 
3 
03 
100 
101 
102 
103 
104 
105 
r15 100,101,102 
"the stack" 
input: x 
return value (the "result") 
return address (line #) 
the stack pointer 
00 read r1 
01 setn r15 100 
02 call r14 06 
03 write r13 
04 halt 
05 nop 
06 jnez r1 09 
07 setn r13 1 
08 jumpr r14 
09 addn r15 1 
10 storer r1 r15 
11 addn r15 1 
12 storer r14 r15 
13 addn r1 -1 
14 call r14 06 
15 loadr r14 r15 
16 addn r15 -1 
17 loadr r1 r15 
18 addn r15 -1 
19 mul r13 r13 r1 
20 jumpr r14 
106 
107 
It's easy to get lost! 
Follow the line numbers below to stay on track... 
r15 
0, 1, 2, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 7, 8, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 3, 4
main 
factorial 
store 
to stack 
recursive case 
load 
from stack 
base 
case 
Trace what happens for an input of 3... 
CPU Registers Memory 
3,2 
03,15 
r1 
r13 
r14 
3 
03 
100 
101 
102 
103 
104 
105 
r15 100,101,102 
"the stack" 
input: x 
return value (the "result") 
return address (line #) 
the stack pointer 
00 read r1 
01 setn r15 100 
02 call r14 06 
03 write r13 
04 halt 
05 nop 
06 jnez r1 09 
07 setn r13 1 
08 jumpr r14 
09 addn r15 1 
10 storer r1 r15 
11 addn r15 1 
12 storer r14 r15 
13 addn r1 -1 
14 call r14 06 
15 loadr r14 r15 
16 addn r15 -1 
17 loadr r1 r15 
18 addn r15 -1 
19 mul r13 r13 r1 
20 jumpr r14 
106 
107 
It's easy to get lost! 
Follow the line numbers below to stay on track... 
r15 
0, 1, 2, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 7, 8, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 3, 4
main 
factorial 
store 
to stack 
recursive case 
load 
from stack 
base 
case 
Trace what happens for an input of 3... 
CPU Registers Memory 
3,2 
03,15 
r1 
r13 
r14 
3 
03 
100 
101 
102 
103 
104 
105 
r15 100,101,102 
"the stack" 
input: x 
return value (the "result") 
return address (line #) 
the stack pointer 
00 read r1 
01 setn r15 100 
02 call r14 06 
03 write r13 
04 halt 
05 nop 
06 jnez r1 09 
07 setn r13 1 
08 jumpr r14 
09 addn r15 1 
10 storer r1 r15 
11 addn r15 1 
12 storer r14 r15 
13 addn r1 -1 
14 call r14 06 
15 loadr r14 r15 
16 addn r15 -1 
17 loadr r1 r15 
18 addn r15 -1 
19 mul r13 r13 r1 
20 jumpr r14 
106 
107 
It's easy to get lost! 
Follow the line numbers below to stay on track... 
r15 
0, 1, 2, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 7, 8, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 3, 4
main 
factorial 
store 
to stack 
recursive case 
load 
from stack 
base 
case 
Trace what happens for an input of 3... 
CPU Registers Memory 
3,2 
03,15 
r1 
r13 
r14 
3 
03 
100 
101 
102 
103 
104 
105 
r15 100,101,102 
"the stack" 
input: x 
return value (the "result") 
return address (line #) 
the stack pointer 
00 read r1 
01 setn r15 100 
02 call r14 06 
03 write r13 
04 halt 
05 nop 
06 jnez r1 09 
07 setn r13 1 
08 jumpr r14 
09 addn r15 1 
10 storer r1 r15 
11 addn r15 1 
12 storer r14 r15 
13 addn r1 -1 
14 call r14 06 
15 loadr r14 r15 
16 addn r15 -1 
17 loadr r1 r15 
18 addn r15 -1 
19 mul r13 r13 r1 
20 jumpr r14 
106 
107 
It's easy to get lost! 
Follow the line numbers below to stay on track... 
r15 
0, 1, 2, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 7, 8, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 3, 4
main 
factorial 
store 
to stack 
recursive case 
load 
from stack 
base 
case 
Trace what happens for an input of 3... 
CPU Registers Memory 
3,2 
03,15 
r1 
r13 
r14 
3 
03 
100 
101 
102 
103 
104 
105 
r15 100,101,102,103 
"the stack" 
input: x 
return value (the "result") 
return address (line #) 
the stack pointer 
00 read r1 
01 setn r15 100 
02 call r14 06 
03 write r13 
04 halt 
05 nop 
06 jnez r1 09 
07 setn r13 1 
08 jumpr r14 
09 addn r15 1 
10 storer r1 r15 
11 addn r15 1 
12 storer r14 r15 
13 addn r1 -1 
14 call r14 06 
15 loadr r14 r15 
16 addn r15 -1 
17 loadr r1 r15 
18 addn r15 -1 
19 mul r13 r13 r1 
20 jumpr r14 
106 
107 
It's easy to get lost! 
Follow the line numbers below to stay on track... 
r15 
0, 1, 2, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 7, 8, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 3, 4
main 
factorial 
store 
to stack 
recursive case 
load 
from stack 
base 
case 
Trace what happens for an input of 3... 
CPU Registers Memory 
3,2 
03,15 
r1 
r13 
r14 
3 
03 
2 
100 
101 
102 
103 
104 
105 
r15 100,101,102,103 
"the stack" 
input: x 
return value (the "result") 
return address (line #) 
the stack pointer 
00 read r1 
01 setn r15 100 
02 call r14 06 
03 write r13 
04 halt 
05 nop 
06 jnez r1 09 
07 setn r13 1 
08 jumpr r14 
09 addn r15 1 
10 storer r1 r15 
11 addn r15 1 
12 storer r14 r15 
13 addn r1 -1 
14 call r14 06 
15 loadr r14 r15 
16 addn r15 -1 
17 loadr r1 r15 
18 addn r15 -1 
19 mul r13 r13 r1 
20 jumpr r14 
106 
107 
It's easy to get lost! 
Follow the line numbers below to stay on track... 
r15 
0, 1, 2, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 7, 8, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 3, 4
main 
factorial 
store 
to stack 
recursive case 
load 
from stack 
base 
case 
Trace what happens for an input of 3... 
CPU Registers Memory 
3,2 
03,15 
r1 
r13 
r14 
3 
03 
2 
100 
101 
102 
103 
104 
105 
100,101,102,103, 
104 
r15 
"the stack" 
input: x 
return value (the "result") 
return address (line #) 
the stack pointer 
00 read r1 
01 setn r15 100 
02 call r14 06 
03 write r13 
04 halt 
05 nop 
06 jnez r1 09 
07 setn r13 1 
08 jumpr r14 
09 addn r15 1 
10 storer r1 r15 
11 addn r15 1 
12 storer r14 r15 
13 addn r1 -1 
14 call r14 06 
15 loadr r14 r15 
16 addn r15 -1 
17 loadr r1 r15 
18 addn r15 -1 
19 mul r13 r13 r1 
20 jumpr r14 
106 
107 
It's easy to get lost! 
Follow the line numbers below to stay on track... 
r15 
0, 1, 2, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 7, 8, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 3, 4
main 
factorial 
store 
to stack 
recursive case 
load 
from stack 
base 
case 
Trace what happens for an input of 3... 
CPU Registers Memory 
3,2 
03,15 
r1 
r13 
r14 
3 
03 
2 
15 
100 
101 
102 
103 
104 
105 
100,101,102,103, 
104 
r15 
"the stack" 
input: x 
return value (the "result") 
return address (line #) 
the stack pointer 
00 read r1 
01 setn r15 100 
02 call r14 06 
03 write r13 
04 halt 
05 nop 
06 jnez r1 09 
07 setn r13 1 
08 jumpr r14 
09 addn r15 1 
10 storer r1 r15 
11 addn r15 1 
12 storer r14 r15 
13 addn r1 -1 
14 call r14 06 
15 loadr r14 r15 
16 addn r15 -1 
17 loadr r1 r15 
18 addn r15 -1 
19 mul r13 r13 r1 
20 jumpr r14 
106 
107 
It's easy to get lost! 
Follow the line numbers below to stay on track... 
r15 
0, 1, 2, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 7, 8, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 3, 4
main 
factorial 
store 
to stack 
recursive case 
load 
from stack 
base 
case 
Trace what happens for an input of 3... 
CPU Registers Memory 
3,2,1 
03,15 
r1 
r13 
r14 
3 
03 
2 
15 
100 
101 
102 
103 
104 
105 
100,101,102,103, 
104 
r15 
"the stack" 
input: x 
return value (the "result") 
return address (line #) 
the stack pointer 
00 read r1 
01 setn r15 100 
02 call r14 06 
03 write r13 
04 halt 
05 nop 
06 jnez r1 09 
07 setn r13 1 
08 jumpr r14 
09 addn r15 1 
10 storer r1 r15 
11 addn r15 1 
12 storer r14 r15 
13 addn r1 -1 
14 call r14 06 
15 loadr r14 r15 
16 addn r15 -1 
17 loadr r1 r15 
18 addn r15 -1 
19 mul r13 r13 r1 
20 jumpr r14 
106 
107 
It's easy to get lost! 
Follow the line numbers below to stay on track... 
r15 
0, 1, 2, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 7, 8, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 3, 4
main 
factorial 
store 
to stack 
recursive case 
load 
from stack 
base 
case 
Trace what happens for an input of 3... 
CPU Registers Memory 
3,2,1 
03,15,15 
r1 
r13 
r14 
3 
03 
2 
15 
100 
101 
102 
103 
104 
105 
100,101,102,103, 
104 
r15 
"the stack" 
input: x 
return value (the "result") 
return address (line #) 
the stack pointer 
00 read r1 
01 setn r15 100 
02 call r14 06 
03 write r13 
04 halt 
05 nop 
06 jnez r1 09 
07 setn r13 1 
08 jumpr r14 
09 addn r15 1 
10 storer r1 r15 
11 addn r15 1 
12 storer r14 r15 
13 addn r1 -1 
14 call r14 06 
15 loadr r14 r15 
16 addn r15 -1 
17 loadr r1 r15 
18 addn r15 -1 
19 mul r13 r13 r1 
20 jumpr r14 
106 
107 
It's easy to get lost! 
Follow the line numbers below to stay on track... 
r15 
0, 1, 2, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 7, 8, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 3, 4
main 
factorial 
store 
to stack 
recursive case 
load 
from stack 
base 
case 
Trace what happens for an input of 3... 
CPU Registers Memory 
3,2,1 
03,15,15 
r1 
r13 
r14 
3 
03 
2 
15 
100 
101 
102 
103 
104 
105 
100,101,102,103, 
104 
r15 
"the stack" 
input: x 
return value (the "result") 
return address (line #) 
the stack pointer 
00 read r1 
01 setn r15 100 
02 call r14 06 
03 write r13 
04 halt 
05 nop 
06 jnez r1 09 
07 setn r13 1 
08 jumpr r14 
09 addn r15 1 
10 storer r1 r15 
11 addn r15 1 
12 storer r14 r15 
13 addn r1 -1 
14 call r14 06 
15 loadr r14 r15 
16 addn r15 -1 
17 loadr r1 r15 
18 addn r15 -1 
19 mul r13 r13 r1 
20 jumpr r14 
106 
107 
It's easy to get lost! 
Follow the line numbers below to stay on track... 
r15 
0, 1, 2, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 7, 8, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 3, 4
main 
factorial 
store 
to stack 
recursive case 
load 
from stack 
base 
case 
Trace what happens for an input of 3... 
CPU Registers Memory 
3,2,1 
03,15,15 
r1 
r13 
r14 
3 
03 
2 
15 
100 
101 
102 
103 
104 
105 
100,101,102,103, 
104,105 
r15 
"the stack" 
input: x 
return value (the "result") 
return address (line #) 
the stack pointer 
00 read r1 
01 setn r15 100 
02 call r14 06 
03 write r13 
04 halt 
05 nop 
06 jnez r1 09 
07 setn r13 1 
08 jumpr r14 
09 addn r15 1 
10 storer r1 r15 
11 addn r15 1 
12 storer r14 r15 
13 addn r1 -1 
14 call r14 06 
15 loadr r14 r15 
16 addn r15 -1 
17 loadr r1 r15 
18 addn r15 -1 
19 mul r13 r13 r1 
20 jumpr r14 
106 
107 
It's easy to get lost! 
Follow the line numbers below to stay on track... 
r15 
0, 1, 2, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 7, 8, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 3, 4
main 
factorial 
store 
to stack 
recursive case 
load 
from stack 
base 
case 
Trace what happens for an input of 3... 
CPU Registers Memory 
3,2,1 
03,15,15 
r1 
r13 
r14 
3 
03 
2 
15 
1 
100 
101 
102 
103 
104 
105 
100,101,102,103, 
104,105 
r15 
"the stack" 
input: x 
return value (the "result") 
return address (line #) 
the stack pointer 
00 read r1 
01 setn r15 100 
02 call r14 06 
03 write r13 
04 halt 
05 nop 
06 jnez r1 09 
07 setn r13 1 
08 jumpr r14 
09 addn r15 1 
10 storer r1 r15 
11 addn r15 1 
12 storer r14 r15 
13 addn r1 -1 
14 call r14 06 
15 loadr r14 r15 
16 addn r15 -1 
17 loadr r1 r15 
18 addn r15 -1 
19 mul r13 r13 r1 
20 jumpr r14 
106 
107 
It's easy to get lost! 
Follow the line numbers below to stay on track... 
r15 
0, 1, 2, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 7, 8, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 3, 4
main 
factorial 
store 
to stack 
recursive case 
load 
from stack 
base 
case 
Trace what happens for an input of 3... 
CPU Registers Memory 
3,2,1 
03,15,15 
r1 
r13 
r14 
3 
03 
2 
15 
1 
100 
101 
102 
103 
104 
105 
100,101,102,103, 
104,105,106 
r15 
"the stack" 
input: x 
return value (the "result") 
return address (line #) 
the stack pointer 
00 read r1 
01 setn r15 100 
02 call r14 06 
03 write r13 
04 halt 
05 nop 
06 jnez r1 09 
07 setn r13 1 
08 jumpr r14 
09 addn r15 1 
10 storer r1 r15 
11 addn r15 1 
12 storer r14 r15 
13 addn r1 -1 
14 call r14 06 
15 loadr r14 r15 
16 addn r15 -1 
17 loadr r1 r15 
18 addn r15 -1 
19 mul r13 r13 r1 
20 jumpr r14 
106 
107 
It's easy to get lost! 
Follow the line numbers below to stay on track... 
r15 
0, 1, 2, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 7, 8, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 3, 4
main 
factorial 
store 
to stack 
recursive case 
load 
from stack 
base 
case 
Trace what happens for an input of 3... 
CPU Registers Memory 
3,2,1 
03,15,15 
r1 
r13 
r14 
3 
03 
2 
15 
1 
100 
101 
102 
103 
104 
105 
100,101,102,103, 
104,105,106 
r15 
"the stack" 
input: x 
return value (the "result") 
return address (line #) 
the stack pointer 
00 read r1 
01 setn r15 100 
02 call r14 06 
03 write r13 
04 halt 
05 nop 
06 jnez r1 09 
07 setn r13 1 
08 jumpr r14 
09 addn r15 1 
10 storer r1 r15 
11 addn r15 1 
12 storer r14 r15 
13 addn r1 -1 
14 call r14 06 
15 loadr r14 r15 
16 addn r15 -1 
17 loadr r1 r15 
18 addn r15 -1 
19 mul r13 r13 r1 
20 jumpr r14 
106 
107 
It's easy to get lost! 
15 
Follow the line numbers below to stay on track... 
r15 
0, 1, 2, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 7, 8, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 3, 4
main 
factorial 
store 
to stack 
recursive case 
load 
from stack 
base 
case 
Trace what happens for an input of 3... 
CPU Registers Memory 
3,2,1,0 
03,15,15 
r1 
r13 
r14 
3 
03 
2 
15 
1 
100 
101 
102 
103 
104 
105 
100,101,102,103, 
104,105,106 
r15 
"the stack" 
input: x 
return value (the "result") 
return address (line #) 
the stack pointer 
00 read r1 
01 setn r15 100 
02 call r14 06 
03 write r13 
04 halt 
05 nop 
06 jnez r1 09 
07 setn r13 1 
08 jumpr r14 
09 addn r15 1 
10 storer r1 r15 
11 addn r15 1 
12 storer r14 r15 
13 addn r1 -1 
14 call r14 06 
15 loadr r14 r15 
16 addn r15 -1 
17 loadr r1 r15 
18 addn r15 -1 
19 mul r13 r13 r1 
20 jumpr r14 
106 
107 
It's easy to get lost! 
15 
Follow the line numbers below to stay on track... 
r15 
0, 1, 2, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 7, 8, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 3, 4
main 
factorial 
store 
to stack 
recursive case 
load 
from stack 
base 
case 
Trace what happens for an input of 3... 
CPU Registers Memory 
3,2,1,0 
03,15,15,15 
r1 
r13 
r14 
3 
03 
2 
15 
1 
100 
101 
102 
103 
104 
105 
100,101,102,103, 
104,105,106 
r15 
"the stack" 
input: x 
return value (the "result") 
return address (line #) 
the stack pointer 
00 read r1 
01 setn r15 100 
02 call r14 06 
03 write r13 
04 halt 
05 nop 
06 jnez r1 09 
07 setn r13 1 
08 jumpr r14 
09 addn r15 1 
10 storer r1 r15 
11 addn r15 1 
12 storer r14 r15 
13 addn r1 -1 
14 call r14 06 
15 loadr r14 r15 
16 addn r15 -1 
17 loadr r1 r15 
18 addn r15 -1 
19 mul r13 r13 r1 
20 jumpr r14 
106 
107 
It's easy to get lost! 
15 
Follow the line numbers below to stay on track... 
r15 
0, 1, 2, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 7, 8, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 3, 4
main 
factorial 
store 
to stack 
recursive case 
load 
from stack 
base 
case 
Trace what happens for an input of 3... 
CPU Registers Memory 
3,2,1,0 
03,15,15,15 
r1 
r13 
r14 
3 
03 
2 
15 
1 
100 
101 
102 
103 
104 
105 
100,101,102,103, 
104,105,106 
r15 
"the stack" 
input: x 
return value (the "result") 
return address (line #) 
the stack pointer 
00 read r1 
01 setn r15 100 
02 call r14 06 
03 write r13 
04 halt 
05 nop 
06 jnez r1 09 
07 setn r13 1 
08 jumpr r14 
09 addn r15 1 
10 storer r1 r15 
11 addn r15 1 
12 storer r14 r15 
13 addn r1 -1 
14 call r14 06 
15 loadr r14 r15 
16 addn r15 -1 
17 loadr r1 r15 
18 addn r15 -1 
19 mul r13 r13 r1 
20 jumpr r14 
106 
107 
It's easy to get lost! 
15 
Follow the line numbers below to stay on track... 
r15 
0, 1, 2, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 7, 8, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 3, 4
main 
factorial 
store 
to stack 
recursive case 
load 
from stack 
base 
case 
Trace what happens for an input of 3... 
CPU Registers Memory 
3,2,1,0 
1 
03,15,15,15 
r1 
r13 
r14 
3 
03 
2 
15 
1 
100 
101 
102 
103 
104 
105 
100,101,102,103, 
104,105,106 
r15 
"the stack" 
input: x 
return value (the "result") 
return address (line #) 
the stack pointer 
00 read r1 
01 setn r15 100 
02 call r14 06 
03 write r13 
04 halt 
05 nop 
06 jnez r1 09 
07 setn r13 1 
08 jumpr r14 
09 addn r15 1 
10 storer r1 r15 
11 addn r15 1 
12 storer r14 r15 
13 addn r1 -1 
14 call r14 06 
15 loadr r14 r15 
16 addn r15 -1 
17 loadr r1 r15 
18 addn r15 -1 
19 mul r13 r13 r1 
20 jumpr r14 
106 
107 
It's easy to get lost! 
15 
Follow the line numbers below to stay on track... 
r15 
0, 1, 2, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 7, 8, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 3, 4
main 
factorial 
store 
to stack 
recursive case 
load 
from stack 
base 
case 
Trace what happens for an input of 3... 
CPU Registers Memory 
3,2,1,0 
1 
03,15,15,15 
r1 
r13 
r14 
3 
03 
2 
15 
1 
100 
101 
102 
103 
104 
105 
100,101,102,103, 
104,105,106 
r15 
"the stack" 
input: x 
return value (the "result") 
return address (line #) 
the stack pointer 
00 read r1 
01 setn r15 100 
02 call r14 06 
03 write r13 
04 halt 
05 nop 
06 jnez r1 09 
07 setn r13 1 
08 jumpr r14 
09 addn r15 1 
10 storer r1 r15 
11 addn r15 1 
12 storer r14 r15 
13 addn r1 -1 
14 call r14 06 
15 loadr r14 r15 
16 addn r15 -1 
17 loadr r1 r15 
18 addn r15 -1 
19 mul r13 r13 r1 
20 jumpr r14 
106 
107 
It's easy to get lost! 
15 
Follow the line numbers below to stay on track... 
r15 
0, 1, 2, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 7, 8, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 3, 4
main 
factorial 
store 
to stack 
recursive case 
load 
from stack 
base 
case 
Trace what happens for an input of 3... 
CPU Registers Memory 
3,2,1,0 
1 
03,15,15,15 
r1 
r13 
r14 
3 
03 
2 
15 
1 
100 
101 
102 
103 
104 
105 
100,101,102,103, 
104,105,106 
r15 
"the stack" 
input: x 
return value (the "result") 
return address (line #) 
the stack pointer 
00 read r1 
01 setn r15 100 
02 call r14 06 
03 write r13 
04 halt 
05 nop 
06 jnez r1 09 
07 setn r13 1 
08 jumpr r14 
09 addn r15 1 
10 storer r1 r15 
11 addn r15 1 
12 storer r14 r15 
13 addn r1 -1 
14 call r14 06 
15 loadr r14 r15 
16 addn r15 -1 
17 loadr r1 r15 
18 addn r15 -1 
19 mul r13 r13 r1 
20 jumpr r14 
106 
107 
It's easy to get lost! 
15 
Follow the line numbers below to stay on track... 
r15 
0, 1, 2, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 7, 8, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 3, 4
main 
factorial 
store 
to stack 
recursive case 
load 
from stack 
base 
case 
Trace what happens for an input of 3... 
CPU Registers Memory 
3,2,1,0 
1 
03,15,15,15 
r1 
r13 
r14 
3 
03 
2 
15 
1 
100 
101 
102 
103 
104 
105 
100,101,102,103, 
104,105,106 
r15 
"the stack" 
input: x 
return value (the "result") 
return address (line #) 
the stack pointer 
00 read r1 
01 setn r15 100 
02 call r14 06 
03 write r13 
04 halt 
05 nop 
06 jnez r1 09 
07 setn r13 1 
08 jumpr r14 
09 addn r15 1 
10 storer r1 r15 
11 addn r15 1 
12 storer r14 r15 
13 addn r1 -1 
14 call r14 06 
15 loadr r14 r15 
16 addn r15 -1 
17 loadr r1 r15 
18 addn r15 -1 
19 mul r13 r13 r1 
20 jumpr r14 
106 
107 
It's easy to get lost! 
15 
Follow the line numbers below to stay on track... 
r15 
0, 1, 2, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 7, 8, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 3, 4
main 
factorial 
store 
to stack 
recursive case 
load 
from stack 
base 
case 
Trace what happens for an input of 3... 
CPU Registers Memory 
3,2,1,0 
1 
03,15,15,15,15 
r1 
r13 
r14 
3 
03 
2 
15 
1 
100 
101 
102 
103 
104 
105 
100,101,102,103, 
104,105,106 
r15 
"the stack" 
input: x 
return value (the "result") 
return address (line #) 
the stack pointer 
00 read r1 
01 setn r15 100 
02 call r14 06 
03 write r13 
04 halt 
05 nop 
06 jnez r1 09 
07 setn r13 1 
08 jumpr r14 
09 addn r15 1 
10 storer r1 r15 
11 addn r15 1 
12 storer r14 r15 
13 addn r1 -1 
14 call r14 06 
15 loadr r14 r15 
16 addn r15 -1 
17 loadr r1 r15 
18 addn r15 -1 
19 mul r13 r13 r1 
20 jumpr r14 
106 
107 
It's easy to get lost! 
15 
Follow the line numbers below to stay on track... 
r15 
0, 1, 2, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 7, 8, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 3, 4
main 
factorial 
store 
to stack 
recursive case 
load 
from stack 
base 
case 
Trace what happens for an input of 3... 
CPU Registers Memory 
3,2,1,0 
1 
03,15,15,15,15 
r1 
r13 
r14 
3 
03 
2 
15 
1 
100 
101 
102 
103 
104 
105 
100,101,102,103, 
104,105,106,105 
r15 
"the stack" 
input: x 
return value (the "result") 
return address (line #) 
the stack pointer 
00 read r1 
01 setn r15 100 
02 call r14 06 
03 write r13 
04 halt 
05 nop 
06 jnez r1 09 
07 setn r13 1 
08 jumpr r14 
09 addn r15 1 
10 storer r1 r15 
11 addn r15 1 
12 storer r14 r15 
13 addn r1 -1 
14 call r14 06 
15 loadr r14 r15 
16 addn r15 -1 
17 loadr r1 r15 
18 addn r15 -1 
19 mul r13 r13 r1 
20 jumpr r14 
106 
107 
It's easy to get lost! 
15 
Follow the line numbers below to stay on track... 
r15 
0, 1, 2, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 7, 8, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 3, 4
main 
factorial 
store 
to stack 
recursive case 
load 
from stack 
base 
case 
Trace what happens for an input of 3... 
CPU Registers Memory 
3,2,1,0,1 
1 
03,15,15,15,15 
r1 
r13 
r14 
3 
03 
2 
15 
1 
100 
101 
102 
103 
104 
105 
100,101,102,103, 
104,105,106,105 
r15 
"the stack" 
input: x 
return value (the "result") 
return address (line #) 
the stack pointer 
00 read r1 
01 setn r15 100 
02 call r14 06 
03 write r13 
04 halt 
05 nop 
06 jnez r1 09 
07 setn r13 1 
08 jumpr r14 
09 addn r15 1 
10 storer r1 r15 
11 addn r15 1 
12 storer r14 r15 
13 addn r1 -1 
14 call r14 06 
15 loadr r14 r15 
16 addn r15 -1 
17 loadr r1 r15 
18 addn r15 -1 
19 mul r13 r13 r1 
20 jumpr r14 
106 
107 
It's easy to get lost! 
15 
Follow the line numbers below to stay on track... 
r15 
0, 1, 2, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 7, 8, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 3, 4
main 
factorial 
store 
to stack 
recursive case 
load 
from stack 
base 
case 
Trace what happens for an input of 3... 
CPU Registers Memory 
3,2,1,0,1 
1 
03,15,15,15,15 
r1 
r13 
r14 
3 
03 
2 
15 
1 
100 
101 
102 
103 
104 
105 
100,101,102,103, 
104,105,106,105, 
104 
r15 
"the stack" 
input: x 
return value (the "result") 
return address (line #) 
the stack pointer 
00 read r1 
01 setn r15 100 
02 call r14 06 
03 write r13 
04 halt 
05 nop 
06 jnez r1 09 
07 setn r13 1 
08 jumpr r14 
09 addn r15 1 
10 storer r1 r15 
11 addn r15 1 
12 storer r14 r15 
13 addn r1 -1 
14 call r14 06 
15 loadr r14 r15 
16 addn r15 -1 
17 loadr r1 r15 
18 addn r15 -1 
19 mul r13 r13 r1 
20 jumpr r14 
106 
107 
It's easy to get lost! 
15 
Follow the line numbers below to stay on track... 
r15 
0, 1, 2, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 7, 8, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 3, 4
main 
factorial 
store 
to stack 
recursive case 
load 
from stack 
base 
case 
Trace what happens for an input of 3... 
CPU Registers Memory 
3,2,1,0,1 
1,1 
03,15,15,15,15 
r1 
r13 
r14 
3 
03 
2 
15 
1 
100 
101 
102 
103 
104 
105 
100,101,102,103, 
104,105,106,105, 
104 
r15 
"the stack" 
input: x 
return value (the "result") 
return address (line #) 
the stack pointer 
00 read r1 
01 setn r15 100 
02 call r14 06 
03 write r13 
04 halt 
05 nop 
06 jnez r1 09 
07 setn r13 1 
08 jumpr r14 
09 addn r15 1 
10 storer r1 r15 
11 addn r15 1 
12 storer r14 r15 
13 addn r1 -1 
14 call r14 06 
15 loadr r14 r15 
16 addn r15 -1 
17 loadr r1 r15 
18 addn r15 -1 
19 mul r13 r13 r1 
20 jumpr r14 
106 
107 
It's easy to get lost! 
15 
Follow the line numbers below to stay on track... 
r15 
0, 1, 2, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 7, 8, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 3, 4
main 
factorial 
store 
to stack 
recursive case 
load 
from stack 
base 
case 
Trace what happens for an input of 3... 
CPU Registers Memory 
3,2,1,0,1 
1,1 
03,15,15,15,15 
r1 
r13 
r14 
3 
03 
2 
15 
1 
100 
101 
102 
103 
104 
105 
100,101,102,103, 
104,105,106,105, 
104 
r15 
"the stack" 
input: x 
return value (the "result") 
return address (line #) 
the stack pointer 
00 read r1 
01 setn r15 100 
02 call r14 06 
03 write r13 
04 halt 
05 nop 
06 jnez r1 09 
07 setn r13 1 
08 jumpr r14 
09 addn r15 1 
10 storer r1 r15 
11 addn r15 1 
12 storer r14 r15 
13 addn r1 -1 
14 call r14 06 
15 loadr r14 r15 
16 addn r15 -1 
17 loadr r1 r15 
18 addn r15 -1 
19 mul r13 r13 r1 
20 jumpr r14 
106 
107 
It's easy to get lost! 
15 
Follow the line numbers below to stay on track... 
r15 
0, 1, 2, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 7, 8, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 3, 4
main 
factorial 
store 
to stack 
recursive case 
load 
from stack 
base 
case 
Trace what happens for an input of 3... 
CPU Registers Memory 
3,2,1,0,1 
1,1 
03,15,15,15,15, 
15 
r1 
r13 
r14 
3 
03 
2 
15 
1 
100 
101 
102 
103 
104 
105 
100,101,102,103, 
104,105,106,105, 
104 
r15 
"the stack" 
input: x 
return value (the "result") 
return address (line #) 
the stack pointer 
00 read r1 
01 setn r15 100 
02 call r14 06 
03 write r13 
04 halt 
05 nop 
06 jnez r1 09 
07 setn r13 1 
08 jumpr r14 
09 addn r15 1 
10 storer r1 r15 
11 addn r15 1 
12 storer r14 r15 
13 addn r1 -1 
14 call r14 06 
15 loadr r14 r15 
16 addn r15 -1 
17 loadr r1 r15 
18 addn r15 -1 
19 mul r13 r13 r1 
20 jumpr r14 
106 
107 
It's easy to get lost! 
15 
Follow the line numbers below to stay on track... 
r15 
0, 1, 2, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 7, 8, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 3, 4
main 
factorial 
store 
to stack 
recursive case 
load 
from stack 
base 
case 
Trace what happens for an input of 3... 
CPU Registers Memory 
3,2,1,0,1 
1,1 
03,15,15,15,15, 
15 
r1 
r13 
r14 
3 
03 
2 
15 
1 
100 
101 
102 
103 
104 
105 
100,101,102,103, 
104,105,106,105, 
104,103 
r15 
"the stack" 
input: x 
return value (the "result") 
return address (line #) 
the stack pointer 
00 read r1 
01 setn r15 100 
02 call r14 06 
03 write r13 
04 halt 
05 nop 
06 jnez r1 09 
07 setn r13 1 
08 jumpr r14 
09 addn r15 1 
10 storer r1 r15 
11 addn r15 1 
12 storer r14 r15 
13 addn r1 -1 
14 call r14 06 
15 loadr r14 r15 
16 addn r15 -1 
17 loadr r1 r15 
18 addn r15 -1 
19 mul r13 r13 r1 
20 jumpr r14 
106 
107 
It's easy to get lost! 
15 
Follow the line numbers below to stay on track... 
r15 
0, 1, 2, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 7, 8, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 3, 4
main 
factorial 
store 
to stack 
recursive case 
load 
from stack 
base 
case 
Trace what happens for an input of 3... 
CPU Registers Memory 
3,2,1,0,1,2 
1,1 
03,15,15,15,15, 
15 
r1 
r13 
r14 
3 
03 
2 
15 
1 
100 
101 
102 
103 
104 
105 
100,101,102,103, 
104,105,106,105, 
104,103 
r15 
"the stack" 
input: x 
return value (the "result") 
return address (line #) 
the stack pointer 
00 read r1 
01 setn r15 100 
02 call r14 06 
03 write r13 
04 halt 
05 nop 
06 jnez r1 09 
07 setn r13 1 
08 jumpr r14 
09 addn r15 1 
10 storer r1 r15 
11 addn r15 1 
12 storer r14 r15 
13 addn r1 -1 
14 call r14 06 
15 loadr r14 r15 
16 addn r15 -1 
17 loadr r1 r15 
18 addn r15 -1 
19 mul r13 r13 r1 
20 jumpr r14 
106 
107 
It's easy to get lost! 
15 
Follow the line numbers below to stay on track... 
r15 
0, 1, 2, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 7, 8, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 3, 4
main 
factorial 
store 
to stack 
recursive case 
load 
from stack 
base 
case 
Trace what happens for an input of 3... 
CPU Registers Memory 
3,2,1,0,1,2 
1,1 
03,15,15,15,15, 
15 
r1 
r13 
r14 
3 
03 
2 
15 
1 
100 
101 
102 
103 
104 
105 
100,101,102,103, 
104,105,106,105, 
104,103,102 
r15 
"the stack" 
input: x 
return value (the "result") 
return address (line #) 
the stack pointer 
00 read r1 
01 setn r15 100 
02 call r14 06 
03 write r13 
04 halt 
05 nop 
06 jnez r1 09 
07 setn r13 1 
08 jumpr r14 
09 addn r15 1 
10 storer r1 r15 
11 addn r15 1 
12 storer r14 r15 
13 addn r1 -1 
14 call r14 06 
15 loadr r14 r15 
16 addn r15 -1 
17 loadr r1 r15 
18 addn r15 -1 
19 mul r13 r13 r1 
20 jumpr r14 
106 
107 
It's easy to get lost! 
15 
Follow the line numbers below to stay on track... 
r15 
0, 1, 2, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 7, 8, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 3, 4
main 
factorial 
store 
to stack 
recursive case 
load 
from stack 
base 
case 
Trace what happens for an input of 3... 
CPU Registers Memory 
3,2,1,0,1,2 
1,1,2 
03,15,15,15,15, 
15 
r1 
r13 
r14 
3 
03 
2 
15 
1 
100 
101 
102 
103 
104 
105 
100,101,102,103, 
104,105,106,105, 
104,103,102 
r15 
"the stack" 
input: x 
return value (the "result") 
return address (line #) 
the stack pointer 
00 read r1 
01 setn r15 100 
02 call r14 06 
03 write r13 
04 halt 
05 nop 
06 jnez r1 09 
07 setn r13 1 
08 jumpr r14 
09 addn r15 1 
10 storer r1 r15 
11 addn r15 1 
12 storer r14 r15 
13 addn r1 -1 
14 call r14 06 
15 loadr r14 r15 
16 addn r15 -1 
17 loadr r1 r15 
18 addn r15 -1 
19 mul r13 r13 r1 
20 jumpr r14 
106 
107 
It's easy to get lost! 
15 
Follow the line numbers below to stay on track... 
r15 
0, 1, 2, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 7, 8, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 3, 4
main 
factorial 
store 
to stack 
recursive case 
load 
from stack 
base 
case 
Trace what happens for an input of 3... 
CPU Registers Memory 
3,2,1,0,1,2 
1,1,2 
03,15,15,15,15, 
15 
r1 
r13 
r14 
3 
03 
2 
15 
1 
100 
101 
102 
103 
104 
105 
100,101,102,103, 
104,105,106,105, 
104,103,102 
r15 
"the stack" 
input: x 
return value (the "result") 
return address (line #) 
the stack pointer 
00 read r1 
01 setn r15 100 
02 call r14 06 
03 write r13 
04 halt 
05 nop 
06 jnez r1 09 
07 setn r13 1 
08 jumpr r14 
09 addn r15 1 
10 storer r1 r15 
11 addn r15 1 
12 storer r14 r15 
13 addn r1 -1 
14 call r14 06 
15 loadr r14 r15 
16 addn r15 -1 
17 loadr r1 r15 
18 addn r15 -1 
19 mul r13 r13 r1 
20 jumpr r14 
106 
107 
It's easy to get lost! 
15 
Follow the line numbers below to stay on track... 
r15 
0, 1, 2, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 7, 8, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 3, 4
main 
factorial 
store 
to stack 
recursive case 
load 
from stack 
base 
case 
Trace what happens for an input of 3... 
CPU Registers Memory 
3,2,1,0,1,2 
1,1,2 
03,15,15,15,15, 
15,03 
r1 
r13 
r14 
3 
03 
2 
15 
1 
100 
101 
102 
103 
104 
105 
100,101,102,103, 
104,105,106,105, 
104,103,102 
r15 
"the stack" 
input: x 
return value (the "result") 
return address (line #) 
the stack pointer 
00 read r1 
01 setn r15 100 
02 call r14 06 
03 write r13 
04 halt 
05 nop 
06 jnez r1 09 
07 setn r13 1 
08 jumpr r14 
09 addn r15 1 
10 storer r1 r15 
11 addn r15 1 
12 storer r14 r15 
13 addn r1 -1 
14 call r14 06 
15 loadr r14 r15 
16 addn r15 -1 
17 loadr r1 r15 
18 addn r15 -1 
19 mul r13 r13 r1 
20 jumpr r14 
106 
107 
It's easy to get lost! 
15 
Follow the line numbers below to stay on track... 
r15 
0, 1, 2, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 7, 8, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 3, 4
main 
factorial 
store 
to stack 
recursive case 
load 
from stack 
base 
case 
Trace what happens for an input of 3... 
CPU Registers Memory 
3,2,1,0,1,2 
1,1,2 
03,15,15,15,15, 
15,03 
r1 
r13 
r14 
3 
03 
2 
15 
1 
100 
101 
102 
103 
104 
105 
100,101,102,103, 
104,105,106,105, 
104,103,102,101 
r15 
"the stack" 
input: x 
return value (the "result") 
return address (line #) 
the stack pointer 
00 read r1 
01 setn r15 100 
02 call r14 06 
03 write r13 
04 halt 
05 nop 
06 jnez r1 09 
07 setn r13 1 
08 jumpr r14 
09 addn r15 1 
10 storer r1 r15 
11 addn r15 1 
12 storer r14 r15 
13 addn r1 -1 
14 call r14 06 
15 loadr r14 r15 
16 addn r15 -1 
17 loadr r1 r15 
18 addn r15 -1 
19 mul r13 r13 r1 
20 jumpr r14 
106 
107 
It's easy to get lost! 
15 
Follow the line numbers below to stay on track... 
r15 
0, 1, 2, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 7, 8, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 3, 4
main 
factorial 
store 
to stack 
recursive case 
load 
from stack 
base 
case 
Trace what happens for an input of 3... 
CPU Registers Memory 
3,2,1,0,1,2,3 
1,1,2 
03,15,15,15,15, 
15,03 
r1 
r13 
r14 
3 
03 
2 
15 
1 
100 
101 
102 
103 
104 
105 
100,101,102,103, 
104,105,106,105, 
104,103,102,101 
r15 
"the stack" 
input: x 
return value (the "result") 
return address (line #) 
the stack pointer 
00 read r1 
01 setn r15 100 
02 call r14 06 
03 write r13 
04 halt 
05 nop 
06 jnez r1 09 
07 setn r13 1 
08 jumpr r14 
09 addn r15 1 
10 storer r1 r15 
11 addn r15 1 
12 storer r14 r15 
13 addn r1 -1 
14 call r14 06 
15 loadr r14 r15 
16 addn r15 -1 
17 loadr r1 r15 
18 addn r15 -1 
19 mul r13 r13 r1 
20 jumpr r14 
106 
107 
It's easy to get lost! 
15 
Follow the line numbers below to stay on track... 
r15 
0, 1, 2, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 7, 8, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 3, 4
main 
factorial 
store 
to stack 
recursive case 
load 
from stack 
base 
case 
Trace what happens for an input of 3... 
CPU Registers Memory 
3,2,1,0,1,2,3 
1,1,2 
03,15,15,15,15, 
15,03 
r1 
r13 
r14 
3 
03 
2 
15 
1 
100 
101 
102 
103 
104 
105 
100,101,102,103, 
104,105,106,105, 
104,103,102,101, 
100 
r15 
"the stack" 
input: x 
return value (the "result") 
return address (line #) 
the stack pointer 
00 read r1 
01 setn r15 100 
02 call r14 06 
03 write r13 
04 halt 
05 nop 
06 jnez r1 09 
07 setn r13 1 
08 jumpr r14 
09 addn r15 1 
10 storer r1 r15 
11 addn r15 1 
12 storer r14 r15 
13 addn r1 -1 
14 call r14 06 
15 loadr r14 r15 
16 addn r15 -1 
17 loadr r1 r15 
18 addn r15 -1 
19 mul r13 r13 r1 
20 jumpr r14 
106 
107 
It's easy to get lost! 
15 
Follow the line numbers below to stay on track... 
r15 
0, 1, 2, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 7, 8, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 3, 4
main 
factorial 
store 
to stack 
recursive case 
load 
from stack 
base 
case 
Trace what happens for an input of 3... 
CPU Registers Memory 
3,2,1,0,1,2,3 
1,1,2,6 
03,15,15,15,15, 
15,03 
r1 
r13 
r14 
3 
03 
2 
15 
1 
100 
101 
102 
103 
104 
105 
100,101,102,103, 
104,105,106,105, 
104,103,102,101, 
100 
r15 
"the stack" 
input: x 
return value (the "result") 
return address (line #) 
the stack pointer 
00 read r1 
01 setn r15 100 
02 call r14 06 
03 write r13 
04 halt 
05 nop 
06 jnez r1 09 
07 setn r13 1 
08 jumpr r14 
09 addn r15 1 
10 storer r1 r15 
11 addn r15 1 
12 storer r14 r15 
13 addn r1 -1 
14 call r14 06 
15 loadr r14 r15 
16 addn r15 -1 
17 loadr r1 r15 
18 addn r15 -1 
19 mul r13 r13 r1 
20 jumpr r14 
106 
107 
It's easy to get lost! 
15 
Follow the line numbers below to stay on track... 
r15 
0, 1, 2, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 7, 8, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 3, 4
main 
factorial 
store 
to stack 
recursive case 
load 
from stack 
base 
case 
Trace what happens for an input of 3... 
CPU Registers Memory 
3,2,1,0,1,2,3 
1,1,2,6 
03,15,15,15,15, 
15,03 
r1 
r13 
r14 
3 
03 
2 
15 
1 
100 
101 
102 
103 
104 
105 
100,101,102,103, 
104,105,106,105, 
104,103,102,101, 
100 
r15 
"the stack" 
input: x 
return value (the "result") 
return address (line #) 
the stack pointer 
00 read r1 
01 setn r15 100 
02 call r14 06 
03 write r13 
04 halt 
05 nop 
06 jnez r1 09 
07 setn r13 1 
08 jumpr r14 
09 addn r15 1 
10 storer r1 r15 
11 addn r15 1 
12 storer r14 r15 
13 addn r1 -1 
14 call r14 06 
15 loadr r14 r15 
16 addn r15 -1 
17 loadr r1 r15 
18 addn r15 -1 
19 mul r13 r13 r1 
20 jumpr r14 
106 
107 
It's easy to get lost! 
15 
Follow the line numbers below to stay on track... 
r15 
0, 1, 2, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 7, 8, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 3, 4
main 
factorial 
store 
to stack 
recursive case 
load 
from stack 
base 
case 
Trace what happens for an input of 3... 
CPU Registers Memory 
3,2,1,0,1,2,3 
1,1,2,6 
03,15,15,15,15, 
15,03 
r1 
r13 
r14 
3 
03 
2 
15 
1 
100 
101 
102 
103 
104 
105 
100,101,102,103, 
104,105,106,105, 
104,103,102,101, 
100 
r15 
"the stack" 
input: x 
return value (the "result") 
return address (line #) 
the stack pointer 
00 read r1 
01 setn r15 100 
02 call r14 06 
03 write r13 
04 halt 
05 nop 
06 jnez r1 09 
07 setn r13 1 
08 jumpr r14 
09 addn r15 1 
10 storer r1 r15 
11 addn r15 1 
12 storer r14 r15 
13 addn r1 -1 
14 call r14 06 
15 loadr r14 r15 
16 addn r15 -1 
17 loadr r1 r15 
18 addn r15 -1 
19 mul r13 r13 r1 
20 jumpr r14 
106 
107 
It's easy to get lost! 
15 
Follow the line numbers below to stay on track... 
r15 
0, 1, 2, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 7, 8, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 3, 4
main 
factorial 
store 
to stack 
recursive case 
load 
from stack 
base 
case 
Trace what happens for an input of 3... 
CPU Registers Memory 
3,2,1,0,1,2,3 
1,1,2,6 
03,15,15,15,15, 
15,03 
r1 
r13 
r14 
3 
03 
2 
15 
1 
100 
101 
102 
103 
104 
105 
100,101,102,103, 
104,105,106,105, 
104,103,102,101, 
100 
r15 
"the stack" 
input: x 
return value (the "result") 
return address (line #) 
the stack pointer 
00 read r1 
01 setn r15 100 
02 call r14 06 
03 write r13 
04 halt 
05 nop 
06 jnez r1 09 
07 setn r13 1 
08 jumpr r14 
09 addn r15 1 
10 storer r1 r15 
11 addn r15 1 
12 storer r14 r15 
13 addn r1 -1 
14 call r14 06 
15 loadr r14 r15 
16 addn r15 -1 
17 loadr r1 r15 
18 addn r15 -1 
19 mul r13 r13 r1 
20 jumpr r14 
106 
107 
It's easy to get lost! 
15 
Follow the line numbers below to stay on track... 
r15 
0, 1, 2, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 7, 8 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 3, 4

Weitere ähnliche Inhalte

Andere mochten auch

Want to know how to find a reliable locksmith
Want to know how to find a reliable locksmith Want to know how to find a reliable locksmith
Want to know how to find a reliable locksmith ninzmiller
 
Còpia de taula de fitxers
Còpia de taula de fitxersCòpia de taula de fitxers
Còpia de taula de fitxerszire22
 
Ikt udruzenje Pk FBiH - 02-12-2014 - jahorina
Ikt udruzenje Pk FBiH - 02-12-2014 - jahorinaIkt udruzenje Pk FBiH - 02-12-2014 - jahorina
Ikt udruzenje Pk FBiH - 02-12-2014 - jahorinaIgor Pandzic
 
Team 5 Website Presentation Rough Draft.
Team 5 Website Presentation Rough Draft.Team 5 Website Presentation Rough Draft.
Team 5 Website Presentation Rough Draft.KKmck
 
My magazine pitch
My magazine pitchMy magazine pitch
My magazine pitchkatiess07
 
Digitalna agenda Dalibor Drljača
Digitalna agenda Dalibor DrljačaDigitalna agenda Dalibor Drljača
Digitalna agenda Dalibor DrljačaIgor Pandzic
 
Kaspersky Kesb ep10 no_cm_v01a
Kaspersky Kesb ep10 no_cm_v01aKaspersky Kesb ep10 no_cm_v01a
Kaspersky Kesb ep10 no_cm_v01aIgor Pandzic
 
Copyright & fair use
Copyright & fair useCopyright & fair use
Copyright & fair useakirkpatri
 
Projekat web Igor Pandžić
Projekat web Igor PandžićProjekat web Igor Pandžić
Projekat web Igor PandžićIgor Pandzic
 
Connect to Community Old Town
Connect to Community Old TownConnect to Community Old Town
Connect to Community Old Townaruban21
 
Info ars napredno google pretrazivanje
Info ars   napredno google pretrazivanjeInfo ars   napredno google pretrazivanje
Info ars napredno google pretrazivanjeIgor Pandzic
 

Andere mochten auch (12)

Want to know how to find a reliable locksmith
Want to know how to find a reliable locksmith Want to know how to find a reliable locksmith
Want to know how to find a reliable locksmith
 
Còpia de taula de fitxers
Còpia de taula de fitxersCòpia de taula de fitxers
Còpia de taula de fitxers
 
Ikt udruzenje Pk FBiH - 02-12-2014 - jahorina
Ikt udruzenje Pk FBiH - 02-12-2014 - jahorinaIkt udruzenje Pk FBiH - 02-12-2014 - jahorina
Ikt udruzenje Pk FBiH - 02-12-2014 - jahorina
 
Team 5 Website Presentation Rough Draft.
Team 5 Website Presentation Rough Draft.Team 5 Website Presentation Rough Draft.
Team 5 Website Presentation Rough Draft.
 
Learn Japanesse
Learn JapanesseLearn Japanesse
Learn Japanesse
 
My magazine pitch
My magazine pitchMy magazine pitch
My magazine pitch
 
Digitalna agenda Dalibor Drljača
Digitalna agenda Dalibor DrljačaDigitalna agenda Dalibor Drljača
Digitalna agenda Dalibor Drljača
 
Kaspersky Kesb ep10 no_cm_v01a
Kaspersky Kesb ep10 no_cm_v01aKaspersky Kesb ep10 no_cm_v01a
Kaspersky Kesb ep10 no_cm_v01a
 
Copyright & fair use
Copyright & fair useCopyright & fair use
Copyright & fair use
 
Projekat web Igor Pandžić
Projekat web Igor PandžićProjekat web Igor Pandžić
Projekat web Igor Pandžić
 
Connect to Community Old Town
Connect to Community Old TownConnect to Community Old Town
Connect to Community Old Town
 
Info ars napredno google pretrazivanje
Info ars   napredno google pretrazivanjeInfo ars   napredno google pretrazivanje
Info ars napredno google pretrazivanje
 

Ähnlich wie tracing a recursive factorial function in assembly language

Graph libraries in Matlab: MatlabBGL and gaimc
Graph libraries in Matlab: MatlabBGL and gaimcGraph libraries in Matlab: MatlabBGL and gaimc
Graph libraries in Matlab: MatlabBGL and gaimcDavid Gleich
 
Ethereum 9¾ @ Devcon5
Ethereum 9¾ @ Devcon5Ethereum 9¾ @ Devcon5
Ethereum 9¾ @ Devcon5Wanseob Lim
 
SQL WORKSHOP::Lecture 4
SQL WORKSHOP::Lecture 4SQL WORKSHOP::Lecture 4
SQL WORKSHOP::Lecture 4Umair Amjad
 
Sangam 18 - Great Applications with Great SQL
Sangam 18 - Great Applications with Great SQLSangam 18 - Great Applications with Great SQL
Sangam 18 - Great Applications with Great SQLConnor McDonald
 
Wellington APAC Groundbreakers tour - SQL Pattern Matching
Wellington APAC Groundbreakers tour - SQL Pattern MatchingWellington APAC Groundbreakers tour - SQL Pattern Matching
Wellington APAC Groundbreakers tour - SQL Pattern MatchingConnor McDonald
 

Ähnlich wie tracing a recursive factorial function in assembly language (8)

Graph libraries in Matlab: MatlabBGL and gaimc
Graph libraries in Matlab: MatlabBGL and gaimcGraph libraries in Matlab: MatlabBGL and gaimc
Graph libraries in Matlab: MatlabBGL and gaimc
 
assembly
assemblyassembly
assembly
 
SLIME
SLIMESLIME
SLIME
 
Ethereum 9¾ @ Devcon5
Ethereum 9¾ @ Devcon5Ethereum 9¾ @ Devcon5
Ethereum 9¾ @ Devcon5
 
SQL WORKSHOP::Lecture 4
SQL WORKSHOP::Lecture 4SQL WORKSHOP::Lecture 4
SQL WORKSHOP::Lecture 4
 
Sangam 18 - Great Applications with Great SQL
Sangam 18 - Great Applications with Great SQLSangam 18 - Great Applications with Great SQL
Sangam 18 - Great Applications with Great SQL
 
Analytic SQL Sep 2013
Analytic SQL Sep 2013Analytic SQL Sep 2013
Analytic SQL Sep 2013
 
Wellington APAC Groundbreakers tour - SQL Pattern Matching
Wellington APAC Groundbreakers tour - SQL Pattern MatchingWellington APAC Groundbreakers tour - SQL Pattern Matching
Wellington APAC Groundbreakers tour - SQL Pattern Matching
 

Kürzlich hochgeladen

Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxVishalSingh1417
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfAyushMahapatra5
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docxPoojaSen20
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin ClassesCeline George
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxVishalSingh1417
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 

Kürzlich hochgeladen (20)

Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docx
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 

tracing a recursive factorial function in assembly language

  • 1. main factorial store to stack recursive case load from stack base case Trace what happens for an input of 3... r1 r13 r14 CPU Registers Memory 100 101 102 103 104 105 r15 "the stack" input: x return value (the "result") return address (line #) the stack pointer 00 read r1 01 setn r15 100 02 call r14 06 03 write r13 04 halt 05 nop 06 jnez r1 09 07 setn r13 1 08 jumpr r14 09 addn r15 1 10 storer r1 r15 11 addn r15 1 12 storer r14 r15 13 addn r1 -1 14 call r14 06 15 loadr r14 r15 16 addn r15 -1 17 loadr r1 r15 18 addn r15 -1 19 mul r13 r13 r1 20 jumpr r14 106 107 It's easy to get lost! Follow the line numbers below to stay on track... 0, 1, 2, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 7, 8, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 3, 4
  • 2. main factorial store to stack recursive case load from stack base case Trace what happens for an input of 3... r1 3 r13 r14 CPU Registers Memory 100 101 102 103 104 105 r15 "the stack" input: x return value (the "result") return address (line #) the stack pointer 00 read r1 01 setn r15 100 02 call r14 06 03 write r13 04 halt 05 nop 06 jnez r1 09 07 setn r13 1 08 jumpr r14 09 addn r15 1 10 storer r1 r15 11 addn r15 1 12 storer r14 r15 13 addn r1 -1 14 call r14 06 15 loadr r14 r15 16 addn r15 -1 17 loadr r1 r15 18 addn r15 -1 19 mul r13 r13 r1 20 jumpr r14 106 107 It's easy to get lost! Follow the line numbers below to stay on track... 0, 1, 2, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 7, 8, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 3, 4
  • 3. main factorial store to stack recursive case load from stack base case Trace what happens for an input of 3... r1 3 r13 r14 CPU Registers Memory 100 101 102 103 104 105 r15 100 "the stack" input: x return value (the "result") return address (line #) the stack pointer r15 00 read r1 01 setn r15 100 02 call r14 06 03 write r13 04 halt 05 nop 06 jnez r1 09 07 setn r13 1 08 jumpr r14 09 addn r15 1 10 storer r1 r15 11 addn r15 1 12 storer r14 r15 13 addn r1 -1 14 call r14 06 15 loadr r14 r15 16 addn r15 -1 17 loadr r1 r15 18 addn r15 -1 19 mul r13 r13 r1 20 jumpr r14 106 107 It's easy to get lost! Follow the line numbers below to stay on track... 0, 1, 2, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 7, 8, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 3, 4
  • 4. main factorial store to stack recursive case load from stack base case Trace what happens for an input of 3... 3 CPU Registers Memory ??? r1 r13 r14 100 101 102 103 104 105 r15 100 "the stack" input: x return value (the "result") return address (line #) the stack pointer r15 00 read r1 01 setn r15 100 02 call r14 06 03 write r13 04 halt 05 nop 06 jnez r1 09 07 setn r13 1 08 jumpr r14 09 addn r15 1 10 storer r1 r15 11 addn r15 1 12 storer r14 r15 13 addn r1 -1 14 call r14 06 15 loadr r14 r15 16 addn r15 -1 17 loadr r1 r15 18 addn r15 -1 19 mul r13 r13 r1 20 jumpr r14 106 107 It's easy to get lost! Follow the line numbers below to stay on track... 0, 1, 2, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 7, 8, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 3, 4
  • 5. main factorial store to stack recursive case load from stack base case Trace what happens for an input of 3... 3 03 r1 r13 r14 CPU Registers Memory 100 101 102 103 104 105 r15 100 "the stack" input: x return value (the "result") return address (line #) the stack pointer r15 00 read r1 01 setn r15 100 02 call r14 06 03 write r13 04 halt 05 nop 06 jnez r1 09 07 setn r13 1 08 jumpr r14 09 addn r15 1 10 storer r1 r15 11 addn r15 1 12 storer r14 r15 13 addn r1 -1 14 call r14 06 15 loadr r14 r15 16 addn r15 -1 17 loadr r1 r15 18 addn r15 -1 19 mul r13 r13 r1 20 jumpr r14 106 107 It's easy to get lost! Follow the line numbers below to stay on track... 0, 1, 2, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 7, 8, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 3, 4
  • 6. main factorial store to stack recursive case load from stack base case Trace what happens for an input of 3... 3 03 r1 r13 r14 CPU Registers Memory 100 101 102 103 104 105 r15 100 "the stack" input: x return value (the "result") return address (line #) the stack pointer r15 00 read r1 01 setn r15 100 02 call r14 06 03 write r13 04 halt 05 nop 06 jnez r1 09 07 setn r13 1 08 jumpr r14 09 addn r15 1 10 storer r1 r15 11 addn r15 1 12 storer r14 r15 13 addn r1 -1 14 call r14 06 15 loadr r14 r15 16 addn r15 -1 17 loadr r1 r15 18 addn r15 -1 19 mul r13 r13 r1 20 jumpr r14 106 107 It's easy to get lost! Follow the line numbers below to stay on track... 0, 1, 2, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 7, 8, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 3, 4
  • 7. main factorial store to stack recursive case load from stack base case Trace what happens for an input of 3... 3 03 r1 r13 r14 CPU Registers Memory 100 101 102 103 104 105 r15 100 "the stack" input: x return value (the "result") return address (line #) the stack pointer r15 00 read r1 01 setn r15 100 02 call r14 06 03 write r13 04 halt 05 nop 06 jnez r1 09 07 setn r13 1 08 jumpr r14 09 addn r15 1 10 storer r1 r15 11 addn r15 1 12 storer r14 r15 13 addn r1 -1 14 call r14 06 15 loadr r14 r15 16 addn r15 -1 17 loadr r1 r15 18 addn r15 -1 19 mul r13 r13 r1 20 jumpr r14 106 107 It's easy to get lost! Follow the line numbers below to stay on track... 0, 1, 2, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 7, 8, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 3, 4
  • 8. main factorial store to stack recursive case load from stack base case Trace what happens for an input of 3... 3 03 r1 r13 r14 CPU Registers Memory 100 101 102 103 104 105 r15 100 "the stack" input: x return value (the "result") return address (line #) the stack pointer r15 00 read r1 01 setn r15 100 02 call r14 06 03 write r13 04 halt 05 nop 06 jnez r1 09 07 setn r13 1 08 jumpr r14 09 addn r15 1 10 storer r1 r15 11 addn r15 1 12 storer r14 r15 13 addn r1 -1 14 call r14 06 15 loadr r14 r15 16 addn r15 -1 17 loadr r1 r15 18 addn r15 -1 19 mul r13 r13 r1 20 jumpr r14 106 107 It's easy to get lost! Follow the line numbers below to stay on track... 0, 1, 2, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 7, 8, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 3, 4
  • 9. main factorial store to stack recursive case load from stack base case Trace what happens for an input of 3... 3 03 r1 r13 r14 CPU Registers Memory 100 101 102 103 104 105 r15 100,101 "the stack" input: x return value (the "result") return address (line #) the stack pointer r15 00 read r1 01 setn r15 100 02 call r14 06 03 write r13 04 halt 05 nop 06 jnez r1 09 07 setn r13 1 08 jumpr r14 09 addn r15 1 10 storer r1 r15 11 addn r15 1 12 storer r14 r15 13 addn r1 -1 14 call r14 06 15 loadr r14 r15 16 addn r15 -1 17 loadr r1 r15 18 addn r15 -1 19 mul r13 r13 r1 20 jumpr r14 106 107 It's easy to get lost! Follow the line numbers below to stay on track... 0, 1, 2, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 7, 8, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 3, 4
  • 10. main factorial store to stack recursive case load from stack base case Trace what happens for an input of 3... 3 03 r1 r13 r14 CPU Registers Memory 100 101 102 103 104 105 r15 100,101 "the stack" input: x return value (the "result") return address (line #) the stack pointer r15 00 read r1 01 setn r15 100 02 call r14 06 03 write r13 04 halt 05 nop 06 jnez r1 09 07 setn r13 1 08 jumpr r14 09 addn r15 1 10 storer r1 r15 11 addn r15 1 12 storer r14 r15 13 addn r1 -1 14 call r14 06 15 loadr r14 r15 16 addn r15 -1 17 loadr r1 r15 18 addn r15 -1 19 mul r13 r13 r1 20 jumpr r14 106 107 It's easy to get lost! Follow the line numbers below to stay on track... 0, 1, 2, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 7, 8, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 3, 4
  • 11. main factorial store to stack recursive case load from stack base case Trace what happens for an input of 3... 3 03 r1 r13 r14 CPU Registers Memory 3 100 101 102 103 104 105 r15 100,101 "the stack" input: x return value (the "result") return address (line #) the stack pointer r15 00 read r1 01 setn r15 100 02 call r14 06 03 write r13 04 halt 05 nop 06 jnez r1 09 07 setn r13 1 08 jumpr r14 09 addn r15 1 10 storer r1 r15 11 addn r15 1 12 storer r14 r15 13 addn r1 -1 14 call r14 06 15 loadr r14 r15 16 addn r15 -1 17 loadr r1 r15 18 addn r15 -1 19 mul r13 r13 r1 20 jumpr r14 106 107 It's easy to get lost! Follow the line numbers below to stay on track... 0, 1, 2, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 7, 8, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 3, 4
  • 12. main factorial store to stack recursive case load from stack base case Trace what happens for an input of 3... 3 03 r1 r13 r14 CPU Registers Memory 3 100 101 102 103 104 105 r15 100,101,102 "the stack" input: x return value (the "result") return address (line #) the stack pointer r15 00 read r1 01 setn r15 100 02 call r14 06 03 write r13 04 halt 05 nop 06 jnez r1 09 07 setn r13 1 08 jumpr r14 09 addn r15 1 10 storer r1 r15 11 addn r15 1 12 storer r14 r15 13 addn r1 -1 14 call r14 06 15 loadr r14 r15 16 addn r15 -1 17 loadr r1 r15 18 addn r15 -1 19 mul r13 r13 r1 20 jumpr r14 106 107 It's easy to get lost! Follow the line numbers below to stay on track... 0, 1, 2, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 7, 8, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 3, 4
  • 13. main factorial store to stack recursive case load from stack base case Trace what happens for an input of 3... 3 03 r1 r13 r14 CPU Registers Memory 3 03 100 101 102 103 104 105 r15 100,101,102 "the stack" input: x return value (the "result") return address (line #) the stack pointer 00 read r1 01 setn r15 100 02 call r14 06 03 write r13 04 halt 05 nop 06 jnez r1 09 07 setn r13 1 08 jumpr r14 09 addn r15 1 10 storer r1 r15 11 addn r15 1 12 storer r14 r15 13 addn r1 -1 14 call r14 06 15 loadr r14 r15 16 addn r15 -1 17 loadr r1 r15 18 addn r15 -1 19 mul r13 r13 r1 20 jumpr r14 106 107 It's easy to get lost! Follow the line numbers below to stay on track... r15 0, 1, 2, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 7, 8, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 3, 4
  • 14. main factorial store to stack recursive case load from stack base case Trace what happens for an input of 3... CPU Registers Memory 3, 2 03 r1 r13 r14 3 03 100 101 102 103 104 105 r15 100,101,102 "the stack" input: x return value (the "result") return address (line #) the stack pointer 00 read r1 01 setn r15 100 02 call r14 06 03 write r13 04 halt 05 nop 06 jnez r1 09 07 setn r13 1 08 jumpr r14 09 addn r15 1 10 storer r1 r15 11 addn r15 1 12 storer r14 r15 13 addn r1 -1 14 call r14 06 15 loadr r14 r15 16 addn r15 -1 17 loadr r1 r15 18 addn r15 -1 19 mul r13 r13 r1 20 jumpr r14 106 107 It's easy to get lost! Follow the line numbers below to stay on track... r15 0, 1, 2, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 7, 8, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 3, 4
  • 15. main factorial store to stack recursive case load from stack base case Trace what happens for an input of 3... CPU Registers Memory 3,2 03 r1 r13 r14 3 03 100 101 102 103 104 105 r15 100,101,102 "the stack" input: x return value (the "result") return address (line #) the stack pointer 00 read r1 01 setn r15 100 02 call r14 06 03 write r13 04 halt 05 nop 06 jnez r1 09 07 setn r13 1 08 jumpr r14 09 addn r15 1 10 storer r1 r15 11 addn r15 1 12 storer r14 r15 13 addn r1 -1 14 call r14 06 15 loadr r14 r15 16 addn r15 -1 17 loadr r1 r15 18 addn r15 -1 19 mul r13 r13 r1 20 jumpr r14 106 107 It's easy to get lost! Follow the line numbers below to stay on track... r15 0, 1, 2, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 7, 8, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 3, 4
  • 16. main factorial store to stack recursive case load from stack base case Trace what happens for an input of 3... CPU Registers Memory 3,2 03,15 r1 r13 r14 3 03 100 101 102 103 104 105 r15 100,101,102 "the stack" input: x return value (the "result") return address (line #) the stack pointer 00 read r1 01 setn r15 100 02 call r14 06 03 write r13 04 halt 05 nop 06 jnez r1 09 07 setn r13 1 08 jumpr r14 09 addn r15 1 10 storer r1 r15 11 addn r15 1 12 storer r14 r15 13 addn r1 -1 14 call r14 06 15 loadr r14 r15 16 addn r15 -1 17 loadr r1 r15 18 addn r15 -1 19 mul r13 r13 r1 20 jumpr r14 106 107 It's easy to get lost! Follow the line numbers below to stay on track... r15 0, 1, 2, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 7, 8, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 3, 4
  • 17. main factorial store to stack recursive case load from stack base case Trace what happens for an input of 3... CPU Registers Memory 3,2 03,15 r1 r13 r14 3 03 100 101 102 103 104 105 r15 100,101,102 "the stack" input: x return value (the "result") return address (line #) the stack pointer 00 read r1 01 setn r15 100 02 call r14 06 03 write r13 04 halt 05 nop 06 jnez r1 09 07 setn r13 1 08 jumpr r14 09 addn r15 1 10 storer r1 r15 11 addn r15 1 12 storer r14 r15 13 addn r1 -1 14 call r14 06 15 loadr r14 r15 16 addn r15 -1 17 loadr r1 r15 18 addn r15 -1 19 mul r13 r13 r1 20 jumpr r14 106 107 It's easy to get lost! Follow the line numbers below to stay on track... r15 0, 1, 2, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 7, 8, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 3, 4
  • 18. main factorial store to stack recursive case load from stack base case Trace what happens for an input of 3... CPU Registers Memory 3,2 03,15 r1 r13 r14 3 03 100 101 102 103 104 105 r15 100,101,102 "the stack" input: x return value (the "result") return address (line #) the stack pointer 00 read r1 01 setn r15 100 02 call r14 06 03 write r13 04 halt 05 nop 06 jnez r1 09 07 setn r13 1 08 jumpr r14 09 addn r15 1 10 storer r1 r15 11 addn r15 1 12 storer r14 r15 13 addn r1 -1 14 call r14 06 15 loadr r14 r15 16 addn r15 -1 17 loadr r1 r15 18 addn r15 -1 19 mul r13 r13 r1 20 jumpr r14 106 107 It's easy to get lost! Follow the line numbers below to stay on track... r15 0, 1, 2, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 7, 8, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 3, 4
  • 19. main factorial store to stack recursive case load from stack base case Trace what happens for an input of 3... CPU Registers Memory 3,2 03,15 r1 r13 r14 3 03 100 101 102 103 104 105 r15 100,101,102,103 "the stack" input: x return value (the "result") return address (line #) the stack pointer 00 read r1 01 setn r15 100 02 call r14 06 03 write r13 04 halt 05 nop 06 jnez r1 09 07 setn r13 1 08 jumpr r14 09 addn r15 1 10 storer r1 r15 11 addn r15 1 12 storer r14 r15 13 addn r1 -1 14 call r14 06 15 loadr r14 r15 16 addn r15 -1 17 loadr r1 r15 18 addn r15 -1 19 mul r13 r13 r1 20 jumpr r14 106 107 It's easy to get lost! Follow the line numbers below to stay on track... r15 0, 1, 2, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 7, 8, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 3, 4
  • 20. main factorial store to stack recursive case load from stack base case Trace what happens for an input of 3... CPU Registers Memory 3,2 03,15 r1 r13 r14 3 03 2 100 101 102 103 104 105 r15 100,101,102,103 "the stack" input: x return value (the "result") return address (line #) the stack pointer 00 read r1 01 setn r15 100 02 call r14 06 03 write r13 04 halt 05 nop 06 jnez r1 09 07 setn r13 1 08 jumpr r14 09 addn r15 1 10 storer r1 r15 11 addn r15 1 12 storer r14 r15 13 addn r1 -1 14 call r14 06 15 loadr r14 r15 16 addn r15 -1 17 loadr r1 r15 18 addn r15 -1 19 mul r13 r13 r1 20 jumpr r14 106 107 It's easy to get lost! Follow the line numbers below to stay on track... r15 0, 1, 2, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 7, 8, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 3, 4
  • 21. main factorial store to stack recursive case load from stack base case Trace what happens for an input of 3... CPU Registers Memory 3,2 03,15 r1 r13 r14 3 03 2 100 101 102 103 104 105 100,101,102,103, 104 r15 "the stack" input: x return value (the "result") return address (line #) the stack pointer 00 read r1 01 setn r15 100 02 call r14 06 03 write r13 04 halt 05 nop 06 jnez r1 09 07 setn r13 1 08 jumpr r14 09 addn r15 1 10 storer r1 r15 11 addn r15 1 12 storer r14 r15 13 addn r1 -1 14 call r14 06 15 loadr r14 r15 16 addn r15 -1 17 loadr r1 r15 18 addn r15 -1 19 mul r13 r13 r1 20 jumpr r14 106 107 It's easy to get lost! Follow the line numbers below to stay on track... r15 0, 1, 2, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 7, 8, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 3, 4
  • 22. main factorial store to stack recursive case load from stack base case Trace what happens for an input of 3... CPU Registers Memory 3,2 03,15 r1 r13 r14 3 03 2 15 100 101 102 103 104 105 100,101,102,103, 104 r15 "the stack" input: x return value (the "result") return address (line #) the stack pointer 00 read r1 01 setn r15 100 02 call r14 06 03 write r13 04 halt 05 nop 06 jnez r1 09 07 setn r13 1 08 jumpr r14 09 addn r15 1 10 storer r1 r15 11 addn r15 1 12 storer r14 r15 13 addn r1 -1 14 call r14 06 15 loadr r14 r15 16 addn r15 -1 17 loadr r1 r15 18 addn r15 -1 19 mul r13 r13 r1 20 jumpr r14 106 107 It's easy to get lost! Follow the line numbers below to stay on track... r15 0, 1, 2, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 7, 8, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 3, 4
  • 23. main factorial store to stack recursive case load from stack base case Trace what happens for an input of 3... CPU Registers Memory 3,2,1 03,15 r1 r13 r14 3 03 2 15 100 101 102 103 104 105 100,101,102,103, 104 r15 "the stack" input: x return value (the "result") return address (line #) the stack pointer 00 read r1 01 setn r15 100 02 call r14 06 03 write r13 04 halt 05 nop 06 jnez r1 09 07 setn r13 1 08 jumpr r14 09 addn r15 1 10 storer r1 r15 11 addn r15 1 12 storer r14 r15 13 addn r1 -1 14 call r14 06 15 loadr r14 r15 16 addn r15 -1 17 loadr r1 r15 18 addn r15 -1 19 mul r13 r13 r1 20 jumpr r14 106 107 It's easy to get lost! Follow the line numbers below to stay on track... r15 0, 1, 2, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 7, 8, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 3, 4
  • 24. main factorial store to stack recursive case load from stack base case Trace what happens for an input of 3... CPU Registers Memory 3,2,1 03,15,15 r1 r13 r14 3 03 2 15 100 101 102 103 104 105 100,101,102,103, 104 r15 "the stack" input: x return value (the "result") return address (line #) the stack pointer 00 read r1 01 setn r15 100 02 call r14 06 03 write r13 04 halt 05 nop 06 jnez r1 09 07 setn r13 1 08 jumpr r14 09 addn r15 1 10 storer r1 r15 11 addn r15 1 12 storer r14 r15 13 addn r1 -1 14 call r14 06 15 loadr r14 r15 16 addn r15 -1 17 loadr r1 r15 18 addn r15 -1 19 mul r13 r13 r1 20 jumpr r14 106 107 It's easy to get lost! Follow the line numbers below to stay on track... r15 0, 1, 2, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 7, 8, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 3, 4
  • 25. main factorial store to stack recursive case load from stack base case Trace what happens for an input of 3... CPU Registers Memory 3,2,1 03,15,15 r1 r13 r14 3 03 2 15 100 101 102 103 104 105 100,101,102,103, 104 r15 "the stack" input: x return value (the "result") return address (line #) the stack pointer 00 read r1 01 setn r15 100 02 call r14 06 03 write r13 04 halt 05 nop 06 jnez r1 09 07 setn r13 1 08 jumpr r14 09 addn r15 1 10 storer r1 r15 11 addn r15 1 12 storer r14 r15 13 addn r1 -1 14 call r14 06 15 loadr r14 r15 16 addn r15 -1 17 loadr r1 r15 18 addn r15 -1 19 mul r13 r13 r1 20 jumpr r14 106 107 It's easy to get lost! Follow the line numbers below to stay on track... r15 0, 1, 2, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 7, 8, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 3, 4
  • 26. main factorial store to stack recursive case load from stack base case Trace what happens for an input of 3... CPU Registers Memory 3,2,1 03,15,15 r1 r13 r14 3 03 2 15 100 101 102 103 104 105 100,101,102,103, 104,105 r15 "the stack" input: x return value (the "result") return address (line #) the stack pointer 00 read r1 01 setn r15 100 02 call r14 06 03 write r13 04 halt 05 nop 06 jnez r1 09 07 setn r13 1 08 jumpr r14 09 addn r15 1 10 storer r1 r15 11 addn r15 1 12 storer r14 r15 13 addn r1 -1 14 call r14 06 15 loadr r14 r15 16 addn r15 -1 17 loadr r1 r15 18 addn r15 -1 19 mul r13 r13 r1 20 jumpr r14 106 107 It's easy to get lost! Follow the line numbers below to stay on track... r15 0, 1, 2, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 7, 8, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 3, 4
  • 27. main factorial store to stack recursive case load from stack base case Trace what happens for an input of 3... CPU Registers Memory 3,2,1 03,15,15 r1 r13 r14 3 03 2 15 1 100 101 102 103 104 105 100,101,102,103, 104,105 r15 "the stack" input: x return value (the "result") return address (line #) the stack pointer 00 read r1 01 setn r15 100 02 call r14 06 03 write r13 04 halt 05 nop 06 jnez r1 09 07 setn r13 1 08 jumpr r14 09 addn r15 1 10 storer r1 r15 11 addn r15 1 12 storer r14 r15 13 addn r1 -1 14 call r14 06 15 loadr r14 r15 16 addn r15 -1 17 loadr r1 r15 18 addn r15 -1 19 mul r13 r13 r1 20 jumpr r14 106 107 It's easy to get lost! Follow the line numbers below to stay on track... r15 0, 1, 2, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 7, 8, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 3, 4
  • 28. main factorial store to stack recursive case load from stack base case Trace what happens for an input of 3... CPU Registers Memory 3,2,1 03,15,15 r1 r13 r14 3 03 2 15 1 100 101 102 103 104 105 100,101,102,103, 104,105,106 r15 "the stack" input: x return value (the "result") return address (line #) the stack pointer 00 read r1 01 setn r15 100 02 call r14 06 03 write r13 04 halt 05 nop 06 jnez r1 09 07 setn r13 1 08 jumpr r14 09 addn r15 1 10 storer r1 r15 11 addn r15 1 12 storer r14 r15 13 addn r1 -1 14 call r14 06 15 loadr r14 r15 16 addn r15 -1 17 loadr r1 r15 18 addn r15 -1 19 mul r13 r13 r1 20 jumpr r14 106 107 It's easy to get lost! Follow the line numbers below to stay on track... r15 0, 1, 2, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 7, 8, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 3, 4
  • 29. main factorial store to stack recursive case load from stack base case Trace what happens for an input of 3... CPU Registers Memory 3,2,1 03,15,15 r1 r13 r14 3 03 2 15 1 100 101 102 103 104 105 100,101,102,103, 104,105,106 r15 "the stack" input: x return value (the "result") return address (line #) the stack pointer 00 read r1 01 setn r15 100 02 call r14 06 03 write r13 04 halt 05 nop 06 jnez r1 09 07 setn r13 1 08 jumpr r14 09 addn r15 1 10 storer r1 r15 11 addn r15 1 12 storer r14 r15 13 addn r1 -1 14 call r14 06 15 loadr r14 r15 16 addn r15 -1 17 loadr r1 r15 18 addn r15 -1 19 mul r13 r13 r1 20 jumpr r14 106 107 It's easy to get lost! 15 Follow the line numbers below to stay on track... r15 0, 1, 2, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 7, 8, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 3, 4
  • 30. main factorial store to stack recursive case load from stack base case Trace what happens for an input of 3... CPU Registers Memory 3,2,1,0 03,15,15 r1 r13 r14 3 03 2 15 1 100 101 102 103 104 105 100,101,102,103, 104,105,106 r15 "the stack" input: x return value (the "result") return address (line #) the stack pointer 00 read r1 01 setn r15 100 02 call r14 06 03 write r13 04 halt 05 nop 06 jnez r1 09 07 setn r13 1 08 jumpr r14 09 addn r15 1 10 storer r1 r15 11 addn r15 1 12 storer r14 r15 13 addn r1 -1 14 call r14 06 15 loadr r14 r15 16 addn r15 -1 17 loadr r1 r15 18 addn r15 -1 19 mul r13 r13 r1 20 jumpr r14 106 107 It's easy to get lost! 15 Follow the line numbers below to stay on track... r15 0, 1, 2, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 7, 8, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 3, 4
  • 31. main factorial store to stack recursive case load from stack base case Trace what happens for an input of 3... CPU Registers Memory 3,2,1,0 03,15,15,15 r1 r13 r14 3 03 2 15 1 100 101 102 103 104 105 100,101,102,103, 104,105,106 r15 "the stack" input: x return value (the "result") return address (line #) the stack pointer 00 read r1 01 setn r15 100 02 call r14 06 03 write r13 04 halt 05 nop 06 jnez r1 09 07 setn r13 1 08 jumpr r14 09 addn r15 1 10 storer r1 r15 11 addn r15 1 12 storer r14 r15 13 addn r1 -1 14 call r14 06 15 loadr r14 r15 16 addn r15 -1 17 loadr r1 r15 18 addn r15 -1 19 mul r13 r13 r1 20 jumpr r14 106 107 It's easy to get lost! 15 Follow the line numbers below to stay on track... r15 0, 1, 2, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 7, 8, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 3, 4
  • 32. main factorial store to stack recursive case load from stack base case Trace what happens for an input of 3... CPU Registers Memory 3,2,1,0 03,15,15,15 r1 r13 r14 3 03 2 15 1 100 101 102 103 104 105 100,101,102,103, 104,105,106 r15 "the stack" input: x return value (the "result") return address (line #) the stack pointer 00 read r1 01 setn r15 100 02 call r14 06 03 write r13 04 halt 05 nop 06 jnez r1 09 07 setn r13 1 08 jumpr r14 09 addn r15 1 10 storer r1 r15 11 addn r15 1 12 storer r14 r15 13 addn r1 -1 14 call r14 06 15 loadr r14 r15 16 addn r15 -1 17 loadr r1 r15 18 addn r15 -1 19 mul r13 r13 r1 20 jumpr r14 106 107 It's easy to get lost! 15 Follow the line numbers below to stay on track... r15 0, 1, 2, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 7, 8, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 3, 4
  • 33. main factorial store to stack recursive case load from stack base case Trace what happens for an input of 3... CPU Registers Memory 3,2,1,0 1 03,15,15,15 r1 r13 r14 3 03 2 15 1 100 101 102 103 104 105 100,101,102,103, 104,105,106 r15 "the stack" input: x return value (the "result") return address (line #) the stack pointer 00 read r1 01 setn r15 100 02 call r14 06 03 write r13 04 halt 05 nop 06 jnez r1 09 07 setn r13 1 08 jumpr r14 09 addn r15 1 10 storer r1 r15 11 addn r15 1 12 storer r14 r15 13 addn r1 -1 14 call r14 06 15 loadr r14 r15 16 addn r15 -1 17 loadr r1 r15 18 addn r15 -1 19 mul r13 r13 r1 20 jumpr r14 106 107 It's easy to get lost! 15 Follow the line numbers below to stay on track... r15 0, 1, 2, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 7, 8, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 3, 4
  • 34. main factorial store to stack recursive case load from stack base case Trace what happens for an input of 3... CPU Registers Memory 3,2,1,0 1 03,15,15,15 r1 r13 r14 3 03 2 15 1 100 101 102 103 104 105 100,101,102,103, 104,105,106 r15 "the stack" input: x return value (the "result") return address (line #) the stack pointer 00 read r1 01 setn r15 100 02 call r14 06 03 write r13 04 halt 05 nop 06 jnez r1 09 07 setn r13 1 08 jumpr r14 09 addn r15 1 10 storer r1 r15 11 addn r15 1 12 storer r14 r15 13 addn r1 -1 14 call r14 06 15 loadr r14 r15 16 addn r15 -1 17 loadr r1 r15 18 addn r15 -1 19 mul r13 r13 r1 20 jumpr r14 106 107 It's easy to get lost! 15 Follow the line numbers below to stay on track... r15 0, 1, 2, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 7, 8, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 3, 4
  • 35. main factorial store to stack recursive case load from stack base case Trace what happens for an input of 3... CPU Registers Memory 3,2,1,0 1 03,15,15,15 r1 r13 r14 3 03 2 15 1 100 101 102 103 104 105 100,101,102,103, 104,105,106 r15 "the stack" input: x return value (the "result") return address (line #) the stack pointer 00 read r1 01 setn r15 100 02 call r14 06 03 write r13 04 halt 05 nop 06 jnez r1 09 07 setn r13 1 08 jumpr r14 09 addn r15 1 10 storer r1 r15 11 addn r15 1 12 storer r14 r15 13 addn r1 -1 14 call r14 06 15 loadr r14 r15 16 addn r15 -1 17 loadr r1 r15 18 addn r15 -1 19 mul r13 r13 r1 20 jumpr r14 106 107 It's easy to get lost! 15 Follow the line numbers below to stay on track... r15 0, 1, 2, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 7, 8, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 3, 4
  • 36. main factorial store to stack recursive case load from stack base case Trace what happens for an input of 3... CPU Registers Memory 3,2,1,0 1 03,15,15,15 r1 r13 r14 3 03 2 15 1 100 101 102 103 104 105 100,101,102,103, 104,105,106 r15 "the stack" input: x return value (the "result") return address (line #) the stack pointer 00 read r1 01 setn r15 100 02 call r14 06 03 write r13 04 halt 05 nop 06 jnez r1 09 07 setn r13 1 08 jumpr r14 09 addn r15 1 10 storer r1 r15 11 addn r15 1 12 storer r14 r15 13 addn r1 -1 14 call r14 06 15 loadr r14 r15 16 addn r15 -1 17 loadr r1 r15 18 addn r15 -1 19 mul r13 r13 r1 20 jumpr r14 106 107 It's easy to get lost! 15 Follow the line numbers below to stay on track... r15 0, 1, 2, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 7, 8, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 3, 4
  • 37. main factorial store to stack recursive case load from stack base case Trace what happens for an input of 3... CPU Registers Memory 3,2,1,0 1 03,15,15,15,15 r1 r13 r14 3 03 2 15 1 100 101 102 103 104 105 100,101,102,103, 104,105,106 r15 "the stack" input: x return value (the "result") return address (line #) the stack pointer 00 read r1 01 setn r15 100 02 call r14 06 03 write r13 04 halt 05 nop 06 jnez r1 09 07 setn r13 1 08 jumpr r14 09 addn r15 1 10 storer r1 r15 11 addn r15 1 12 storer r14 r15 13 addn r1 -1 14 call r14 06 15 loadr r14 r15 16 addn r15 -1 17 loadr r1 r15 18 addn r15 -1 19 mul r13 r13 r1 20 jumpr r14 106 107 It's easy to get lost! 15 Follow the line numbers below to stay on track... r15 0, 1, 2, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 7, 8, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 3, 4
  • 38. main factorial store to stack recursive case load from stack base case Trace what happens for an input of 3... CPU Registers Memory 3,2,1,0 1 03,15,15,15,15 r1 r13 r14 3 03 2 15 1 100 101 102 103 104 105 100,101,102,103, 104,105,106,105 r15 "the stack" input: x return value (the "result") return address (line #) the stack pointer 00 read r1 01 setn r15 100 02 call r14 06 03 write r13 04 halt 05 nop 06 jnez r1 09 07 setn r13 1 08 jumpr r14 09 addn r15 1 10 storer r1 r15 11 addn r15 1 12 storer r14 r15 13 addn r1 -1 14 call r14 06 15 loadr r14 r15 16 addn r15 -1 17 loadr r1 r15 18 addn r15 -1 19 mul r13 r13 r1 20 jumpr r14 106 107 It's easy to get lost! 15 Follow the line numbers below to stay on track... r15 0, 1, 2, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 7, 8, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 3, 4
  • 39. main factorial store to stack recursive case load from stack base case Trace what happens for an input of 3... CPU Registers Memory 3,2,1,0,1 1 03,15,15,15,15 r1 r13 r14 3 03 2 15 1 100 101 102 103 104 105 100,101,102,103, 104,105,106,105 r15 "the stack" input: x return value (the "result") return address (line #) the stack pointer 00 read r1 01 setn r15 100 02 call r14 06 03 write r13 04 halt 05 nop 06 jnez r1 09 07 setn r13 1 08 jumpr r14 09 addn r15 1 10 storer r1 r15 11 addn r15 1 12 storer r14 r15 13 addn r1 -1 14 call r14 06 15 loadr r14 r15 16 addn r15 -1 17 loadr r1 r15 18 addn r15 -1 19 mul r13 r13 r1 20 jumpr r14 106 107 It's easy to get lost! 15 Follow the line numbers below to stay on track... r15 0, 1, 2, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 7, 8, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 3, 4
  • 40. main factorial store to stack recursive case load from stack base case Trace what happens for an input of 3... CPU Registers Memory 3,2,1,0,1 1 03,15,15,15,15 r1 r13 r14 3 03 2 15 1 100 101 102 103 104 105 100,101,102,103, 104,105,106,105, 104 r15 "the stack" input: x return value (the "result") return address (line #) the stack pointer 00 read r1 01 setn r15 100 02 call r14 06 03 write r13 04 halt 05 nop 06 jnez r1 09 07 setn r13 1 08 jumpr r14 09 addn r15 1 10 storer r1 r15 11 addn r15 1 12 storer r14 r15 13 addn r1 -1 14 call r14 06 15 loadr r14 r15 16 addn r15 -1 17 loadr r1 r15 18 addn r15 -1 19 mul r13 r13 r1 20 jumpr r14 106 107 It's easy to get lost! 15 Follow the line numbers below to stay on track... r15 0, 1, 2, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 7, 8, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 3, 4
  • 41. main factorial store to stack recursive case load from stack base case Trace what happens for an input of 3... CPU Registers Memory 3,2,1,0,1 1,1 03,15,15,15,15 r1 r13 r14 3 03 2 15 1 100 101 102 103 104 105 100,101,102,103, 104,105,106,105, 104 r15 "the stack" input: x return value (the "result") return address (line #) the stack pointer 00 read r1 01 setn r15 100 02 call r14 06 03 write r13 04 halt 05 nop 06 jnez r1 09 07 setn r13 1 08 jumpr r14 09 addn r15 1 10 storer r1 r15 11 addn r15 1 12 storer r14 r15 13 addn r1 -1 14 call r14 06 15 loadr r14 r15 16 addn r15 -1 17 loadr r1 r15 18 addn r15 -1 19 mul r13 r13 r1 20 jumpr r14 106 107 It's easy to get lost! 15 Follow the line numbers below to stay on track... r15 0, 1, 2, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 7, 8, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 3, 4
  • 42. main factorial store to stack recursive case load from stack base case Trace what happens for an input of 3... CPU Registers Memory 3,2,1,0,1 1,1 03,15,15,15,15 r1 r13 r14 3 03 2 15 1 100 101 102 103 104 105 100,101,102,103, 104,105,106,105, 104 r15 "the stack" input: x return value (the "result") return address (line #) the stack pointer 00 read r1 01 setn r15 100 02 call r14 06 03 write r13 04 halt 05 nop 06 jnez r1 09 07 setn r13 1 08 jumpr r14 09 addn r15 1 10 storer r1 r15 11 addn r15 1 12 storer r14 r15 13 addn r1 -1 14 call r14 06 15 loadr r14 r15 16 addn r15 -1 17 loadr r1 r15 18 addn r15 -1 19 mul r13 r13 r1 20 jumpr r14 106 107 It's easy to get lost! 15 Follow the line numbers below to stay on track... r15 0, 1, 2, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 7, 8, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 3, 4
  • 43. main factorial store to stack recursive case load from stack base case Trace what happens for an input of 3... CPU Registers Memory 3,2,1,0,1 1,1 03,15,15,15,15, 15 r1 r13 r14 3 03 2 15 1 100 101 102 103 104 105 100,101,102,103, 104,105,106,105, 104 r15 "the stack" input: x return value (the "result") return address (line #) the stack pointer 00 read r1 01 setn r15 100 02 call r14 06 03 write r13 04 halt 05 nop 06 jnez r1 09 07 setn r13 1 08 jumpr r14 09 addn r15 1 10 storer r1 r15 11 addn r15 1 12 storer r14 r15 13 addn r1 -1 14 call r14 06 15 loadr r14 r15 16 addn r15 -1 17 loadr r1 r15 18 addn r15 -1 19 mul r13 r13 r1 20 jumpr r14 106 107 It's easy to get lost! 15 Follow the line numbers below to stay on track... r15 0, 1, 2, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 7, 8, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 3, 4
  • 44. main factorial store to stack recursive case load from stack base case Trace what happens for an input of 3... CPU Registers Memory 3,2,1,0,1 1,1 03,15,15,15,15, 15 r1 r13 r14 3 03 2 15 1 100 101 102 103 104 105 100,101,102,103, 104,105,106,105, 104,103 r15 "the stack" input: x return value (the "result") return address (line #) the stack pointer 00 read r1 01 setn r15 100 02 call r14 06 03 write r13 04 halt 05 nop 06 jnez r1 09 07 setn r13 1 08 jumpr r14 09 addn r15 1 10 storer r1 r15 11 addn r15 1 12 storer r14 r15 13 addn r1 -1 14 call r14 06 15 loadr r14 r15 16 addn r15 -1 17 loadr r1 r15 18 addn r15 -1 19 mul r13 r13 r1 20 jumpr r14 106 107 It's easy to get lost! 15 Follow the line numbers below to stay on track... r15 0, 1, 2, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 7, 8, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 3, 4
  • 45. main factorial store to stack recursive case load from stack base case Trace what happens for an input of 3... CPU Registers Memory 3,2,1,0,1,2 1,1 03,15,15,15,15, 15 r1 r13 r14 3 03 2 15 1 100 101 102 103 104 105 100,101,102,103, 104,105,106,105, 104,103 r15 "the stack" input: x return value (the "result") return address (line #) the stack pointer 00 read r1 01 setn r15 100 02 call r14 06 03 write r13 04 halt 05 nop 06 jnez r1 09 07 setn r13 1 08 jumpr r14 09 addn r15 1 10 storer r1 r15 11 addn r15 1 12 storer r14 r15 13 addn r1 -1 14 call r14 06 15 loadr r14 r15 16 addn r15 -1 17 loadr r1 r15 18 addn r15 -1 19 mul r13 r13 r1 20 jumpr r14 106 107 It's easy to get lost! 15 Follow the line numbers below to stay on track... r15 0, 1, 2, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 7, 8, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 3, 4
  • 46. main factorial store to stack recursive case load from stack base case Trace what happens for an input of 3... CPU Registers Memory 3,2,1,0,1,2 1,1 03,15,15,15,15, 15 r1 r13 r14 3 03 2 15 1 100 101 102 103 104 105 100,101,102,103, 104,105,106,105, 104,103,102 r15 "the stack" input: x return value (the "result") return address (line #) the stack pointer 00 read r1 01 setn r15 100 02 call r14 06 03 write r13 04 halt 05 nop 06 jnez r1 09 07 setn r13 1 08 jumpr r14 09 addn r15 1 10 storer r1 r15 11 addn r15 1 12 storer r14 r15 13 addn r1 -1 14 call r14 06 15 loadr r14 r15 16 addn r15 -1 17 loadr r1 r15 18 addn r15 -1 19 mul r13 r13 r1 20 jumpr r14 106 107 It's easy to get lost! 15 Follow the line numbers below to stay on track... r15 0, 1, 2, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 7, 8, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 3, 4
  • 47. main factorial store to stack recursive case load from stack base case Trace what happens for an input of 3... CPU Registers Memory 3,2,1,0,1,2 1,1,2 03,15,15,15,15, 15 r1 r13 r14 3 03 2 15 1 100 101 102 103 104 105 100,101,102,103, 104,105,106,105, 104,103,102 r15 "the stack" input: x return value (the "result") return address (line #) the stack pointer 00 read r1 01 setn r15 100 02 call r14 06 03 write r13 04 halt 05 nop 06 jnez r1 09 07 setn r13 1 08 jumpr r14 09 addn r15 1 10 storer r1 r15 11 addn r15 1 12 storer r14 r15 13 addn r1 -1 14 call r14 06 15 loadr r14 r15 16 addn r15 -1 17 loadr r1 r15 18 addn r15 -1 19 mul r13 r13 r1 20 jumpr r14 106 107 It's easy to get lost! 15 Follow the line numbers below to stay on track... r15 0, 1, 2, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 7, 8, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 3, 4
  • 48. main factorial store to stack recursive case load from stack base case Trace what happens for an input of 3... CPU Registers Memory 3,2,1,0,1,2 1,1,2 03,15,15,15,15, 15 r1 r13 r14 3 03 2 15 1 100 101 102 103 104 105 100,101,102,103, 104,105,106,105, 104,103,102 r15 "the stack" input: x return value (the "result") return address (line #) the stack pointer 00 read r1 01 setn r15 100 02 call r14 06 03 write r13 04 halt 05 nop 06 jnez r1 09 07 setn r13 1 08 jumpr r14 09 addn r15 1 10 storer r1 r15 11 addn r15 1 12 storer r14 r15 13 addn r1 -1 14 call r14 06 15 loadr r14 r15 16 addn r15 -1 17 loadr r1 r15 18 addn r15 -1 19 mul r13 r13 r1 20 jumpr r14 106 107 It's easy to get lost! 15 Follow the line numbers below to stay on track... r15 0, 1, 2, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 7, 8, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 3, 4
  • 49. main factorial store to stack recursive case load from stack base case Trace what happens for an input of 3... CPU Registers Memory 3,2,1,0,1,2 1,1,2 03,15,15,15,15, 15,03 r1 r13 r14 3 03 2 15 1 100 101 102 103 104 105 100,101,102,103, 104,105,106,105, 104,103,102 r15 "the stack" input: x return value (the "result") return address (line #) the stack pointer 00 read r1 01 setn r15 100 02 call r14 06 03 write r13 04 halt 05 nop 06 jnez r1 09 07 setn r13 1 08 jumpr r14 09 addn r15 1 10 storer r1 r15 11 addn r15 1 12 storer r14 r15 13 addn r1 -1 14 call r14 06 15 loadr r14 r15 16 addn r15 -1 17 loadr r1 r15 18 addn r15 -1 19 mul r13 r13 r1 20 jumpr r14 106 107 It's easy to get lost! 15 Follow the line numbers below to stay on track... r15 0, 1, 2, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 7, 8, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 3, 4
  • 50. main factorial store to stack recursive case load from stack base case Trace what happens for an input of 3... CPU Registers Memory 3,2,1,0,1,2 1,1,2 03,15,15,15,15, 15,03 r1 r13 r14 3 03 2 15 1 100 101 102 103 104 105 100,101,102,103, 104,105,106,105, 104,103,102,101 r15 "the stack" input: x return value (the "result") return address (line #) the stack pointer 00 read r1 01 setn r15 100 02 call r14 06 03 write r13 04 halt 05 nop 06 jnez r1 09 07 setn r13 1 08 jumpr r14 09 addn r15 1 10 storer r1 r15 11 addn r15 1 12 storer r14 r15 13 addn r1 -1 14 call r14 06 15 loadr r14 r15 16 addn r15 -1 17 loadr r1 r15 18 addn r15 -1 19 mul r13 r13 r1 20 jumpr r14 106 107 It's easy to get lost! 15 Follow the line numbers below to stay on track... r15 0, 1, 2, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 7, 8, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 3, 4
  • 51. main factorial store to stack recursive case load from stack base case Trace what happens for an input of 3... CPU Registers Memory 3,2,1,0,1,2,3 1,1,2 03,15,15,15,15, 15,03 r1 r13 r14 3 03 2 15 1 100 101 102 103 104 105 100,101,102,103, 104,105,106,105, 104,103,102,101 r15 "the stack" input: x return value (the "result") return address (line #) the stack pointer 00 read r1 01 setn r15 100 02 call r14 06 03 write r13 04 halt 05 nop 06 jnez r1 09 07 setn r13 1 08 jumpr r14 09 addn r15 1 10 storer r1 r15 11 addn r15 1 12 storer r14 r15 13 addn r1 -1 14 call r14 06 15 loadr r14 r15 16 addn r15 -1 17 loadr r1 r15 18 addn r15 -1 19 mul r13 r13 r1 20 jumpr r14 106 107 It's easy to get lost! 15 Follow the line numbers below to stay on track... r15 0, 1, 2, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 7, 8, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 3, 4
  • 52. main factorial store to stack recursive case load from stack base case Trace what happens for an input of 3... CPU Registers Memory 3,2,1,0,1,2,3 1,1,2 03,15,15,15,15, 15,03 r1 r13 r14 3 03 2 15 1 100 101 102 103 104 105 100,101,102,103, 104,105,106,105, 104,103,102,101, 100 r15 "the stack" input: x return value (the "result") return address (line #) the stack pointer 00 read r1 01 setn r15 100 02 call r14 06 03 write r13 04 halt 05 nop 06 jnez r1 09 07 setn r13 1 08 jumpr r14 09 addn r15 1 10 storer r1 r15 11 addn r15 1 12 storer r14 r15 13 addn r1 -1 14 call r14 06 15 loadr r14 r15 16 addn r15 -1 17 loadr r1 r15 18 addn r15 -1 19 mul r13 r13 r1 20 jumpr r14 106 107 It's easy to get lost! 15 Follow the line numbers below to stay on track... r15 0, 1, 2, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 7, 8, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 3, 4
  • 53. main factorial store to stack recursive case load from stack base case Trace what happens for an input of 3... CPU Registers Memory 3,2,1,0,1,2,3 1,1,2,6 03,15,15,15,15, 15,03 r1 r13 r14 3 03 2 15 1 100 101 102 103 104 105 100,101,102,103, 104,105,106,105, 104,103,102,101, 100 r15 "the stack" input: x return value (the "result") return address (line #) the stack pointer 00 read r1 01 setn r15 100 02 call r14 06 03 write r13 04 halt 05 nop 06 jnez r1 09 07 setn r13 1 08 jumpr r14 09 addn r15 1 10 storer r1 r15 11 addn r15 1 12 storer r14 r15 13 addn r1 -1 14 call r14 06 15 loadr r14 r15 16 addn r15 -1 17 loadr r1 r15 18 addn r15 -1 19 mul r13 r13 r1 20 jumpr r14 106 107 It's easy to get lost! 15 Follow the line numbers below to stay on track... r15 0, 1, 2, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 7, 8, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 3, 4
  • 54. main factorial store to stack recursive case load from stack base case Trace what happens for an input of 3... CPU Registers Memory 3,2,1,0,1,2,3 1,1,2,6 03,15,15,15,15, 15,03 r1 r13 r14 3 03 2 15 1 100 101 102 103 104 105 100,101,102,103, 104,105,106,105, 104,103,102,101, 100 r15 "the stack" input: x return value (the "result") return address (line #) the stack pointer 00 read r1 01 setn r15 100 02 call r14 06 03 write r13 04 halt 05 nop 06 jnez r1 09 07 setn r13 1 08 jumpr r14 09 addn r15 1 10 storer r1 r15 11 addn r15 1 12 storer r14 r15 13 addn r1 -1 14 call r14 06 15 loadr r14 r15 16 addn r15 -1 17 loadr r1 r15 18 addn r15 -1 19 mul r13 r13 r1 20 jumpr r14 106 107 It's easy to get lost! 15 Follow the line numbers below to stay on track... r15 0, 1, 2, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 7, 8, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 3, 4
  • 55. main factorial store to stack recursive case load from stack base case Trace what happens for an input of 3... CPU Registers Memory 3,2,1,0,1,2,3 1,1,2,6 03,15,15,15,15, 15,03 r1 r13 r14 3 03 2 15 1 100 101 102 103 104 105 100,101,102,103, 104,105,106,105, 104,103,102,101, 100 r15 "the stack" input: x return value (the "result") return address (line #) the stack pointer 00 read r1 01 setn r15 100 02 call r14 06 03 write r13 04 halt 05 nop 06 jnez r1 09 07 setn r13 1 08 jumpr r14 09 addn r15 1 10 storer r1 r15 11 addn r15 1 12 storer r14 r15 13 addn r1 -1 14 call r14 06 15 loadr r14 r15 16 addn r15 -1 17 loadr r1 r15 18 addn r15 -1 19 mul r13 r13 r1 20 jumpr r14 106 107 It's easy to get lost! 15 Follow the line numbers below to stay on track... r15 0, 1, 2, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 7, 8, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 3, 4
  • 56. main factorial store to stack recursive case load from stack base case Trace what happens for an input of 3... CPU Registers Memory 3,2,1,0,1,2,3 1,1,2,6 03,15,15,15,15, 15,03 r1 r13 r14 3 03 2 15 1 100 101 102 103 104 105 100,101,102,103, 104,105,106,105, 104,103,102,101, 100 r15 "the stack" input: x return value (the "result") return address (line #) the stack pointer 00 read r1 01 setn r15 100 02 call r14 06 03 write r13 04 halt 05 nop 06 jnez r1 09 07 setn r13 1 08 jumpr r14 09 addn r15 1 10 storer r1 r15 11 addn r15 1 12 storer r14 r15 13 addn r1 -1 14 call r14 06 15 loadr r14 r15 16 addn r15 -1 17 loadr r1 r15 18 addn r15 -1 19 mul r13 r13 r1 20 jumpr r14 106 107 It's easy to get lost! 15 Follow the line numbers below to stay on track... r15 0, 1, 2, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 9, 10, 11, 12, 13, 14, 6, 7, 8 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 15, 16, 17, 18, 19, 20, 3, 4