CS2200 Presentation 2a - PowerPoint PPT Presentation

1 / 111
About This Presentation
Title:

CS2200 Presentation 2a

Description:

Closet. Renters. Closet. A Tale of Two Closets. T. S. My ... How many closets did we discuss? Press 1 for 1. Press 2 for 2. etc. Compiling simple procedures ... – PowerPoint PPT presentation

Number of Views:39
Avg rating:3.0/5.0
Slides: 112
Provided by: BillL161
Category:

less

Transcript and Presenter's Notes

Title: CS2200 Presentation 2a


1
CS2200Presentation 2a
  • Processors
  • Part Deux
  • Instruction Formats, Calling Conventions,
  • etc.

2
Announcements
  • Project 1 will be available via WebWork later
    today.
  • There is no Homework 1. Project 1 has two
    phases.
  • If you can't log on to WebWork
  • Read the instructions one more time
  • Email me.
  • If you just registered we will be adding you to
    WebWork this weekend.

3
Deadlines
  • Homeworks and Projects will be due on Mondays at
    115959 p.m.
  • There will be no extensions
  • Not because were mean
  • Because we need time to properly grade projects
  • Your cooperation and understanding are appreciated

4
Details
  • Web Page
  • http//www.cc.gatech.edu/classes/AY2005/cs2200_sum
    mer/
  • This lecture is on the web page!
  • Newsgroups
  • git.cc.class.cs2200.announce
  • git.cc.class.cs2200

5
Last time...C
  • Expressions
  • add, sub, nand, etc.
  • Assignment
  • Store
  • Fetching
  • Load
  • If, while, for
  • BEQ, etc

6
Questions?
7
Instruction Format
  • Human Readable
  • add s3, s1, a2

8
LC2200-8 Registers
Name
R
Usage
Preserved on Call
zero
0
The constant value 0
n.a.
at
1
Reserved for assembler
n.a.
v0
2
Return value
no
a0-a2
3-5
Arguments
no
t0-t2
6-8
Temporary general purpose registers
no
s0-s2
9-11
Saved general purpose registers
yes
k0
12
Reserved for OS/traps
n.a.
sp
13
Stack pointer
yes
pr
14
Page Register
yes
ra
15
Return address
yes
9
Instruction Format
  • Human Readable
  • add s0, s1, a2
  • (add contents of s1 and a2, place results in
    s0)
  • Machine Readable

10
Field NamesR-Type Instruction
rY
rX
op
rZ
name
1
4
4
3
4
bits
op opcode rX register destination
operand rY first register source
operand rZ second register source
operand unused
How many registers?
11
Choices
  • Fixed Length Instruction
  • Requires different formats
  • Can reduce complexity by making different formats
    as constant as possible
  • Variable Length Instruction
  • Uses less memory
  • More common before RISC (CISC)

12
Questions?
  • We now continue discussing how HLL's are
    implemented in the instruction set

13
Procedures
  • Procedural abstraction
  • What is the programmers model?

14
Procedures
  • Procedure abstraction
  • What is the programmers model?
  • What does the compiler have to do?
  • Remember functions are not compiled at the same
    time
  • A function would like to have most of registers
    available for use

15
Procedures
  • Procedure abstraction
  • What is the programmers model?
  • What does the compiler have to do?
  • Remember functions are not compiled at the same
    time
  • A function would like to have most of registers
    available for use
  • Simple hardware to support procedures?
  • One idea...
  • Shadow area for processor state?
  • Save/restore on call/return

16
Shadow Concept
Primary Processor State
Shadow Processor State
High Speed
ROW
Problems?
17
What do we need?
  • Nested modules/Recursion
  • Pass values to modules
  • Return value(s) from module
  • Asynchronous compilation
  • Need to do things in a uniform way
  • Continue execution after module finishes

18
Procedure Issues
  • Hardware instructions to support this model?
  • Call/return
  • Remember where we are in the program. Why?
  • Program counter (PC)
  • What should happen on every instruction
    execution?
  • Would we need a PC if there were no procedure
    abstraction?
  • Jump AND store return address
  • Load/store
  • Stack
  • Push and pop
  • Stack pointer (sp)
  • Stack frames
  • What do we store and restore on call/return?

19
  • Software conventions (Why?)
  • Reserve some number of registers for parameters,
    return values, and return address
  • e.g. LC2200
  • 3 for params, 1 for return values, one for return
    address
  • JALR ltproc-addr in reggt, ra ra is
    return-addr
  • JALR ra, zero Where does this go?
  • What if we have more params or return values?
  • Registers used in procedures
  • Temporary registers
  • Caller does not expect value to be preserved upon
    return
  • LC2200 t0 to t2
  • Saved registers
  • Caller does expect value to be preserved on
    return
  • LC2200 s0 to s2

20
LC2200-8 Registers
Recall
Name
R
Usage
Preserved on Call
zero
0
The constant value 0
n.a.
at
1
Reserved for assembler
n.a.
v0
2
Return value
no
a0-a2
3-5
Arguments
no
t0-t2
6-8
Temporary general purpose registers
no
s0-s2
9-11
Saved general purpose registers
yes
k0
12
Reserved for OS/traps
n.a.
sp
13
Stack pointer
yes
pr
14
Page Register
yes
ra
15
Return address
yes
21
A Tale of Two Closets
T
S
My Closet
Renters Closet
22
A Tale of Two Closets
T
S
My Closet
Renters Closet
23
A Tale of Two Closets
T
S
My Closet
Renters Closet
24
Questions
  • How many closets did we discuss?
  • Press 1 for 1
  • Press 2 for 2
  • etc.

25
  • Compiling simple procedures
  • Just need to save/restore registers used by
    called procedure
  • Who should do this? caller? callee?
  • What regs in the LC2200 example?

26
Question
  • Caller has values in s1 and t1
  • Callee will need (to destroy) s1 and t1 to
    perform its operations.
  • Who should save s1?

27
Question
  • Caller has values in s1 and t1
  • Callee will need (to destroy) s1 and t1 to
    perform its operations.
  • Who should save s1?
  • Press 1 for Caller
  • Press 2 for Callee
  • Press 3 for either

28
Question
  • Caller has values in s1 and t1
  • Callee will need (to destroy) s1 and t1 to
    perform its operations.
  • Who should save t1?

29
Question
  • Caller has values in s1 and t1
  • Callee will need (to destroy) s1 and t1 to
    perform its operations.
  • Who should save t1?
  • Press 1 for Caller
  • Press 2 for Callee
  • Press 3 for either

30
Questions?
31
Mips Registers
Name
R
Usage
Preserved on Call
zero
0
The constant value 0
n.a.
at
1
Reserved for assembler
n.a.
v0-v1
2-3
Values for results and expression evaluation
no
a0-a3
4-7
Arguments
no
t0-t7
8-15
Temporaries
no
s0-s7
16-23
Saved
yes
t8-t9
24-25
More temporaries
no
k0-k1
26-27
Reserved for use by operating system
n.a.
gp
28
Global pointer
yes
sp
29
Stack pointer
yes
fp
30
Frame pointer
yes
ra
31
Return address
yes
32
Factorial Again!
  • int fact(int n)
  • if (n lt 1)
  • return 1
  • else
  • return (n fact(n-1))

