Download presentation
Presentation is loading. Please wait.
1
CS41B recursion David Kauchak CS 52 – Fall 2015
2
Admin Midterm back on Thursday Assignments Survey in assignment 4
Assignment 4: due Monday (10/12 at 11:59pm) Assignment 5: due Friday (10/23 at 5pm) Assignment 6: due Monday (11/2 at 11:59pm) Survey in assignment 4 Academic Honesty
3
Academic Honesty A few rules to follow for this course to keep you out of trouble: If you talk with someone in the class about a problem, you should not take notes. If you understand the material you talked about, you should be able to recreate it on your own. Similarly, if you talk with someone, you must wait 5 minutes before resuming work on the problem. Stretch. Use the restroom. Go for a quick walk. This will ensure that you really understand the material. You may not sit next to (or where you can see the screen of) anyone you are talking with about the assignment. The only time you may look at someone else's screen is if they are asking you for help with a basic programming problem (e.g. syntax error). You should not look at someone else's code to help yourself!
4
Examples from this lecture
5
CS41B machine CPU instruction counter (location in memory of the next
instruction in memory) processor ic r0 holds the value 0 (read only) r1 general purpose read/write r2 registers r3
6
Memory layout Code Heap Stack
Code Where dynamically allocated program data is stored Heap Where program/function execution information is stored, parameters, and local variables Stack
7
Stack frame Key unit for keeping track of a function call
return address (where to go when we’re done executing) parameters local variables
8
CS41B function call conventions
r1: reserved for the stack pointer r2: contains the return address r3: contains the first parameter additional parameters go on the stack (more on this) the result (i.e. the return value) should go in r3
9
Structure of a single parameter function
fname psh r2 ; save return address on stack ... ; do work using r3 as argument ; put result in r3 pop r2 ; restore return address from stack jmp r2 ; return to caller conventions: argument is in r3 r1 is off-limits since it’s used for the stack pointer return value goes in r3
10
Our first function call
loa r3 r0 ; get variable lcw r2 increment ; call increment cal r2 r2 sto r0 r3 ; write result, hlt ; and halt increment psh r2 ; save the return address on the stack adc r3 r3 1 ; add 1 to the input parameter pop r2 ; get the return address from stack jmp r2 ; go back to where we were called from
11
Functions with multiple arguments
fname psh r2 ; save return address on stack loa r2 r1 4 ; load the second parameter into r2 ... ; do work using r3 and r2 as arguments ; put result in r3 pop r2 ; restore return address from stack jmp r2 ; return to caller conventions: first argument is in r3 r1 is off-limits since it’s used for the stack pointer return value goes in r3
12
Functions with multiple arguments
fname psh r2 ; save return address on stack loa r2 r1 4 ; load the second parameter into r2 ... ; do work using r3 and r2 as arguments ; put result in r3 pop r2 ; restore return address from stack jmp r2 ; return to caller What does this operation do? What is the 4?
13
Functions with multiple arguments
fname psh r2 ; save return address on stack loa r2 r1 4 ; load the second parameter into r2 ... ; do work using r3 and r2 as arguments ; put result in r3 pop r2 ; restore return address from stack jmp r2 ; return to caller r1 is the stack pointer and points at the top (next) slot stacks grow towards smaller memory values
14
Functions with multiple arguments
fname psh r2 ; save return address on stack loa r2 r1 4 ; load the second parameter into r2 ... ; do work using r3 and r2 as arguments ; put result in r3 pop r2 ; restore return address from stack jmp r2 ; return to caller r1 is the stack pointer and points at the top (next) slot stacks grow towards smaller memory values r1+2 is then the top value of the stack r1+4 is the 2nd value of the stack
15
Multiple arguments What does this code do?
max psh r2 loa r2 r1 4 bge r3 r2 endif adc r3 r2 0 endif pop r2 jmp r2 What does this code do?
16
Multiple arguments max, as a function!
max psh r2 loa r2 r1 4 bge r3 r2 endif adc r3 r2 0 endif pop r2 jmp r2 max, as a function!
17
Calling max loa r3 r0 loa r2 r0 psh r2 lcw r2 max cal r2 r2 pop r2 sto r0 r3 hlt Anything different?
18
Calling max For the second argument, push it on the stack
loa r3 r0 loa r2 r0 psh r2 lcw r2 max cal r2 r2 pop r2 sto r0 r3 hlt For the second argument, push it on the stack
19
loa r3 r0 loa r2 r0 psh r2 lcw r2 max cal r2 r2 pop r2 sto r0 r3 hlt max loa r2 r1 4 bge r3 r2 endif adc r3 r2 0 endif jmp r2 r2 r3 sp (r1) Stack
20
loa r3 r0 loa r2 r0 psh r2 lcw r2 max cal r2 r2 pop r2 sto r0 r3 hlt max loa r2 r1 4 bge r3 r2 endif adc r3 r2 0 endif jmp r2 r2 r3 10 sp (r1) Stack
21
loa r3 r0 loa r2 r0 psh r2 lcw r2 max cal r2 r2 pop r2 sto r0 r3 hlt max loa r2 r1 4 bge r3 r2 endif adc r3 r2 0 endif jmp r2 r2 2 r3 10 sp (r1) Stack
22
loa r3 r0 loa r2 r0 psh r2 lcw r2 max cal r2 r2 pop r2 sto r0 r3 hlt max loa r2 r1 4 bge r3 r2 endif adc r3 r2 0 endif jmp r2 r2 2 r3 10 sp (r1) 2 Stack
23
loa r3 r0 loa r2 r0 psh r2 lcw r2 max cal r2 r2 pop r2 sto r0 r3 hlt max loa r2 r1 4 bge r3 r2 endif adc r3 r2 0 endif jmp r2 r2 2 r3 10 sp (r1) 2 Stack
24
loa r3 r0 loa r2 r0 psh r2 lcw r2 max cal r2 r2 pop r2 sto r0 r3 hlt max loa r2 r1 4 bge r3 r2 endif adc r3 r2 0 endif jmp r2 r2 max r3 10 Notice that we overwrote the value in r2 If we hadn’t save it on the stack, it would have been lost sp (r1) 2 Stack
25
loa r3 r0 loa r2 r0 psh r2 lcw r2 max cal r2 r2 pop r2 sto r0 r3 hlt max loa r2 r1 4 bge r3 r2 endif adc r3 r2 0 endif jmp r2 r2 max r3 10 sp (r1) 2 Stack
26
loa r3 r0 loa r2 r0 psh r2 lcw r2 max cal r2 r2 pop r2 sto r0 r3 hlt max loa r2 r1 4 bge r3 r2 endif adc r3 r2 0 endif jmp r2 r2 loc: cal r3 10 sp (r1) 2 Stack
27
loa r3 r0 loa r2 r0 psh r2 lcw r2 max cal r2 r2 pop r2 sto r0 r3 hlt max loa r2 r1 4 bge r3 r2 endif adc r3 r2 0 endif jmp r2 r2 loc: cal r3 10 sp (r1) 2 Stack
28
loc: cal 2 r2 loc: cal r3 10 sp (r1) Stack
loa r3 r0 loa r2 r0 psh r2 lcw r2 max cal r2 r2 pop r2 sto r0 r3 hlt max loa r2 r1 4 bge r3 r2 endif adc r3 r2 0 endif jmp r2 r2 loc: cal r3 10 sp (r1) loc: cal 2 Stack
29
loc: cal 2 r2 loc: cal r3 10 sp (r1) Stack
loa r3 r0 loa r2 r0 psh r2 lcw r2 max cal r2 r2 pop r2 sto r0 r3 hlt max loa r2 r1 4 bge r3 r2 endif adc r3 r2 0 endif jmp r2 r2 loc: cal r3 10 sp (r1) loc: cal 2 Stack
30
loc: cal 2 r2 loc: cal r3 10 sp (r1) larger values Stack
loa r3 r0 loa r2 r0 psh r2 lcw r2 max cal r2 r2 pop r2 sto r0 r3 hlt max loa r2 r1 4 bge r3 r2 endif adc r3 r2 0 endif jmp r2 r2 loc: cal r3 10 sp (r1) loc: cal +2 larger values 2 +4 Stack
31
loc: cal 2 r2 2 r3 10 sp (r1) larger values Stack
loa r3 r0 loa r2 r0 psh r2 lcw r2 max cal r2 r2 pop r2 sto r0 r3 hlt max loa r2 r1 4 bge r3 r2 endif adc r3 r2 0 endif jmp r2 r2 2 r3 10 sp (r1) loc: cal +2 larger values 2 +4 Stack
32
loa r3 r0 loa r2 r0 psh r2 lcw r2 max cal r2 r2 pop r2 sto r0 r3 hlt max loa r2 r1 4 bge r3 r2 endif adc r3 r2 0 endif jmp r2 r2 2 r3 10 sp (r1) loc: cal 2 Stack
33
loa r3 r0 loa r2 r0 psh r2 lcw r2 max cal r2 r2 pop r2 sto r0 r3 hlt max loa r2 r1 4 bge r3 r2 endif adc r3 r2 0 endif jmp r2 r2 2 r3 10 sp (r1) loc: cal 2 Stack
34
loa r3 r0 loa r2 r0 psh r2 lcw r2 max cal r2 r2 pop r2 sto r0 r3 hlt max loa r2 r1 4 bge r3 r2 endif adc r3 r2 0 endif jmp r2 r2 loc: cal r3 10 sp (r1) 2 Stack
35
loa r3 r0 loa r2 r0 psh r2 lcw r2 max cal r2 r2 pop r2 sto r0 r3 hlt max loa r2 r1 4 bge r3 r2 endif adc r3 r2 0 endif jmp r2 r2 loc: cal r3 10 sp (r1) 2 Stack
36
loa r3 r0 loa r2 r0 psh r2 lcw r2 max cal r2 r2 pop r2 sto r0 r3 hlt max loa r2 r1 4 bge r3 r2 endif adc r3 r2 0 endif jmp r2 r2 loc: cal r3 10 sp (r1) 2 Stack
37
loa r3 r0 loa r2 r0 psh r2 lcw r2 max cal r2 r2 pop r2 sto r0 r3 hlt max loa r2 r1 4 bge r3 r2 endif adc r3 r2 0 endif jmp r2 r2 2 r3 10 sp (r1) Stack
38
loa r3 r0 loa r2 r0 psh r2 lcw r2 max cal r2 r2 pop r2 sto r0 r3 hlt max loa r2 r1 4 bge r3 r2 endif adc r3 r2 0 endif jmp r2 r2 2 r3 10 sp (r1) Stack
39
loa r3 r0 loa r2 r0 psh r2 lcw r2 max cal r2 r2 pop r2 sto r0 r3 hlt max loa r2 r1 4 bge r3 r2 endif adc r3 r2 0 endif jmp r2 r2 2 r3 10 10! sp (r1) Stack
40
loa r3 r0 loa r2 r0 psh r2 lcw r2 max cal r2 r2 pop r2 sto r0 r3 hlt max loa r2 r1 4 bge r3 r2 endif adc r3 r2 0 endif jmp r2 r2 2 r3 10 sp (r1) Stack
41
Real structure of CS41B program
; great comments at the top! ; lcw r1 stack instruction1 ; comment instruction2 ; comment ... hlt ; stack area: 50 words dat 100 stack end Save address of highest end (highest address) of the stack in r1 Reserve 50 words for the stack
42
Recursion What does this function do?
int mystery(int a, int b){ if( b <= 0 ){ return 0 else return a + mystery(a, b-1) } What does this function do?
43
Recursion Multiplication… a*b (assuming b is positive)
int mystery(int a, int b){ if( b <= 0 ){ return 0 else return a + mystery(a, b-1) } Multiplication… a*b (assuming b is positive) Note to future Dave from past Dave: write the function up on the board
44
Function cleanup and return
mult psh r2 ; save the return address psh r3 ; save first argument, a, on stack loa r2 r1 6 ; get at the 2nd argument, b ; b = r2, a = r3 blt r0 r2 else ; 0 < r2, i.e. recursive case adc r3 r0 0 ; return 0 brs endif else sbc r2 r2 1 ; r2 = b-1 psh r2 ; add r2 as 2nd argument lcw r2 mult ; call mult recursively cal r2 r2 pop r2 ; pop 2nd argument off stack loa r2 r1 2 ; load a into r2 off of the stack add r3 r3 r2 ; r3 = a + mult(a, b-1) endif pop r0 ; remove first argument from stack pop r2 ; get the return address jmp r2 ; return Function startup Base case Recursive case Recursive call answer calculation Function cleanup and return
45
Notice symmetry of psh and pop
mult psh r2 ; save the return address psh r3 ; save first argument, a, on stack loa r2 r1 6 ; get at the 2nd argument, b ; b = r2, a = r3 blt r0 r2 else ; 0 < r2, i.e. recursive case adc r3 r0 0 ; return 0 brs endif else sbc r2 r2 1 ; r2 = b-1 psh r2 ; add r2 as 2nd argument, r3 shouldn't have changed lcw r2 mult ; call mult recursively cal r2 r2 pop r2 ; pop 2nd argument off stack loa r2 r1 2 ; load a into r2 off of the stack add r3 r3 r2 ; r3 = a + mult(a, b-1) endif pop r0 ; remove first argument from stack pop r2 ; get the return address jmp r2 ; return Notice symmetry of psh and pop
46
Calling mult r2 r3 sp (r1) Stack loa r3 r0 loa r2 r0 psh r2
lcw r2 mult cal r2 r2 pop r2 sto r0 r3 hlt sp (r1) Stack
47
Calling mult r2 r3 sp (r1) Stack loa r3 r0 loa r2 r0 psh r2
lcw r2 mult cal r2 r2 pop r2 sto r0 r3 hlt sp (r1) Stack
48
Calling mult r2 r3 6 sp (r1) Stack loa r3 r0 loa r2 r0 psh r2
lcw r2 mult cal r2 r2 pop r2 sto r0 r3 hlt sp (r1) Stack
49
Calling mult r2 r3 6 sp (r1) Stack loa r3 r0 loa r2 r0 psh r2
lcw r2 mult cal r2 r2 pop r2 sto r0 r3 hlt sp (r1) Stack
50
Calling mult r2 2 r3 6 sp (r1) Stack loa r3 r0 loa r2 r0 psh r2
lcw r2 mult cal r2 r2 pop r2 sto r0 r3 hlt sp (r1) Stack
51
Calling mult r2 2 r3 6 sp (r1) Stack loa r3 r0 loa r2 r0 psh r2
lcw r2 mult cal r2 r2 pop r2 sto r0 r3 hlt sp (r1) Stack
52
Calling mult r2 2 r3 6 sp (r1) 2 Stack loa r3 r0 loa r2 r0 psh r2
lcw r2 mult cal r2 r2 pop r2 sto r0 r3 hlt sp (r1) 2 Stack
53
Calling mult r2 2 r3 6 sp (r1) 2 Stack loa r3 r0 loa r2 r0 psh r2
lcw r2 mult cal r2 r2 pop r2 sto r0 r3 hlt sp (r1) 2 Stack
54
Calling mult r2 loc: mult r3 6 sp (r1) 2 Stack loa r3 r0 loa r2 r0
psh r2 lcw r2 mult cal r2 r2 pop r2 sto r0 r3 hlt sp (r1) 2 Stack
55
Calling mult r2 loc: mult r3 6 sp (r1) 2 Stack loa r3 r0 loa r2 r0
psh r2 lcw r2 mult cal r2 r2 pop r2 sto r0 r3 hlt sp (r1) 2 Stack
56
r2 loc: cal0 r3 6 sp (r1) 2 Stack mult psh r2 psh r3 loa r2 r1 6
blt r0 r2 else adc r3 r0 0 brs endif else sbc r2 r2 1 lcw r2 mult cal r2 r2 pop r2 loa r2 r1 2 add r3 r3 r2 endif pop r0 jmp r2 r2 loc: cal0 r3 6 sp (r1) 2 Stack
57
r2 loc: cal0 r3 6 sp (r1) 2 Stack mult psh r2 psh r3 loa r2 r1 6
blt r0 r2 else adc r3 r0 0 brs endif else sbc r2 r2 1 lcw r2 mult cal r2 r2 pop r2 loa r2 r1 2 add r3 r3 r2 endif pop r0 jmp r2 r2 loc: cal0 r3 6 sp (r1) 2 Stack
58
r2 loc: cal0 r3 6 sp (r1) loc: cal0 2 Stack mult psh r2 psh r3
loa r2 r1 6 blt r0 r2 else adc r3 r0 0 brs endif else sbc r2 r2 1 lcw r2 mult cal r2 r2 pop r2 loa r2 r1 2 add r3 r3 r2 endif pop r0 jmp r2 r2 loc: cal0 r3 6 sp (r1) loc: cal0 2 Stack
59
r2 loc: cal0 r3 6 sp (r1) loc: cal0 2 Stack mult psh r2 psh r3
loa r2 r1 6 blt r0 r2 else adc r3 r0 0 brs endif else sbc r2 r2 1 lcw r2 mult cal r2 r2 pop r2 loa r2 r1 2 add r3 r3 r2 endif pop r0 jmp r2 r2 loc: cal0 r3 6 sp (r1) loc: cal0 2 Stack
60
r2 loc: cal0 r3 6 Why push r3? sp (r1) 6 loc: cal0 2 Stack mult psh r2
loa r2 r1 6 blt r0 r2 else adc r3 r0 0 brs endif else sbc r2 r2 1 lcw r2 mult cal r2 r2 pop r2 loa r2 r1 2 add r3 r3 r2 endif pop r0 jmp r2 r2 loc: cal0 r3 6 Why push r3? sp (r1) 6 loc: cal0 2 Stack
61
mult psh r2 psh r3 loa r2 r1 6 blt r0 r2 else adc r3 r0 0 brs endif else sbc r2 r2 1 lcw r2 mult cal r2 r2 pop r2 loa r2 r1 2 add r3 r3 r2 endif pop r0 jmp r2 r2 loc: cal0 r3 6 Not always required, but allows us to use r3 for computation without worrying about losing first parameter sp (r1) 6 loc: cal0 2 Stack
62
r2 loc: cal0 r3 6 sp (r1) 6 loc: cal0 2 Stack mult psh r2 psh r3
loa r2 r1 6 blt r0 r2 else adc r3 r0 0 brs endif else sbc r2 r2 1 lcw r2 mult cal r2 r2 pop r2 loa r2 r1 2 add r3 r3 r2 endif pop r0 jmp r2 r2 loc: cal0 r3 6 sp (r1) 6 loc: cal0 2 Stack
63
r2 loc: cal0 r3 6 sp (r1) 6 loc: cal0 larger values 2 Stack +2 +4 +6
mult psh r2 psh r3 loa r2 r1 6 blt r0 r2 else adc r3 r0 0 brs endif else sbc r2 r2 1 lcw r2 mult cal r2 r2 pop r2 loa r2 r1 2 add r3 r3 r2 endif pop r0 jmp r2 r2 loc: cal0 r3 6 sp (r1) 6 +2 loc: cal0 +4 larger values 2 +6 Stack
64
r2 2 r3 6 sp (r1) 6 loc: cal0 larger values 2 Stack +2 +4 +6 mult
psh r2 psh r3 loa r2 r1 6 blt r0 r2 else adc r3 r0 0 brs endif else sbc r2 r2 1 lcw r2 mult cal r2 r2 pop r2 loa r2 r1 2 add r3 r3 r2 endif pop r0 jmp r2 r2 2 r3 6 sp (r1) 6 +2 loc: cal0 +4 larger values 2 +6 Stack
65
r2 2 r3 6 sp (r1) 6 loc: cal0 2 Stack mult psh r2 psh r3 loa r2 r1 6
blt r0 r2 else adc r3 r0 0 brs endif else sbc r2 r2 1 lcw r2 mult cal r2 r2 pop r2 loa r2 r1 2 add r3 r3 r2 endif jmp r2 r2 2 r3 6 sp (r1) 6 loc: cal0 2 Stack
66
r2 2 r3 6 sp (r1) 6 loc: cal0 2 Stack mult psh r2 psh r3 loa r2 r1 6
blt r0 r2 else adc r3 r0 0 brs endif else sbc r2 r2 1 lcw r2 mult cal r2 r2 pop r2 loa r2 r1 2 add r3 r3 r2 endif pop r0 jmp r2 r2 2 r3 6 sp (r1) 6 loc: cal0 2 Stack
67
r2 1 r3 6 sp (r1) 6 loc: cal0 2 Stack mult psh r2 psh r3 loa r2 r1 6
blt r0 r2 else adc r3 r0 0 brs endif else sbc r2 r2 1 lcw r2 mult cal r2 r2 pop r2 loa r2 r1 2 add r3 r3 r2 endif pop r0 jmp r2 r2 1 r3 6 sp (r1) 6 loc: cal0 2 Stack
68
r2 1 r3 6 sp (r1) 6 loc: cal0 2 Stack mult psh r2 psh r3 loa r2 r1 6
blt r0 r2 else adc r3 r0 0 brs endif else sbc r2 r2 1 lcw r2 mult cal r2 r2 pop r2 loa r2 r1 2 add r3 r3 r2 endif pop r0 jmp r2 r2 1 r3 6 sp (r1) 6 loc: cal0 2 Stack
69
r2 1 r3 6 sp (r1) 1 6 loc: cal0 2 Stack mult psh r2 psh r3 loa r2 r1 6
blt r0 r2 else adc r3 r0 0 brs endif else sbc r2 r2 1 lcw r2 mult cal r2 r2 pop r2 loa r2 r1 2 add r3 r3 r2 endif pop r0 jmp r2 r2 1 r3 6 sp (r1) 1 6 loc: cal0 2 Stack
70
r2 1 r3 6 sp (r1) 1 6 loc: cal0 2 Stack mult psh r2 psh r3 loa r2 r1 6
blt r0 r2 else adc r3 r0 0 brs endif else sbc r2 r2 1 lcw r2 mult cal r2 r2 pop r2 loa r2 r1 2 add r3 r3 r2 endif pop r0 jmp r2 r2 1 r3 6 sp (r1) 1 6 loc: cal0 2 Stack
71
r2 loc: mult r3 6 sp (r1) 1 6 loc: cal0 2 Stack mult psh r2 psh r3
loa r2 r1 6 blt r0 r2 else adc r3 r0 0 brs endif else sbc r2 r2 1 lcw r2 mult cal r2 r2 pop r2 loa r2 r1 2 add r3 r3 r2 endif pop r0 jmp r2 r2 loc: mult r3 6 sp (r1) 1 6 loc: cal0 2 Stack
72
r2 loc: mult r3 6 sp (r1) 1 6 loc: cal0 2 Stack mult psh r2 psh r3
loa r2 r1 6 blt r0 r2 else adc r3 r0 0 brs endif else sbc r2 r2 1 lcw r2 mult cal r2 r2 pop r2 loa r2 r1 2 add r3 r3 r2 endif pop r0 jmp r2 r2 loc: mult r3 6 sp (r1) 1 6 loc: cal0 2 Stack
73
r2 loc: cal1 r3 6 sp (r1) 1 6 loc: cal0 2 Stack mult psh r2 psh r3
loa r2 r1 6 blt r0 r2 else adc r3 r0 0 brs endif else sbc r2 r2 1 lcw r2 mult cal r2 r2 pop r2 loa r2 r1 2 add r3 r3 r2 endif pop r0 jmp r2 r2 loc: cal1 r3 6 sp (r1) 1 6 loc: cal0 2 Stack
74
r2 loc: cal1 r3 6 sp (r1) 1 6 loc: cal0 2 Stack mult psh r2 psh r3
loa r2 r1 6 blt r0 r2 else adc r3 r0 0 brs endif else sbc r2 r2 1 lcw r2 mult cal r2 r2 pop r2 loa r2 r1 2 add r3 r3 r2 endif pop r0 jmp r2 r2 loc: cal1 r3 6 sp (r1) 1 6 loc: cal0 2 Stack
75
r2 loc: cal1 r3 6 sp (r1) loc: cal1 1 6 loc: cal0 2 Stack mult psh r2
loa r2 r1 6 blt r0 r2 else adc r3 r0 0 brs endif else sbc r2 r2 1 lcw r2 mult cal r2 r2 pop r2 loa r2 r1 2 add r3 r3 r2 endif pop r0 jmp r2 r2 loc: cal1 r3 6 sp (r1) loc: cal1 1 6 loc: cal0 2 Stack
76
r2 loc: cal1 r3 6 sp (r1) loc: cal1 1 6 loc: cal0 2 Stack mult psh r2
loa r2 r1 6 blt r0 r2 else adc r3 r0 0 brs endif else sbc r2 r2 1 lcw r2 mult cal r2 r2 pop r2 loa r2 r1 2 add r3 r3 r2 endif pop r0 jmp r2 r2 loc: cal1 r3 6 sp (r1) loc: cal1 1 6 loc: cal0 2 Stack
77
r2 loc: cal1 r3 6 sp (r1) 6 loc: cal1 1 6 loc: cal0 2 Stack mult
psh r2 psh r3 loa r2 r1 6 blt r0 r2 else adc r3 r0 0 brs endif else sbc r2 r2 1 lcw r2 mult cal r2 r2 pop r2 loa r2 r1 2 add r3 r3 r2 endif pop r0 jmp r2 r2 loc: cal1 r3 6 sp (r1) 6 loc: cal1 1 6 loc: cal0 2 Stack
78
r2 loc: cal1 r3 6 sp (r1) 6 loc: cal1 1 6 loc: cal0 2 Stack mult
psh r2 psh r3 loa r2 r1 6 blt r0 r2 else adc r3 r0 0 brs endif else sbc r2 r2 1 lcw r2 mult cal r2 r2 pop r2 loa r2 r1 2 add r3 r3 r2 endif pop r0 jmp r2 r2 loc: cal1 r3 6 sp (r1) 6 loc: cal1 1 6 loc: cal0 2 Stack
79
r2 1 r3 6 sp (r1) 6 loc: cal1 1 6 loc: cal0 2 Stack mult psh r2 psh r3
loa r2 r1 6 blt r0 r2 else adc r3 r0 0 brs endif else sbc r2 r2 1 lcw r2 mult cal r2 r2 pop r2 loa r2 r1 2 add r3 r3 r2 endif pop r0 jmp r2 r2 1 r3 6 sp (r1) 6 loc: cal1 1 6 loc: cal0 2 Stack
80
r2 1 r3 6 sp (r1) 6 loc: cal1 1 6 loc: cal0 2 Stack mult psh r2 psh r3
loa r2 r1 6 blt r0 r2 else adc r3 r0 0 brs endif else sbc r2 r2 1 lcw r2 mult cal r2 r2 pop r2 loa r2 r1 2 add r3 r3 r2 endif pop r0 jmp r2 r2 1 r3 6 sp (r1) 6 loc: cal1 1 6 loc: cal0 2 Stack
81
r2 1 r3 6 sp (r1) 6 loc: cal1 1 6 loc: cal0 2 Stack mult psh r2 psh r3
loa r2 r1 6 blt r0 r2 else adc r3 r0 0 brs endif else sbc r2 r2 1 lcw r2 mult cal r2 r2 pop r2 loa r2 r1 2 add r3 r3 r2 endif pop r0 jmp r2 r2 1 r3 6 sp (r1) 6 loc: cal1 1 6 loc: cal0 2 Stack
82
r2 r3 6 sp (r1) 6 loc: cal1 1 6 loc: cal0 2 Stack mult psh r2 psh r3
loa r2 r1 6 blt r0 r2 else adc r3 r0 0 brs endif else sbc r2 r2 1 lcw r2 mult cal r2 r2 pop r2 loa r2 r1 2 add r3 r3 r2 endif pop r0 jmp r2 r2 r3 6 sp (r1) 6 loc: cal1 1 6 loc: cal0 2 Stack
83
r2 r3 6 sp (r1) 6 loc: cal1 1 6 loc: cal0 2 Stack mult psh r2 psh r3
loa r2 r1 6 blt r0 r2 else adc r3 r0 0 brs endif else sbc r2 r2 1 lcw r2 mult cal r2 r2 pop r2 loa r2 r1 2 add r3 r3 r2 endif pop r0 jmp r2 r2 r3 6 sp (r1) 6 loc: cal1 1 6 loc: cal0 2 Stack
84
r2 r3 6 sp (r1) 6 loc: cal1 1 6 loc: cal0 2 Stack mult psh r2 psh r3
loa r2 r1 6 blt r0 r2 else adc r3 r0 0 brs endif else sbc r2 r2 1 lcw r2 mult cal r2 r2 pop r2 loa r2 r1 2 add r3 r3 r2 endif pop r0 jmp r2 r2 r3 6 sp (r1) 6 loc: cal1 1 6 loc: cal0 2 Stack
85
r2 r3 6 sp (r1) 6 loc: cal1 1 6 loc: cal0 2 Stack mult psh r2 psh r3
loa r2 r1 6 blt r0 r2 else adc r3 r0 0 brs endif else sbc r2 r2 1 lcw r2 mult cal r2 r2 pop r2 loa r2 r1 2 add r3 r3 r2 endif pop r0 jmp r2 r2 r3 6 sp (r1) 6 loc: cal1 1 6 loc: cal0 2 Stack
86
r2 loc: mult r3 6 sp (r1) 6 loc: cal1 1 6 loc: cal0 2 Stack mult
psh r2 psh r3 loa r2 r1 6 blt r0 r2 else adc r3 r0 0 brs endif else sbc r2 r2 1 lcw r2 mult cal r2 r2 pop r2 loa r2 r1 2 add r3 r3 r2 endif pop r0 jmp r2 r2 loc: mult r3 6 sp (r1) 6 loc: cal1 1 6 loc: cal0 2 Stack
87
r2 loc: mult r3 6 sp (r1) 6 loc: cal1 1 6 loc: cal0 2 Stack mult
psh r2 psh r3 loa r2 r1 6 blt r0 r2 else adc r3 r0 0 brs endif else sbc r2 r2 1 lcw r2 mult cal r2 r2 pop r2 loa r2 r1 2 add r3 r3 r2 endif pop r0 jmp r2 r2 loc: mult r3 6 sp (r1) 6 loc: cal1 1 6 loc: cal0 2 Stack
88
r2 loc: cal1 r3 6 sp (r1) 6 loc: cal1 1 6 loc: cal0 2 Stack mult
psh r2 psh r3 loa r2 r1 6 blt r0 r2 else adc r3 r0 0 brs endif else sbc r2 r2 1 lcw r2 mult cal r2 r2 pop r2 loa r2 r1 2 add r3 r3 r2 endif pop r0 jmp r2 r2 loc: cal1 r3 6 sp (r1) 6 loc: cal1 1 6 loc: cal0 2 Stack
89
r2 loc: cal1 r3 6 sp (r1) 6 loc: cal1 1 6 loc: cal0 2 Stack mult
psh r2 psh r3 loa r2 r1 6 blt r0 r2 else adc r3 r0 0 brs endif else sbc r2 r2 1 lcw r2 mult cal r2 r2 pop r2 loa r2 r1 2 add r3 r3 r2 endif pop r0 jmp r2 r2 loc: cal1 r3 6 sp (r1) 6 loc: cal1 1 6 loc: cal0 2 Stack
90
r2 loc: cal1 r3 6 sp (r1) loc: cal1 6 loc: cal1 1 6 loc: cal0 2 Stack
mult psh r2 psh r3 loa r2 r1 6 blt r0 r2 else adc r3 r0 0 brs endif else sbc r2 r2 1 lcw r2 mult cal r2 r2 pop r2 loa r2 r1 2 add r3 r3 r2 endif pop r0 jmp r2 r2 loc: cal1 r3 6 sp (r1) loc: cal1 6 loc: cal1 1 6 loc: cal0 2 Stack
91
r2 loc: cal1 r3 6 sp (r1) loc: cal1 6 loc: cal1 1 6 loc: cal0 2 Stack
mult psh r2 psh r3 loa r2 r1 6 blt r0 r2 else adc r3 r0 0 brs endif else sbc r2 r2 1 lcw r2 mult cal r2 r2 pop r2 loa r2 r1 2 add r3 r3 r2 endif pop r0 jmp r2 r2 loc: cal1 r3 6 sp (r1) loc: cal1 6 loc: cal1 1 6 loc: cal0 2 Stack
92
r2 loc: cal1 r3 6 sp (r1) 6 loc: cal1 6 loc: cal1 1 6 loc: cal0 2
mult psh r2 psh r3 loa r2 r1 6 blt r0 r2 else adc r3 r0 0 brs endif else sbc r2 r2 1 lcw r2 mult cal r2 r2 pop r2 loa r2 r1 2 add r3 r3 r2 endif pop r0 jmp r2 r2 loc: cal1 r3 6 sp (r1) 6 loc: cal1 6 loc: cal1 1 6 loc: cal0 2 Stack
93
r2 loc: cal1 r3 6 sp (r1) 6 loc: cal1 6 loc: cal1 1 6 loc: cal0 2
mult psh r2 psh r3 loa r2 r1 6 blt r0 r2 else adc r3 r0 0 brs endif else sbc r2 r2 1 lcw r2 mult cal r2 r2 pop r2 loa r2 r1 2 add r3 r3 r2 endif pop r0 jmp r2 r2 loc: cal1 r3 6 sp (r1) 6 loc: cal1 6 loc: cal1 1 6 loc: cal0 2 Stack
94
r2 r3 6 sp (r1) 6 loc: cal1 6 loc: cal1 1 6 loc: cal0 2 Stack mult
psh r2 psh r3 loa r2 r1 6 blt r0 r2 else adc r3 r0 0 brs endif else sbc r2 r2 1 lcw r2 mult cal r2 r2 pop r2 loa r2 r1 2 add r3 r3 r2 endif pop r0 jmp r2 r2 r3 6 sp (r1) 6 loc: cal1 6 loc: cal1 1 6 loc: cal0 2 Stack
95
r2 r3 6 sp (r1) 6 loc: cal1 6 loc: cal1 1 6 loc: cal0 2 Stack mult
psh r2 psh r3 loa r2 r1 6 blt r0 r2 else adc r3 r0 0 brs endif else sbc r2 r2 1 lcw r2 mult cal r2 r2 pop r2 loa r2 r1 2 add r3 r3 r2 endif pop r0 jmp r2 r2 r3 6 sp (r1) 6 loc: cal1 6 loc: cal1 1 6 loc: cal0 2 Stack
96
r2 r3 6 sp (r1) 6 loc: cal1 6 loc: cal1 1 6 loc: cal0 2 Stack mult
psh r2 psh r3 loa r2 r1 6 blt r0 r2 else adc r3 r0 0 brs endif else sbc r2 r2 1 lcw r2 mult cal r2 r2 pop r2 loa r2 r1 2 add r3 r3 r2 endif pop r0 jmp r2 r2 r3 6 sp (r1) 6 loc: cal1 6 loc: cal1 1 6 loc: cal0 2 Stack
97
r2 r3 sp (r1) 6 loc: cal1 6 loc: cal1 1 6 loc: cal0 2 Stack mult
psh r2 psh r3 loa r2 r1 6 blt r0 r2 else adc r3 r0 0 brs endif else sbc r2 r2 1 lcw r2 mult cal r2 r2 pop r2 loa r2 r1 2 add r3 r3 r2 endif pop r0 jmp r2 r2 r3 sp (r1) 6 loc: cal1 6 loc: cal1 1 6 loc: cal0 2 Stack
98
r2 r3 sp (r1) 6 loc: cal1 6 loc: cal1 1 6 loc: cal0 2 Stack mult
psh r2 psh r3 loa r2 r1 6 blt r0 r2 else adc r3 r0 0 brs endif else sbc r2 r2 1 lcw r2 mult cal r2 r2 pop r2 loa r2 r1 2 add r3 r3 r2 endif pop r0 jmp r2 r2 r3 sp (r1) 6 loc: cal1 6 loc: cal1 1 6 loc: cal0 2 Stack
99
r2 r3 Stack frames! sp (r1) 6 loc: cal1 6 loc: cal1 1 6 loc: cal0 2
mult psh r2 psh r3 loa r2 r1 6 blt r0 r2 else adc r3 r0 0 brs endif else sbc r2 r2 1 lcw r2 mult cal r2 r2 pop r2 loa r2 r1 2 add r3 r3 r2 endif pop r0 jmp r2 r2 r3 Stack frames! sp (r1) 6 loc: cal1 mult(6,0) 6 loc: cal1 mult(6,1) 1 6 loc: cal0 mult(6,2) 2 Stack
100
r2 r3 sp (r1) 6 loc: cal1 6 loc: cal1 1 6 loc: cal0 2 Stack mult
psh r2 psh r3 loa r2 r1 6 blt r0 r2 else adc r3 r0 0 brs endif else sbc r2 r2 1 lcw r2 mult cal r2 r2 pop r2 loa r2 r1 2 add r3 r3 r2 endif pop r0 jmp r2 r2 r3 sp (r1) 6 loc: cal1 6 loc: cal1 1 6 loc: cal0 2 Stack
101
r2 r3 sp (r1) loc: cal1 6 loc: cal1 1 6 loc: cal0 2 Stack
mult psh r2 psh r3 loa r2 r1 6 blt r0 r2 else adc r3 r0 0 brs endif else sbc r2 r2 1 lcw r2 mult cal r2 r2 pop r2 loa r2 r1 2 add r3 r3 r2 endif pop r0 jmp r2 r2 r3 We don’t actually care about this value, but need to get it off the stack to cleanup… just put it in r0, which throws it away sp (r1) loc: cal1 6 loc: cal1 1 6 loc: cal0 2 Stack
102
r2 r3 sp (r1) loc: cal1 6 loc: cal1 1 6 loc: cal0 2 Stack mult psh r2
loa r2 r1 6 blt r0 r2 else adc r3 r0 0 brs endif else sbc r2 r2 1 lcw r2 mult cal r2 r2 pop r2 loa r2 r1 2 add r3 r3 r2 endif pop r0 jmp r2 r2 r3 sp (r1) loc: cal1 6 loc: cal1 1 6 loc: cal0 2 Stack
103
r2 loc: cal1 r3 sp (r1) 6 loc: cal1 1 6 loc: cal0 2 Stack mult psh r2
loa r2 r1 6 blt r0 r2 else adc r3 r0 0 brs endif else sbc r2 r2 1 lcw r2 mult cal r2 r2 pop r2 loa r2 r1 2 add r3 r3 r2 endif pop r0 jmp r2 r2 loc: cal1 r3 sp (r1) 6 loc: cal1 1 6 loc: cal0 2 Stack
104
r2 loc: cal1 r3 sp (r1) 6 loc: cal1 1 6 loc: cal0 2 Stack mult psh r2
loa r2 r1 6 blt r0 r2 else adc r3 r0 0 brs endif else sbc r2 r2 1 lcw r2 mult cal r2 r2 pop r2 loa r2 r1 2 add r3 r3 r2 endif pop r0 jmp r2 r2 loc: cal1 r3 sp (r1) 6 loc: cal1 1 6 loc: cal0 2 Stack
105
Returning with answer in r3
mult psh r2 psh r3 loa r2 r1 6 blt r0 r2 else adc r3 r0 0 brs endif else sbc r2 r2 1 lcw r2 mult cal r2 r2 pop r2 loa r2 r1 2 add r3 r3 r2 endif pop r0 jmp r2 r2 loc: cal1 r3 sp (r1) 6 loc: cal1 1 6 loc: cal0 2 Stack Returning with answer in r3
106
r2 loc: cal1 r3 sp (r1) 6 loc: cal1 1 6 loc: cal0 2 Stack mult psh r2
loa r2 r1 6 blt r0 r2 else adc r3 r0 0 brs endif else sbc r2 r2 1 lcw r2 mult cal r2 r2 pop r2 loa r2 r1 2 add r3 r3 r2 endif pop r0 jmp r2 r2 loc: cal1 r3 sp (r1) 6 loc: cal1 1 6 loc: cal0 2 Stack
107
r2 r3 sp (r1) 6 loc: cal1 1 6 loc: cal0 2 Stack mult psh r2 psh r3
loa r2 r1 6 blt r0 r2 else adc r3 r0 0 brs endif else sbc r2 r2 1 lcw r2 mult cal r2 r2 pop r2 loa r2 r1 2 add r3 r3 r2 endif pop r0 jmp r2 r2 r3 sp (r1) 6 loc: cal1 1 6 loc: cal0 2 Stack
108
r2 r3 sp (r1) 6 loc: cal1 1 6 loc: cal0 2 Stack mult psh r2 psh r3
loa r2 r1 6 blt r0 r2 else adc r3 r0 0 brs endif else sbc r2 r2 1 lcw r2 mult cal r2 r2 pop r2 loa r2 r1 2 add r3 r3 r2 endif pop r0 jmp r2 r2 r3 sp (r1) 6 loc: cal1 1 6 loc: cal0 2 Stack
109
r2 6 r3 sp (r1) 6 loc: cal1 1 6 loc: cal0 2 Stack mult psh r2 psh r3
loa r2 r1 6 blt r0 r2 else adc r3 r0 0 brs endif else sbc r2 r2 1 lcw r2 mult cal r2 r2 pop r2 loa r2 r1 2 add r3 r3 r2 endif pop r0 jmp r2 r2 6 r3 sp (r1) 6 loc: cal1 1 6 loc: cal0 2 Stack
110
r2 6 r3 sp (r1) 6 loc: cal1 1 6 loc: cal0 2 Stack mult psh r2 psh r3
loa r2 r1 6 blt r0 r2 else adc r3 r0 0 brs endif else sbc r2 r2 1 lcw r2 mult cal r2 r2 pop r2 loa r2 r1 2 add r3 r3 r2 endif pop r0 jmp r2 r2 6 r3 sp (r1) 6 loc: cal1 1 6 loc: cal0 2 Stack
111
r2 6 r3 sp (r1) 6 loc: cal1 1 6 loc: cal0 2 Stack mult psh r2 psh r3
loa r2 r1 6 blt r0 r2 else adc r3 r0 0 brs endif else sbc r2 r2 1 lcw r2 mult cal r2 r2 pop r2 loa r2 r1 2 add r3 r3 r2 endif pop r0 jmp r2 r2 6 r3 sp (r1) 6 loc: cal1 1 6 loc: cal0 2 Stack
112
r2 6 r3 sp (r1) 6 loc: cal1 1 6 loc: cal0 2 Stack mult psh r2 psh r3
loa r2 r1 6 blt r0 r2 else adc r3 r0 0 brs endif else sbc r2 r2 1 lcw r2 mult cal r2 r2 pop r2 loa r2 r1 2 add r3 r3 r2 endif pop r0 jmp r2 r2 6 r3 sp (r1) 6 loc: cal1 1 6 loc: cal0 2 Stack
113
r2 6 r3 sp (r1) loc: cal1 1 6 loc: cal0 2 Stack mult psh r2 psh r3
loa r2 r1 6 blt r0 r2 else adc r3 r0 0 brs endif else sbc r2 r2 1 lcw r2 mult cal r2 r2 pop r2 loa r2 r1 2 add r3 r3 r2 endif pop r0 jmp r2 r2 6 r3 sp (r1) loc: cal1 1 6 loc: cal0 2 Stack
114
r2 6 r3 sp (r1) loc: cal1 1 6 loc: cal0 2 Stack mult psh r2 psh r3
loa r2 r1 6 blt r0 r2 else adc r3 r0 0 brs endif else sbc r2 r2 1 lcw r2 mult cal r2 r2 pop r2 loa r2 r1 2 add r3 r3 r2 endif pop r0 jmp r2 r2 6 r3 sp (r1) loc: cal1 1 6 loc: cal0 2 Stack
115
r2 loc: cal1 r3 6 sp (r1) 1 6 loc: cal0 2 Stack mult psh r2 psh r3
loa r2 r1 6 blt r0 r2 else adc r3 r0 0 brs endif else sbc r2 r2 1 lcw r2 mult cal r2 r2 pop r2 loa r2 r1 2 add r3 r3 r2 endif pop r0 jmp r2 r2 loc: cal1 r3 6 sp (r1) 1 6 loc: cal0 2 Stack
116
r2 loc: cal1 r3 6 sp (r1) 1 6 loc: cal0 2 Stack mult psh r2 psh r3
loa r2 r1 6 blt r0 r2 else adc r3 r0 0 brs endif else sbc r2 r2 1 lcw r2 mult cal r2 r2 pop r2 loa r2 r1 2 add r3 r3 r2 endif pop r0 jmp r2 r2 loc: cal1 r3 6 sp (r1) 1 6 loc: cal0 2 Stack
117
Returning with answer in r3
mult psh r2 psh r3 loa r2 r1 6 blt r0 r2 else adc r3 r0 0 brs endif else sbc r2 r2 1 lcw r2 mult cal r2 r2 pop r2 loa r2 r1 2 add r3 r3 r2 endif pop r0 jmp r2 r2 loc: cal1 r3 6 sp (r1) 1 6 loc: cal0 2 Stack Returning with answer in r3
118
r2 loc: cal1 r3 6 sp (r1) 1 6 loc: cal0 2 Stack mult psh r2 psh r3
loa r2 r1 6 blt r0 r2 else adc r3 r0 0 brs endif else sbc r2 r2 1 lcw r2 mult cal r2 r2 pop r2 loa r2 r1 2 add r3 r3 r2 endif pop r0 jmp r2 r2 loc: cal1 r3 6 sp (r1) 1 6 loc: cal0 2 Stack
119
r2 1 r3 6 sp (r1) 6 loc: cal0 2 Stack mult psh r2 psh r3 loa r2 r1 6
blt r0 r2 else adc r3 r0 0 brs endif else sbc r2 r2 1 lcw r2 mult cal r2 r2 pop r2 loa r2 r1 2 add r3 r3 r2 endif pop r0 jmp r2 r2 1 r3 6 sp (r1) 6 loc: cal0 2 Stack
120
r2 1 r3 6 sp (r1) 6 loc: cal0 2 Stack mult psh r2 psh r3 loa r2 r1 6
blt r0 r2 else adc r3 r0 0 brs endif else sbc r2 r2 1 lcw r2 mult cal r2 r2 pop r2 loa r2 r1 2 add r3 r3 r2 endif pop r0 jmp r2 r2 1 r3 6 sp (r1) 6 loc: cal0 2 Stack
121
r2 6 r3 sp (r1) 6 loc: cal0 2 Stack mult psh r2 psh r3 loa r2 r1 6
blt r0 r2 else adc r3 r0 0 brs endif else sbc r2 r2 1 lcw r2 mult cal r2 r2 pop r2 loa r2 r1 2 add r3 r3 r2 endif pop r0 jmp r2 r2 6 r3 sp (r1) 6 loc: cal0 2 Stack
122
r2 6 r3 sp (r1) 6 loc: cal0 2 Stack mult psh r2 psh r3 loa r2 r1 6
blt r0 r2 else adc r3 r0 0 brs endif else sbc r2 r2 1 lcw r2 mult cal r2 r2 pop r2 loa r2 r1 2 add r3 r3 r2 endif pop r0 jmp r2 r2 6 r3 sp (r1) 6 loc: cal0 2 Stack
123
r2 6 r3 12 sp (r1) 6 loc: cal0 2 Stack mult psh r2 psh r3 loa r2 r1 6
blt r0 r2 else adc r3 r0 0 brs endif else sbc r2 r2 1 lcw r2 mult cal r2 r2 pop r2 loa r2 r1 2 add r3 r3 r2 endif pop r0 jmp r2 r2 6 r3 12 sp (r1) 6 loc: cal0 2 Stack
124
r2 6 r3 12 sp (r1) 6 loc: cal0 2 Stack mult psh r2 psh r3 loa r2 r1 6
blt r0 r2 else adc r3 r0 0 brs endif else sbc r2 r2 1 lcw r2 mult cal r2 r2 pop r2 loa r2 r1 2 add r3 r3 r2 endif pop r0 jmp r2 r2 6 r3 12 sp (r1) 6 loc: cal0 2 Stack
125
r2 6 r3 12 sp (r1) loc: cal0 2 Stack mult psh r2 psh r3 loa r2 r1 6
blt r0 r2 else adc r3 r0 0 brs endif else sbc r2 r2 1 lcw r2 mult cal r2 r2 pop r2 loa r2 r1 2 add r3 r3 r2 endif pop r0 jmp r2 r2 6 r3 12 sp (r1) loc: cal0 2 Stack
126
r2 6 r3 12 sp (r1) loc: cal0 2 Stack mult psh r2 psh r3 loa r2 r1 6
blt r0 r2 else adc r3 r0 0 brs endif else sbc r2 r2 1 lcw r2 mult cal r2 r2 pop r2 loa r2 r1 2 add r3 r3 r2 endif pop r0 jmp r2 r2 6 r3 12 sp (r1) loc: cal0 2 Stack
127
r2 loc: cal0 r3 12 sp (r1) 2 Stack mult psh r2 psh r3 loa r2 r1 6
blt r0 r2 else adc r3 r0 0 brs endif else sbc r2 r2 1 lcw r2 mult cal r2 r2 pop r2 loa r2 r1 2 add r3 r3 r2 endif pop r0 jmp r2 r2 loc: cal0 r3 12 sp (r1) 2 Stack
128
r2 loc: cal0 r3 12 sp (r1) 2 Stack mult psh r2 psh r3 loa r2 r1 6
blt r0 r2 else adc r3 r0 0 brs endif else sbc r2 r2 1 lcw r2 mult cal r2 r2 pop r2 loa r2 r1 2 add r3 r3 r2 endif pop r0 jmp r2 r2 loc: cal0 r3 12 sp (r1) 2 Stack
129
Returning with answer in r3
mult psh r2 psh r3 loa r2 r1 6 blt r0 r2 else adc r3 r0 0 brs endif else sbc r2 r2 1 lcw r2 mult cal r2 r2 pop r2 loa r2 r1 2 add r3 r3 r2 endif pop r0 jmp r2 r2 loc: cal0 r3 12 sp (r1) 2 Stack Returning with answer in r3
130
Calling mult r2 loc: cal0 r3 12 sp (r1) 2 Stack loa r3 r0 loa r2 r0
psh r2 lcw r2 mult cal r2 r2 pop r2 sto r0 r3 hlt sp (r1) 2 Stack
131
Calling mult r2 2 r3 12 sp (r1) Stack loa r3 r0 loa r2 r0 psh r2
lcw r2 mult cal r2 r2 pop r2 sto r0 r3 hlt sp (r1) Stack
132
Calling mult r2 2 r3 12 sp (r1) Stack loa r3 r0 loa r2 r0 psh r2
lcw r2 mult cal r2 r2 pop r2 sto r0 r3 hlt sp (r1) Stack
133
Calling mult r2 2 r3 12 Print the answer: 12! sp (r1) Stack loa r3 r0
psh r2 lcw r2 mult cal r2 r2 pop r2 sto r0 r3 hlt Print the answer: 12! sp (r1) Stack
134
Calling mult r2 2 r3 12 Print the answer: 12! sp (r1) Stack loa r3 r0
psh r2 lcw r2 mult cal r2 r2 pop r2 sto r0 r3 hlt Print the answer: 12! sp (r1) Stack
135
Run mult.a41 in simulator
136
CS41B programming advice
Match your push and pops Follow the register conventions Develop code incrementally Debugging: write out stack, registers, etc. on paper and compare against system execution
137
Examples from this lecture
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.