33
Factorial Again!
  • int fact(int n)
  • if (n lt 1)
  • return 1
  • else
  • return (n fact(n-1))

fact n 0
fact n 1
fact n 2
fact n 3
fact n 4
caller fact(4)
34
Factorial Again!
  • fact sub sp, sp, 8 adjust stack for 2
  • sw ra, 4(sp) save the return addr
  • sw a0, 0(sp) save arg n
  • slt t0, a0, 1 test for n lt 1
  • beq t0, zero, L1 if n gt 1, goto L1
  • add v0, zero, 1 return 1
  • add sp, sp, 8 pop 2 off stack
  • jr ra return to caller
  • L1 sub a0, a0, 1 n gt 1 arg gets n-1
  • jal fact call fact w/ (n-1)
  • lw a0, 0(sp) ret frm jal restr n
  • lw ra, 4(sp) restore ret addr
  • add sp, sp, 8 adj stk ptr (pop 2)
  • mul v0, a0, v0 ret n fact(n-1)
  • jr ra return to caller

35
?
2000 fact sub sp,sp,8 adjust stack for
2 2004 sw ra,4(sp) save the return
addr 2008 sw a0,0(sp) save arg
n 2012 slt t0,a0,1 test for n lt
1 2016 beq t0,zero,L1 if n gt 1, goto
L1 2020 add v0,zero,1 return 1 2024
add sp,sp,8 pop 2 off stack 2028
jr ra return to caller 2032 L1
sub a0,a0,1 n gt 1 arg gets n-1 2036
jal fact call fact w/ (n-1) 2040
lw a0,0(sp) ret frm jal restr n 2044
lw ra,4(sp) restore ret addr 2048
add sp,sp,8 adj stk ptr (pop 2) 2052
mul v0,a0,v0 ret n fact(n-1) 2056
jr ra return to caller
0
0
0
0
0
0
0
0
0
Assume that fact(n) is called with a value of n
4 a return address of 1000 And the stack pointer
is as shown
v0
0
0
a0
4
0
t0
0
sp
...
0
ra
1000
0
36
?
2000 fact sub sp,sp,8 adjust stack for
2 2004 sw ra,4(sp) save the return
addr 2008 sw a0,0(sp) save arg
n 2012 slt t0,a0,1 test for n lt
1 2016 beq t0,zero,L1 if n gt 1, goto
L1 2020 add v0,zero,1 return 1 2024
add sp,sp,8 pop 2 off stack 2028
jr ra return to caller 2032 L1
sub a0,a0,1 n gt 1 arg gets n-1 2036
jal fact call fact w/ (n-1) 2040
lw a0,0(sp) ret frm jal restr n 2044
lw ra,4(sp) restore ret addr 2048
add sp,sp,8 adj stk ptr (pop 2) 2052
mul v0,a0,v0 ret n fact(n-1) 2056
jr ra return to caller
0
0
0
0
0
0
0
0
0
v0
0
0
a0
4
0
t0
0
sp
...
0
ra
1000
0
37
?
2000 fact sub sp,sp,8 adjust stack for
2 2004 sw ra,4(sp) save the return
addr 2008 sw a0,0(sp) save arg
n 2012 slt t0,a0,1 test for n lt
1 2016 beq t0,zero,L1 if n gt 1, goto
L1 2020 add v0,zero,1 return 1 2024
add sp,sp,8 pop 2 off stack 2028
jr ra return to caller 2032 L1
sub a0,a0,1 n gt 1 arg gets n-1 2036
jal fact call fact w/ (n-1) 2040
lw a0,0(sp) ret frm jal restr n 2044
lw ra,4(sp) restore ret addr 2048
add sp,sp,8 adj stk ptr (pop 2) 2052
mul v0,a0,v0 ret n fact(n-1) 2056
jr ra return to caller
1000
0
0
0
0
0
0
0
0
v0
0
0
a0
4
0
t0
0
sp
...
0
ra
1000
0
38
?
2000 fact sub sp,sp,8 adjust stack for
2 2004 sw ra,4(sp) save the return
addr 2008 sw a0,0(sp) save arg
n 2012 slt t0,a0,1 test for n lt
1 2016 beq t0,zero,L1 if n gt 1, goto
L1 2020 add v0,zero,1 return 1 2024
add sp,sp,8 pop 2 off stack 2028
jr ra return to caller 2032 L1
sub a0,a0,1 n gt 1 arg gets n-1 2036
jal fact call fact w/ (n-1) 2040
lw a0,0(sp) ret frm jal restr n 2044
lw ra,4(sp) restore ret addr 2048
add sp,sp,8 adj stk ptr (pop 2) 2052
mul v0,a0,v0 ret n fact(n-1) 2056
jr ra return to caller
1000
4
0
0
0
0
0
0
0
v0
0
0
a0
4
0
t0
0
sp
...
0
ra
1000
0
39
?
2000 fact sub sp,sp,8 adjust stack for
2 2004 sw ra,4(sp) save the return
addr 2008 sw a0,0(sp) save arg
n 2012 slt t0,a0,1 test for n lt
1 2016 beq t0,zero,L1 if n gt 1, goto
L1 2020 add v0,zero,1 return 1 2024
add sp,sp,8 pop 2 off stack 2028
jr ra return to caller 2032 L1
sub a0,a0,1 n gt 1 arg gets n-1 2036
jal fact call fact w/ (n-1) 2040
lw a0,0(sp) ret frm jal restr n 2044
lw ra,4(sp) restore ret addr 2048
add sp,sp,8 adj stk ptr (pop 2) 2052
mul v0,a0,v0 ret n fact(n-1) 2056
jr ra return to caller
1000
4
0
0
0
0
0
0
0
v0
0
0
lt
a0
4
1
0
t0
0
0
sp
...
0
ra
1000
0
40
?
2000 fact sub sp,sp,8 adjust stack for
2 2004 sw ra,4(sp) save the return
addr 2008 sw a0,0(sp) save arg
n 2012 slt t0,a0,1 test for n lt
1 2016 beq t0,zero,L1 if n gt 1, goto
L1 2020 add v0,zero,1 return 1 2024
add sp,sp,8 pop 2 off stack 2028
jr ra return to caller 2032 L1
sub a0,a0,1 n gt 1 arg gets n-1 2036
jal fact call fact w/ (n-1) 2040
lw a0,0(sp) ret frm jal restr n 2044
lw ra,4(sp) restore ret addr 2048
add sp,sp,8 adj stk ptr (pop 2) 2052
mul v0,a0,v0 ret n fact(n-1) 2056
jr ra return to caller
1000
4
0
0
0
0
0
0
0
v0
0
0
a0
4
0

t0
0
0
L1
0
sp
...
0
ra
1000
0
41
?
2000 fact sub sp,sp,8 adjust stack for
2 2004 sw ra,4(sp) save the return
addr 2008 sw a0,0(sp) save arg
n 2012 slt t0,a0,1 test for n lt
1 2016 beq t0,zero,L1 if n gt 1, goto
L1 2020 add v0,zero,1 return 1 2024
add sp,sp,8 pop 2 off stack 2028
jr ra return to caller 2032 L1
sub a0,a0,1 n gt 1 arg gets n-1 2036
jal fact call fact w/ (n-1) 2040
lw a0,0(sp) ret frm jal restr n 2044
lw ra,4(sp) restore ret addr 2048
add sp,sp,8 adj stk ptr (pop 2) 2052
mul v0,a0,v0 ret n fact(n-1) 2056
jr ra return to caller
1000
4
0
0
0
0
0
0
0
v0
0
0
a0
3
0
t0
0
0
sp
...
0
ra
1000
0
42
?
2000 fact sub sp,sp,8 adjust stack for
2 2004 sw ra,4(sp) save the return
addr 2008 sw a0,0(sp) save arg
n 2012 slt t0,a0,1 test for n lt
1 2016 beq t0,zero,L1 if n gt 1, goto
L1 2020 add v0,zero,1 return 1 2024
add sp,sp,8 pop 2 off stack 2028
jr ra return to caller 2032 L1
sub a0,a0,1 n gt 1 arg gets n-1 2036
jal fact call fact w/ (n-1) 2040
lw a0,0(sp) ret frm jal restr n 2044
lw ra,4(sp) restore ret addr 2048
add sp,sp,8 adj stk ptr (pop 2) 2052
mul v0,a0,v0 ret n fact(n-1) 2056
jr ra return to caller
1000
4
0
0
0
0
0
0
0
v0
0
0
a0
3
0
t0
0
0
sp
...
0
ra
2040
0
43
?
2000 fact sub sp,sp,8 adjust stack for
2 2004 sw ra,4(sp) save the return
addr 2008 sw a0,0(sp) save arg
n 2012 slt t0,a0,1 test for n lt
1 2016 beq t0,zero,L1 if n gt 1, goto
L1 2020 add v0,zero,1 return 1 2024
add sp,sp,8 pop 2 off stack 2028
jr ra return to caller 2032 L1
sub a0,a0,1 n gt 1 arg gets n-1 2036
jal fact call fact w/ (n-1) 2040
lw a0,0(sp) ret frm jal restr n 2044
lw ra,4(sp) restore ret addr 2048
add sp,sp,8 adj stk ptr (pop 2) 2052
mul v0,a0,v0 ret n fact(n-1) 2056
jr ra return to caller
1000
4
0
0
0
0
0
0
0
v0
0
0
a0
3
0
t0
0
0
sp
...
0
ra
2040
0
44
?
2000 fact sub sp,sp,8 adjust stack for
2 2004 sw ra,4(sp) save the return
addr 2008 sw a0,0(sp) save arg
n 2012 slt t0,a0,1 test for n lt
1 2016 beq t0,zero,L1 if n gt 1, goto
L1 2020 add v0,zero,1 return 1 2024
add sp,sp,8 pop 2 off stack 2028
jr ra return to caller 2032 L1
sub a0,a0,1 n gt 1 arg gets n-1 2036
jal fact call fact w/ (n-1) 2040
lw a0,0(sp) ret frm jal restr n 2044
lw ra,4(sp) restore ret addr 2048
add sp,sp,8 adj stk ptr (pop 2) 2052
mul v0,a0,v0 ret n fact(n-1) 2056
jr ra return to caller
1000
4
2040
0
0
0
0
0
0
v0
0
0
a0
3
0
t0
0
0
sp
...
0
ra
2040
0
45
?
2000 fact sub sp,sp,8 adjust stack for
2 2004 sw ra,4(sp) save the return
addr 2008 sw a0,0(sp) save arg
n 2012 slt t0,a0,1 test for n lt
1 2016 beq t0,zero,L1 if n gt 1, goto
L1 2020 add v0,zero,1 return 1 2024
add sp,sp,8 pop 2 off stack 2028
jr ra return to caller 2032 L1
sub a0,a0,1 n gt 1 arg gets n-1 2036
jal fact call fact w/ (n-1) 2040
lw a0,0(sp) ret frm jal restr n 2044
lw ra,4(sp) restore ret addr 2048
add sp,sp,8 adj stk ptr (pop 2) 2052
mul v0,a0,v0 ret n fact(n-1) 2056
jr ra return to caller
1000
4
2040
3
0
0
0
0
0
v0
0
0
a0
3
0
t0
0
0
sp
...
0
ra
2040
0
46
?
2000 fact sub sp,sp,8 adjust stack for
2 2004 sw ra,4(sp) save the return
addr 2008 sw a0,0(sp) save arg
n 2012 slt t0,a0,1 test for n lt
1 2016 beq t0,zero,L1 if n gt 1, goto
L1 2020 add v0,zero,1 return 1 2024
add sp,sp,8 pop 2 off stack 2028
jr ra return to caller 2032 L1
sub a0,a0,1 n gt 1 arg gets n-1 2036
jal fact call fact w/ (n-1) 2040
lw a0,0(sp) ret frm jal restr n 2044
lw ra,4(sp) restore ret addr 2048
add sp,sp,8 adj stk ptr (pop 2) 2052
mul v0,a0,v0 ret n fact(n-1) 2056
jr ra return to caller
1000
4
2040
3
0
0
0
0
0
v0
0
0
lt
a0
3
1
0
t0
0
0
sp
...
0
ra
2040
0
47
?
2000 fact sub sp,sp,8 adjust stack for
2 2004 sw ra,4(sp) save the return
addr 2008 sw a0,0(sp) save arg
n 2012 slt t0,a0,1 test for n lt
1 2016 beq t0,zero,L1 if n gt 1, goto
L1 2020 add v0,zero,1 return 1 2024
add sp,sp,8 pop 2 off stack 2028
jr ra return to caller 2032 L1
sub a0,a0,1 n gt 1 arg gets n-1 2036
jal fact call fact w/ (n-1) 2040
lw a0,0(sp) ret frm jal restr n 2044
lw ra,4(sp) restore ret addr 2048
add sp,sp,8 adj stk ptr (pop 2) 2052
mul v0,a0,v0 ret n fact(n-1) 2056
jr ra return to caller
1000
4
2040
3
0
0
0
0
0
v0
0
0
a0
3
0

t0
0
0
L1
0
sp
...
0
ra
2040
0
48
?
2000 fact sub sp,sp,8 adjust stack for
2 2004 sw ra,4(sp) save the return
addr 2008 sw a0,0(sp) save arg
n 2012 slt t0,a0,1 test for n lt
1 2016 beq t0,zero,L1 if n gt 1, goto
L1 2020 add v0,zero,1 return 1 2024
add sp,sp,8 pop 2 off stack 2028
jr ra return to caller 2032 L1
sub a0,a0,1 n gt 1 arg gets n-1 2036
jal fact call fact w/ (n-1) 2040
lw a0,0(sp) ret frm jal restr n 2044
lw ra,4(sp) restore ret addr 2048
add sp,sp,8 adj stk ptr (pop 2) 2052
mul v0,a0,v0 ret n fact(n-1) 2056
jr ra return to caller
1000
4
2040
3
0
0
0
0
0
v0
0
0
a0
2
0
t0
0
0
sp
...
0
ra
2040
0
49
?
2000 fact sub sp,sp,8 adjust stack for
2 2004 sw ra,4(sp) save the return
addr 2008 sw a0,0(sp) save arg
n 2012 slt t0,a0,1 test for n lt
1 2016 beq t0,zero,L1 if n gt 1, goto
L1 2020 add v0,zero,1 return 1 2024
add sp,sp,8 pop 2 off stack 2028
jr ra return to caller 2032 L1
sub a0,a0,1 n gt 1 arg gets n-1 2036
jal fact call fact w/ (n-1) 2040
lw a0,0(sp) ret frm jal restr n 2044
lw ra,4(sp) restore ret addr 2048
add sp,sp,8 adj stk ptr (pop 2) 2052
mul v0,a0,v0 ret n fact(n-1) 2056
jr ra return to caller
1000
4
2040
3
0
0
0
0
0
v0
0
0
a0
2
0
t0
0
0
sp
...
0
ra
2040
0
50
?
2000 fact sub sp,sp,8 adjust stack for
2 2004 sw ra,4(sp) save the return
addr 2008 sw a0,0(sp) save arg
n 2012 slt t0,a0,1 test for n lt
1 2016 beq t0,zero,L1 if n gt 1, goto
L1 2020 add v0,zero,1 return 1 2024
add sp,sp,8 pop 2 off stack 2028
jr ra return to caller 2032 L1
sub a0,a0,1 n gt 1 arg gets n-1 2036
jal fact call fact w/ (n-1) 2040
lw a0,0(sp) ret frm jal restr n 2044
lw ra,4(sp) restore ret addr 2048
add sp,sp,8 adj stk ptr (pop 2) 2052
mul v0,a0,v0 ret n fact(n-1) 2056
jr ra return to caller
1000
4
2040
3
0
0
0
0
0
v0
0
0
a0
2
0
t0
0
0
sp
...
0
ra
2040
0
51
?
2000 fact sub sp,sp,8 adjust stack for
2 2004 sw ra,4(sp) save the return
addr 2008 sw a0,0(sp) save arg
n 2012 slt t0,a0,1 test for n lt
1 2016 beq t0,zero,L1 if n gt 1, goto
L1 2020 add v0,zero,1 return 1 2024
add sp,sp,8 pop 2 off stack 2028
jr ra return to caller 2032 L1
sub a0,a0,1 n gt 1 arg gets n-1 2036
jal fact call fact w/ (n-1) 2040
lw a0,0(sp) ret frm jal restr n 2044
lw ra,4(sp) restore ret addr 2048
add sp,sp,8 adj stk ptr (pop 2) 2052
mul v0,a0,v0 ret n fact(n-1) 2056
jr ra return to caller
1000
4
2040
3
2040
0
0
0
0
v0
0
0
a0
2
0
t0
0
0
sp
...
0
ra
2040
0
52
?
2000 fact sub sp,sp,8 adjust stack for
2 2004 sw ra,4(sp) save the return
addr 2008 sw a0,0(sp) save arg
n 2012 slt t0,a0,1 test for n lt
1 2016 beq t0,zero,L1 if n gt 1, goto
L1 2020 add v0,zero,1 return 1 2024
add sp,sp,8 pop 2 off stack 2028
jr ra return to caller 2032 L1
sub a0,a0,1 n gt 1 arg gets n-1 2036
jal fact call fact w/ (n-1) 2040
lw a0,0(sp) ret frm jal restr n 2044
lw ra,4(sp) restore ret addr 2048
add sp,sp,8 adj stk ptr (pop 2) 2052
mul v0,a0,v0 ret n fact(n-1) 2056
jr ra return to caller
1000
4
2040
3
2040
2
0
0
0
v0
0
0
a0
2
0
t0
0
0
sp
...
0
ra
2040
0
53
?
2000 fact sub sp,sp,8 adjust stack for
2 2004 sw ra,4(sp) save the return
addr 2008 sw a0,0(sp) save arg
n 2012 slt t0,a0,1 test for n lt
1 2016 beq t0,zero,L1 if n gt 1, goto
L1 2020 add v0,zero,1 return 1 2024
add sp,sp,8 pop 2 off stack 2028
jr ra return to caller 2032 L1
sub a0,a0,1 n gt 1 arg gets n-1 2036
jal fact call fact w/ (n-1) 2040
lw a0,0(sp) ret frm jal restr n 2044
lw ra,4(sp) restore ret addr 2048
add sp,sp,8 adj stk ptr (pop 2) 2052
mul v0,a0,v0 ret n fact(n-1) 2056
jr ra return to caller
1000
4
2040
3
2040
2
0
0
0
v0
0
0
lt
a0
2
1
0
t0
0
0
sp
...
0
ra
2040
0
54
?
2000 fact sub sp,sp,8 adjust stack for
2 2004 sw ra,4(sp) save the return
addr 2008 sw a0,0(sp) save arg
n 2012 slt t0,a0,1 test for n lt
1 2016 beq t0,zero,L1 if n gt 1, goto
L1 2020 add v0,zero,1 return 1 2024
add sp,sp,8 pop 2 off stack 2028
jr ra return to caller 2032 L1
sub a0,a0,1 n gt 1 arg gets n-1 2036
jal fact call fact w/ (n-1) 2040
lw a0,0(sp) ret frm jal restr n 2044
lw ra,4(sp) restore ret addr 2048
add sp,sp,8 adj stk ptr (pop 2) 2052
mul v0,a0,v0 ret n fact(n-1) 2056
jr ra return to caller
1000
4
2040
3
2040
2
0
0
0
v0
0
0
a0
2
0

t0
0
0
L1
0
sp
...
0
ra
2040
0
55
?
2000 fact sub sp,sp,8 adjust stack for
2 2004 sw ra,4(sp) save the return
addr 2008 sw a0,0(sp) save arg
n 2012 slt t0,a0,1 test for n lt
1 2016 beq t0,zero,L1 if n gt 1, goto
L1 2020 add v0,zero,1 return 1 2024
add sp,sp,8 pop 2 off stack 2028
jr ra return to caller 2032 L1
sub a0,a0,1 n gt 1 arg gets n-1 2036
jal fact call fact w/ (n-1) 2040
lw a0,0(sp) ret frm jal restr n 2044
lw ra,4(sp) restore ret addr 2048
add sp,sp,8 adj stk ptr (pop 2) 2052
mul v0,a0,v0 ret n fact(n-1) 2056
jr ra return to caller
1000
4
2040
3
2040
2
0
0
0
v0
0
0
a0
1
0
t0
0
0
sp
...
0
ra
2040
0
56
?
2000 fact sub sp,sp,8 adjust stack for
2 2004 sw ra,4(sp) save the return
addr 2008 sw a0,0(sp) save arg
n 2012 slt t0,a0,1 test for n lt
1 2016 beq t0,zero,L1 if n gt 1, goto
L1 2020 add v0,zero,1 return 1 2024
add sp,sp,8 pop 2 off stack 2028
jr ra return to caller 2032 L1
sub a0,a0,1 n gt 1 arg gets n-1 2036
jal fact call fact w/ (n-1) 2040
lw a0,0(sp) ret frm jal restr n 2044
lw ra,4(sp) restore ret addr 2048
add sp,sp,8 adj stk ptr (pop 2) 2052
mul v0,a0,v0 ret n fact(n-1) 2056
jr ra return to caller
1000
4
2040
3
2040
2
0
0
0
v0
0
0
a0
1
0
t0
0
0
sp
...
0
ra
2040
0
57
?
2000 fact sub sp,sp,8 adjust stack for
2 2004 sw ra,4(sp) save the return
addr 2008 sw a0,0(sp) save arg
n 2012 slt t0,a0,1 test for n lt
1 2016 beq t0,zero,L1 if n gt 1, goto
L1 2020 add v0,zero,1 return 1 2024
add sp,sp,8 pop 2 off stack 2028
jr ra return to caller 2032 L1
sub a0,a0,1 n gt 1 arg gets n-1 2036
jal fact call fact w/ (n-1) 2040
lw a0,0(sp) ret frm jal restr n 2044
lw ra,4(sp) restore ret addr 2048
add sp,sp,8 adj stk ptr (pop 2) 2052
mul v0,a0,v0 ret n fact(n-1) 2056
jr ra return to caller
1000
4
2040
3
2040
2
0
0
0
v0
0
0
a0
1
0
t0
0
0
sp
...
0
ra
2040
0
58
?
2000 fact sub sp,sp,8 adjust stack for
2 2004 sw ra,4(sp) save the return
addr 2008 sw a0,0(sp) save arg
n 2012 slt t0,a0,1 test for n lt
1 2016 beq t0,zero,L1 if n gt 1, goto
L1 2020 add v0,zero,1 return 1 2024
add sp,sp,8 pop 2 off stack 2028
jr ra return to caller 2032 L1
sub a0,a0,1 n gt 1 arg gets n-1 2036
jal fact call fact w/ (n-1) 2040
lw a0,0(sp) ret frm jal restr n 2044
lw ra,4(sp) restore ret addr 2048
add sp,sp,8 adj stk ptr (pop 2) 2052
mul v0,a0,v0 ret n fact(n-1) 2056
jr ra return to caller
1000
4
2040
3
2040
2
2040
0
0
v0
0
0
a0
1
0
t0
0
0
sp
...
0
ra
2040
0
59
?
2000 fact sub sp,sp,8 adjust stack for
2 2004 sw ra,4(sp) save the return
addr 2008 sw a0,0(sp) save arg
n 2012 slt t0,a0,1 test for n lt
1 2016 beq t0,zero,L1 if n gt 1, goto
L1 2020 add v0,zero,1 return 1 2024
add sp,sp,8 pop 2 off stack 2028
jr ra return to caller 2032 L1
sub a0,a0,1 n gt 1 arg gets n-1 2036
jal fact call fact w/ (n-1) 2040
lw a0,0(sp) ret frm jal restr n 2044
lw ra,4(sp) restore ret addr 2048
add sp,sp,8 adj stk ptr (pop 2) 2052
mul v0,a0,v0 ret n fact(n-1) 2056
jr ra return to caller
1000
4
2040
3
2040
2
2040
1
0
v0
0
0
a0
1
0
t0
0
0
sp
...
0
ra
2040
0
60
?
2000 fact sub sp,sp,8 adjust stack for
2 2004 sw ra,4(sp) save the return
addr 2008 sw a0,0(sp) save arg
n 2012 slt t0,a0,1 test for n lt
1 2016 beq t0,zero,L1 if n gt 1, goto
L1 2020 add v0,zero,1 return 1 2024
add sp,sp,8 pop 2 off stack 2028
jr ra return to caller 2032 L1
sub a0,a0,1 n gt 1 arg gets n-1 2036
jal fact call fact w/ (n-1) 2040
lw a0,0(sp) ret frm jal restr n 2044
lw ra,4(sp) restore ret addr 2048
add sp,sp,8 adj stk ptr (pop 2) 2052
mul v0,a0,v0 ret n fact(n-1) 2056
jr ra return to caller
1000
4
2040
3
2040
2
2040
1
0
v0
0
0
lt
a0
1
1
0
t0
0
0
sp
...
0
ra
2040
0
61
?
2000 fact sub sp,sp,8 adjust stack for
2 2004 sw ra,4(sp) save the return
addr 2008 sw a0,0(sp) save arg
n 2012 slt t0,a0,1 test for n lt
1 2016 beq t0,zero,L1 if n gt 1, goto
L1 2020 add v0,zero,1 return 1 2024
add sp,sp,8 pop 2 off stack 2028
jr ra return to caller 2032 L1
sub a0,a0,1 n gt 1 arg gets n-1 2036
jal fact call fact w/ (n-1) 2040
lw a0,0(sp) ret frm jal restr n 2044
lw ra,4(sp) restore ret addr 2048
add sp,sp,8 adj stk ptr (pop 2) 2052
mul v0,a0,v0 ret n fact(n-1) 2056
jr ra return to caller
1000
4
2040
3
2040
2
2040
1
0
v0
0
0
a0
1
0

t0
0
0
L1
0
sp
...
0
ra
2040
0
62
?
2000 fact sub sp,sp,8 adjust stack for
2 2004 sw ra,4(sp) save the return
addr 2008 sw a0,0(sp) save arg
n 2012 slt t0,a0,1 test for n lt
1 2016 beq t0,zero,L1 if n gt 1, goto
L1 2020 add v0,zero,1 return 1 2024
add sp,sp,8 pop 2 off stack 2028
jr ra return to caller 2032 L1
sub a0,a0,1 n gt 1 arg gets n-1 2036
jal fact call fact w/ (n-1) 2040
lw a0,0(sp) ret frm jal restr n 2044
lw ra,4(sp) restore ret addr 2048
add sp,sp,8 adj stk ptr (pop 2) 2052
mul v0,a0,v0 ret n fact(n-1) 2056
jr ra return to caller
1000
4
2040
3
2040
2
2040
1
0
v0
0
0
a0
0
0
t0
0
0
sp
...
0
ra
2040
0
63
?
2000 fact sub sp,sp,8 adjust stack for
2 2004 sw ra,4(sp) save the return
addr 2008 sw a0,0(sp) save arg
n 2012 slt t0,a0,1 test for n lt
1 2016 beq t0,zero,L1 if n gt 1, goto
L1 2020 add v0,zero,1 return 1 2024
add sp,sp,8 pop 2 off stack 2028
jr ra return to caller 2032 L1
sub a0,a0,1 n gt 1 arg gets n-1 2036
jal fact call fact w/ (n-1) 2040
lw a0,0(sp) ret frm jal restr n 2044
lw ra,4(sp) restore ret addr 2048
add sp,sp,8 adj stk ptr (pop 2) 2052
mul v0,a0,v0 ret n fact(n-1) 2056
jr ra return to caller
1000
4
2040
3
2040
2
2040
1
0
v0
0
0
a0
0
0
t0
0
0
sp
...
0
ra
2040
0
64
?
2000 fact sub sp,sp,8 adjust stack for
2 2004 sw ra,4(sp) save the return
addr 2008 sw a0,0(sp) save arg
n 2012 slt t0,a0,1 test for n lt
1 2016 beq t0,zero,L1 if n gt 1, goto
L1 2020 add v0,zero,1 return 1 2024
add sp,sp,8 pop 2 off stack 2028
jr ra return to caller 2032 L1
sub a0,a0,1 n gt 1 arg gets n-1 2036
jal fact call fact w/ (n-1) 2040
lw a0,0(sp) ret frm jal restr n 2044
lw ra,4(sp) restore ret addr 2048
add sp,sp,8 adj stk ptr (pop 2) 2052
mul v0,a0,v0 ret n fact(n-1) 2056
jr ra return to caller
1000
4
2040
3
2040
2
2040
1
0
v0
0
0
a0
0
0
t0
0
0
sp
...
0
ra
2040
0
65
?
2000 fact sub sp,sp,8 adjust stack for
2 2004 sw ra,4(sp) save the return
addr 2008 sw a0,0(sp) save arg
n 2012 slt t0,a0,1 test for n lt
1 2016 beq t0,zero,L1 if n gt 1, goto
L1 2020 add v0,zero,1 return 1 2024
add sp,sp,8 pop 2 off stack 2028
jr ra return to caller 2032 L1
sub a0,a0,1 n gt 1 arg gets n-1 2036
jal fact call fact w/ (n-1) 2040
lw a0,0(sp) ret frm jal restr n 2044
lw ra,4(sp) restore ret addr 2048
add sp,sp,8 adj stk ptr (pop 2) 2052
mul v0,a0,v0 ret n fact(n-1) 2056
jr ra return to caller
1000
4
2040
3
2040
2
2040
1
2040
v0
0
0
a0
0
0
t0
0
0
sp
...
0
ra
2040
0
66
?
2000 fact sub sp,sp,8 adjust stack for
2 2004 sw ra,4(sp) save the return
addr 2008 sw a0,0(sp) save arg
n 2012 slt t0,a0,1 test for n lt
1 2016 beq t0,zero,L1 if n gt 1, goto
L1 2020 add v0,zero,1 return 1 2024
add sp,sp,8 pop 2 off stack 2028
jr ra return to caller 2032 L1
sub a0,a0,1 n gt 1 arg gets n-1 2036
jal fact call fact w/ (n-1) 2040
lw a0,0(sp) ret frm jal restr n 2044
lw ra,4(sp) restore ret addr 2048
add sp,sp,8 adj stk ptr (pop 2) 2052
mul v0,a0,v0 ret n fact(n-1) 2056
jr ra return to caller
1000
4
2040
3
2040
2
2040
1
2040
v0
0
0
a0
0
0
t0
0
0
sp
...
0
ra
2040
0
67
?
2000 fact sub sp,sp,8 adjust stack for
2 2004 sw ra,4(sp) save the return
addr 2008 sw a0,0(sp) save arg
n 2012 slt t0,a0,1 test for n lt
1 2016 beq t0,zero,L1 if n gt 1, goto
L1 2020 add v0,zero,1 return 1 2024
add sp,sp,8 pop 2 off stack 2028
jr ra return to caller 2032 L1
sub a0,a0,1 n gt 1 arg gets n-1 2036
jal fact call fact w/ (n-1) 2040
lw a0,0(sp) ret frm jal restr n 2044
lw ra,4(sp) restore ret addr 2048
add sp,sp,8 adj stk ptr (pop 2) 2052
mul v0,a0,v0 ret n fact(n-1) 2056
jr ra return to caller
1000
4
2040
3
2040
2
2040
1
2040
v0
0
0
lt
a0
0
1
0
t0
1
0
sp
...
0
ra
2040
0
68
?
2000 fact sub sp,sp,8 adjust stack for
2 2004 sw ra,4(sp) save the return
addr 2008 sw a0,0(sp) save arg
n 2012 slt t0,a0,1 test for n lt
1 2016 beq t0,zero,L1 if n gt 1, goto
L1 2020 add v0,zero,1 return 1 2024
add sp,sp,8 pop 2 off stack 2028
jr ra return to caller 2032 L1
sub a0,a0,1 n gt 1 arg gets n-1 2036
jal fact call fact w/ (n-1) 2040
lw a0,0(sp) ret frm jal restr n 2044
lw ra,4(sp) restore ret addr 2048
add sp,sp,8 adj stk ptr (pop 2) 2052
mul v0,a0,v0 ret n fact(n-1) 2056
jr ra return to caller
1000
4
2040
3
2040
2
2040
1
2040
v0
0
0
a0
0
0

t0
1
0
0
sp
...
0
ra
2040
0
CONTINUE
69
?
2000 fact sub sp,sp,8 adjust stack for
2 2004 sw ra,4(sp) save the return
addr 2008 sw a0,0(sp) save arg
n 2012 slt t0,a0,1 test for n lt
1 2016 beq t0,zero,L1 if n gt 1, goto
L1 2020 add v0,zero,1 return 1 2024
add sp,sp,8 pop 2 off stack 2028
jr ra return to caller 2032 L1
sub a0,a0,1 n gt 1 arg gets n-1 2036
jal fact call fact w/ (n-1) 2040
lw a0,0(sp) ret frm jal restr n 2044
lw ra,4(sp) restore ret addr 2048
add sp,sp,8 adj stk ptr (pop 2) 2052
mul v0,a0,v0 ret n fact(n-1) 2056
jr ra return to caller
1000
4
2040
3
2040
2
2040
1
2040
v0
1
0
a0
0
0
t0
1
0
sp
...
0
ra
2040
0
70
?
2000 fact sub sp,sp,8 adjust stack for
2 2004 sw ra,4(sp) save the return
addr 2008 sw a0,0(sp) save arg
n 2012 slt t0,a0,1 test for n lt
1 2016 beq t0,zero,L1 if n gt 1, goto
L1 2020 add v0,zero,1 return 1 2024
add sp,sp,8 pop 2 off stack 2028
jr ra return to caller 2032 L1
sub a0,a0,1 n gt 1 arg gets n-1 2036
jal fact call fact w/ (n-1) 2040
lw a0,0(sp) ret frm jal restr n 2044
lw ra,4(sp) restore ret addr 2048
add sp,sp,8 adj stk ptr (pop 2) 2052
mul v0,a0,v0 ret n fact(n-1) 2056
jr ra return to caller
1000
4
2040
3
2040
2
2040
1
2040
v0
1
0
a0
0
0
t0
1
0
sp
...
0
ra
2040
0
71
?
2000 fact sub sp,sp,8 adjust stack for
2 2004 sw ra,4(sp) save the return
addr 2008 sw a0,0(sp) save arg
n 2012 slt t0,a0,1 test for n lt
1 2016 beq t0,zero,L1 if n gt 1, goto
L1 2020 add v0,zero,1 return 1 2024
add sp,sp,8 pop 2 off stack 2028
jr ra return to caller 2032 L1
sub a0,a0,1 n gt 1 arg gets n-1 2036
jal fact call fact w/ (n-1) 2040
lw a0,0(sp) ret frm jal restr n 2044
lw ra,4(sp) restore ret addr 2048
add sp,sp,8 adj stk ptr (pop 2) 2052
mul v0,a0,v0 ret n fact(n-1) 2056
jr ra return to caller
1000
4
2040
3
2040
2
2040
1
2040
v0
1
0
a0
0
0
t0
1
0
sp
...
0
ra
2040
0
72
?
2000 fact sub sp,sp,8 adjust stack for
2 2004 sw ra,4(sp) save the return
addr 2008 sw a0,0(sp) save arg
n 2012 slt t0,a0,1 test for n lt
1 2016 beq t0,zero,L1 if n gt 1, goto
L1 2020 add v0,zero,1 return 1 2024
add sp,sp,8 pop 2 off stack 2028
jr ra return to caller 2032 L1
sub a0,a0,1 n gt 1 arg gets n-1 2036
jal fact call fact w/ (n-1) 2040
lw a0,0(sp) ret frm jal restr n 2044
lw ra,4(sp) restore ret addr 2048
add sp,sp,8 adj stk ptr (pop 2) 2052
mul v0,a0,v0 ret n fact(n-1) 2056
jr ra return to caller
1000
4
2040
3
2040
2
2040
1
2040
v0
1
0
a0
1
0
t0
1
0
sp
...
0
ra
2040
0
73
?
2000 fact sub sp,sp,8 adjust stack for
2 2004 sw ra,4(sp) save the return
addr 2008 sw a0,0(sp) save arg
n 2012 slt t0,a0,1 test for n lt
1 2016 beq t0,zero,L1 if n gt 1, goto
L1 2020 add v0,zero,1 return 1 2024
add sp,sp,8 pop 2 off stack 2028
jr ra return to caller 2032 L1
sub a0,a0,1 n gt 1 arg gets n-1 2036
jal fact call fact w/ (n-1) 2040
lw a0,0(sp) ret frm jal restr n 2044
lw ra,4(sp) restore ret addr 2048
add sp,sp,8 adj stk ptr (pop 2) 2052
mul v0,a0,v0 ret n fact(n-1) 2056
jr ra return to caller
1000
4
2040
3
2040
2
2040
1
2040
v0
1
0
a0
1
0
t0
1
0
sp
...
0
ra
2040
0
74
?
2000 fact sub sp,sp,8 adjust stack for
2 2004 sw ra,4(sp) save the return
addr 2008 sw a0,0(sp) save arg
n 2012 slt t0,a0,1 test for n lt
1 2016 beq t0,zero,L1 if n gt 1, goto
L1 2020 add v0,zero,1 return 1 2024
add sp,sp,8 pop 2 off stack 2028
jr ra return to caller 2032 L1
sub a0,a0,1 n gt 1 arg gets n-1 2036
jal fact call fact w/ (n-1) 2040
lw a0,0(sp) ret frm jal restr n 2044
lw ra,4(sp) restore ret addr 2048
add sp,sp,8 adj stk ptr (pop 2) 2052
mul v0,a0,v0 ret n fact(n-1) 2056
jr ra return to caller
1000
4
2040
3
2040
2
2040
1
2040
v0
1
0
a0
1
0
t0
1
0
sp
...
0
ra
2040
0
75
?
2000 fact sub sp,sp,8 adjust stack for
2 2004 sw ra,4(sp) save the return
addr 2008 sw a0,0(sp) save arg
n 2012 slt t0,a0,1 test for n lt
1 2016 beq t0,zero,L1 if n gt 1, goto
L1 2020 add v0,zero,1 return 1 2024
add sp,sp,8 pop 2 off stack 2028
jr ra return to caller 2032 L1
sub a0,a0,1 n gt 1 arg gets n-1 2036
jal fact call fact w/ (n-1) 2040
lw a0,0(sp) ret frm jal restr n 2044
lw ra,4(sp) restore ret addr 2048
add sp,sp,8 adj stk ptr (pop 2) 2052
mul v0,a0,v0 ret n fact(n-1) 2056
jr ra return to caller
1000
4
2040
3
2040
2
2040
1
2040
v0
1
0
a0
1
0
t0
1
0
sp
...
0
ra
2040
0
76
?
2000 fact sub sp,sp,8 adjust stack for
2 2004 sw ra,4(sp) save the return
addr 2008 sw a0,0(sp) save arg
n 2012 slt t0,a0,1 test for n lt
1 2016 beq t0,zero,L1 if n gt 1, goto
L1 2020 add v0,zero,1 return 1 2024
add sp,sp,8 pop 2 off stack 2028
jr ra return to caller 2032 L1
sub a0,a0,1 n gt 1 arg gets n-1 2036
jal fact call fact w/ (n-1) 2040
lw a0,0(sp) ret frm jal restr n 2044
lw ra,4(sp) restore ret addr 2048
add sp,sp,8 adj stk ptr (pop 2) 2052
mul v0,a0,v0 ret n fact(n-1) 2056
jr ra return to caller
1000
4
2040
3
2040
2
2040
1
2040
v0
1
0
a0
1
0
t0
1
0
sp
...
0
ra
2040
0
77
?
2000 fact sub sp,sp,8 adjust stack for
2 2004 sw ra,4(sp) save the return
addr 2008 sw a0,0(sp) save arg
n 2012 slt t0,a0,1 test for n lt
1 2016 beq t0,zero,L1 if n gt 1, goto
L1 2020 add v0,zero,1 return 1 2024
add sp,sp,8 pop 2 off stack 2028
jr ra return to caller 2032 L1
sub a0,a0,1 n gt 1 arg gets n-1 2036
jal fact call fact w/ (n-1) 2040
lw a0,0(sp) ret frm jal restr n 2044
lw ra,4(sp) restore ret addr 2048
add sp,sp,8 adj stk ptr (pop 2) 2052
mul v0,a0,v0 ret n fact(n-1) 2056
jr ra return to caller
1000
4
2040
3
2040
2
2040
1
2040
v0
1
0
a0
2
0
t0
1
0
sp
...
0
ra
2040
0
78
?
2000 fact sub sp,sp,8 adjust stack for
2 2004 sw ra,4(sp) save the return
addr 2008 sw a0,0(sp) save arg
n 2012 slt t0,a0,1 test for n lt
1 2016 beq t0,zero,L1 if n gt 1, goto
L1 2020 add v0,zero,1 return 1 2024
add sp,sp,8 pop 2 off stack 2028
jr ra return to caller 2032 L1
sub a0,a0,1 n gt 1 arg gets n-1 2036
jal fact call fact w/ (n-1) 2040
lw a0,0(sp) ret frm jal restr n 2044
lw ra,4(sp) restore ret addr 2048
add sp,sp,8 adj stk ptr (pop 2) 2052
mul v0,a0,v0 ret n fact(n-1) 2056
jr ra return to caller
1000
4
2040
3
2040
2
2040
1
2040
v0
1
0
a0
2
0
t0
1
0
sp
...
0
ra
2040
0
79
?
2000 fact sub sp,sp,8 adjust stack for
2 2004 sw ra,4(sp) save the return
addr 2008 sw a0,0(sp) save arg
n 2012 slt t0,a0,1 test for n lt
1 2016 beq t0,zero,L1 if n gt 1, goto
L1 2020 add v0,zero,1 return 1 2024
add sp,sp,8 pop 2 off stack 2028
jr ra return to caller 2032 L1
sub a0,a0,1 n gt 1 arg gets n-1 2036
jal fact call fact w/ (n-1) 2040
lw a0,0(sp) ret frm jal restr n 2044
lw ra,4(sp) restore ret addr 2048
add sp,sp,8 adj stk ptr (pop 2) 2052
mul v0,a0,v0 ret n fact(n-1) 2056
jr ra return to caller
1000
4
2040
3
2040
2
2040
1
2040
v0
1
0
a0
2
0
t0
1
0
sp
...
0
ra
2040
0
80
?
2000 fact sub sp,sp,8 adjust stack for
2 2004 sw ra,4(sp) save the return
addr 2008 sw a0,0(sp) save arg
n 2012 slt t0,a0,1 test for n lt
1 2016 beq t0,zero,L1 if n gt 1, goto
L1 2020 add v0,zero,1 return 1 2024
add sp,sp,8 pop 2 off stack 2028
jr ra return to caller 2032 L1
sub a0,a0,1 n gt 1 arg gets n-1 2036
jal fact call fact w/ (n-1) 2040
lw a0,0(sp) ret frm jal restr n 2044
lw ra,4(sp) restore ret addr 2048
add sp,sp,8 adj stk ptr (pop 2) 2052
mul v0,a0,v0 ret n fact(n-1) 2056
jr ra return to caller
1000
4
2040
3
2040
2
2040
1
2040
v0
2
0
a0
2
0
t0
1
0
sp
...
0
ra
2040
0
81
?
2000 fact sub sp,sp,8 adjust stack for
2 2004 sw ra,4(sp) save the return
addr 2008 sw a0,0(sp) save arg
n 2012 slt t0,a0,1 test for n lt
1 2016 beq t0,zero,L1 if n gt 1, goto
L1 2020 add v0,zero,1 return 1 2024
add sp,sp,8 pop 2 off stack 2028
jr ra return to caller 2032 L1
sub a0,a0,1 n gt 1 arg gets n-1 2036
jal fact call fact w/ (n-1) 2040
lw a0,0(sp) ret frm jal restr n 2044
lw ra,4(sp) restore ret addr 2048
add sp,sp,8 adj stk ptr (pop 2) 2052
mul v0,a0,v0 ret n fact(n-1) 2056
jr ra return to caller
1000
4
2040
3
2040
2
2040
1
2040
v0
2
0
a0
2
0
t0
1
0
sp
...
0
ra
2040
0
82
?
2000 fact sub sp,sp,8 adjust stack for
2 2004 sw ra,4(sp) save the return
addr 2008 sw a0,0(sp) save arg
n 2012 slt t0,a0,1 test for n lt
1 2016 beq t0,zero,L1 if n gt 1, goto
L1 2020 add v0,zero,1 return 1 2024
add sp,sp,8 pop 2 off stack 2028
jr ra return to caller 2032 L1
sub a0,a0,1 n gt 1 arg gets n-1 2036
jal fact call fact w/ (n-1) 2040
lw a0,0(sp) ret frm jal restr n 2044
lw ra,4(sp) restore ret addr 2048
add sp,sp,8 adj stk ptr (pop 2) 2052
mul v0,a0,v0 ret n fact(n-1) 2056
jr ra return to caller
1000
4
2040
3
2040
2
2040
1
2040
v0
2
0
a0
3
0
t0
1
0
sp
...
0
ra
2040
0
83
?
2000 fact sub sp,sp,8 adjust stack for
2 2004 sw ra,4(sp) save the return
addr 2008 sw a0,0(sp) save arg
n 2012 slt t0,a0,1 test for n lt
1 2016 beq t0,zero,L1 if n gt 1, goto
L1 2020 add v0,zero,1 return 1 2024
add sp,sp,8 pop 2 off stack 2028
jr ra return to caller 2032 L1
sub a0,a0,1 n gt 1 arg gets n-1 2036
jal fact call fact w/ (n-1) 2040
lw a0,0(sp) ret frm jal restr n 2044
lw ra,4(sp) restore ret addr 2048
add sp,sp,8 adj stk ptr (pop 2) 2052
mul v0,a0,v0 ret n fact(n-1) 2056
jr ra return to caller
1000
4
2040
3
2040
2
2040
1
2040
v0
2
0
a0
3
0
t0
1
0
sp
...
0
ra
2040
0
84
?
2000 fact sub sp,sp,8 adjust stack for
2 2004 sw ra,4(sp) save the return
addr 2008 sw a0,0(sp) save arg
n 2012 slt t0,a0,1 test for n lt
1 2016 beq t0,zero,L1 if n gt 1, goto
L1 2020 add v0,zero,1 return 1 2024
add sp,sp,8 pop 2 off stack 2028
jr ra return to caller 2032 L1
sub a0,a0,1 n gt 1 arg gets n-1 2036
jal fact call fact w/ (n-1) 2040
lw a0,0(sp) ret frm jal restr n 2044
lw ra,4(sp) restore ret addr 2048
add sp,sp,8 adj stk ptr (pop 2) 2052
mul v0,a0,v0 ret n fact(n-1) 2056
jr ra return to caller
1000
4
2040
3
2040
2
2040
1
2040
v0
2
0
a0
3
0
t0
1
0
sp
...
0
ra
2040
0
85
?
2000 fact sub sp,sp,8 adjust stack for
2 2004 sw ra,4(sp) save t
Write a Comment
User Comments (0)
About PowerShow.com