CMPUT229 - Fall 2003
Computer Organization and
Architecture I
José Nelson Amaral
CMPUT 229 - Computer
Organization and Architecture I
1
In Your Course Package
Hennessy, John L., Patterson, David A., Computer
Organization and Design: The Hardware/Software
Interface, Morgan Kaufmann Pub., San Mateo, CA.
(H&P)
Patt, Yale N., and Patel, Sanjay J., Introduction to Computing
Systems: from bits & gates to C & Beyond,
McGrawHill Press, 2001. (P&P)
Goodman, James and Miller, Karen, A Programmer’s View
of Computer Architecture with Assembly Language Examples
from the MIPS RISC Architecure, Oxford University Press,
1993. (G&M)
Bryant, Randal E., O’Hallaron, David, Computer Systems:
229 - Computer
A Programmer’sCMPUT
Perspective,
Prentice Hall, 2003. (B&H)
Organization and Architecture I
2
In Your Course Package
Hennessy, John L., Patterson, David A., Computer
Organization and Design: The Hardware/Software
Interface, Morgan Kaufmann Pub., San Mateo, CA.
(H&P)
Patt, Yale N., and Patel, Sanjay J., Introduction to Computing
Systems: from bits & gates to C & Beyond,
McGrawHill Press, 2001. (P&P)
Goodman, James and Miller, Karen, A Programmer’s View
of Computer Architecture with Assembly Language Examples
from the MIPS RISC Architecure, Oxford University Press,
1993. (G&M)
Bryant, Randal E., O’Hallaron, David, Computer Systems:
229 - Computer
A Programmer’sCMPUT
Perspective,
Prentice Hall, 2003. (B&H)
Organization and Architecture I
3
Your Course Package
Source
P&H
P&P
P&P
P&P
P&P
H&P
H&P
G&M
G&M
P&P
P&P
B&O
P&P
B&O
Pages
A.1-A.78
1-16
17-45
47-74
75-78
104-206
275-301; 322-329
287-306
307-338
223-239
241-279
730-764
365-391
454-537
CMPUT 229 - Computer
Organization and Architecture I
Topic
MIPS Assembly Reference
Introduction
Number Representation
Digital Logic
Von Neumann Architecture
MIPS instructions
Floating Point
I/O - polling vs. interrupts
Interruption Handling
C Fundamentals
Variables & Memory Storage
Dynamic Memory, Heap
Pointers & Arrays
Caches & Coding
4
Additional Optional
Reading
An excellent reference book for the C Language:
Harbison, Samuel P., and Steele Jr., Guy, C: A Reference Manual,
Prentice Hall, 4th Edition, 1995.
An easy to follow reference to MIPS Assembly:
Waldron, J., Introduction to RISC Assembly Language
Programming, Addison-Wesley, ISBN 0-201-39828-1.
A more recent and complete book on MIPS Assembbly:
Britton, Robert L., MIPS Assembly Language
Programming, Prentice Hall, Upper Saddle River, NJ,
2004.
CMPUT 229 - Computer
Organization and Architecture I
5
2000
1998
1990
1994
1988
1980
Below Your Program
High-level void swap(int v[ ], int k)
language
{
program in C int temp;
temp = v[k];
v[k] = v[k+1];
v[k+1] = temp;
}
swap:
Compiler
Assembler
00000000101000010000000000011000
Binary
00000000100011100001100000100001
machine
10001100011000100000000000000000
10001100111100100000000000000100 language
10101100111100100000000000000000
program
10101100011000100000000000000100 (for MIPS)
00000011111000000000000000001000
CMPUT 229 - Computer
Organization and Architecture I
muli
add
lw
lw
sw
sw
jr
$2, $5, 4
$2, $4, $2
$15, 0($2)
$16, 4($2)
$16, 0($2)
$15, 4($2)
$31
Assembly
language
program
(for MIPS)
Henn-Pat, pp. 7
7
Trying it out
#include <stdio.h>
void swap(int v[ ], int k);
void print_vector(int v[ ]);
int main(int argc, char *argv[ ])
{
int v[]={1,3,5,7,9,-1};
print_vector(v);
swap(v,2);
print_vector(v);
}
void swap(int v[], int k)
{
int temp;
temp = v[k];
v[k] = v[k+1];
v[k+1] = temp;
}
void print_vector(int v[])
{
int i;
for(i=0 ; v[i]>0 ; i++)
printf("\t%d ",v[i]);
printf("\n");
}
CMPUT 229 - Computer
Organization and Architecture I
8
swap:
# vars= 8, regs= 2/0, args= 0, extra= 8
.frame
$fp,24,$31
.mask
0x50000000,-4
.fmask
0x00000000,0
.set
noreorder
.cpload
$25
.set
reorder
subu
$sp,$sp,24
.cprestore 0
sw
$fp,20($sp)
sw
$28,16($sp)
move
$fp,$sp
sw
$4,24($fp)
sw
$5,28($fp)
lw
$2,28($fp)
move
$3,$2
sll
$2,$3,2
lw
$3,24($fp)
addu
$2,$2,$3
lw
$3,0($2)
sw
$3,8($fp)
lw
$2,28($fp)
move
$3,$2
sll
$2,$3,2
lw
$3,24($fp)
addu
$2,$2,$3
lw
$3,28($fp)
move
$4,$3
sll
$3,$4,2
lw
$4,24($fp)
addu
$3,$3,$4
addu
$4,$3,4
# page 1
$ gcc -S swap.c
[on a MIPS R12K machine]
lw
sw
lw
move
sll
lw
addu
addu
lw
sw
$3,0($4)
$3,0($2)
$2,28($fp)
$3,$2
$2,$3,2
$3,24($fp)
$2,$2,$3
$3,$2,4
$2,8($fp)
$2,0($3)
# page 2
$ gcc -O3 -S swap.c
[on a MIPS R12K machine]
swap:
# vars= 0, regs= 0/0, args= 0, extra= 0
.frame
$sp,0,$31
.mask
0x00000000,0
.fmask
0x00000000,0
.set
noreorder
.cpload
$25
.set
reorder
sll
$5,$5,2
addu
$5,$5,$4
lw
$2,4($5)
lw
$3,0($5)
sw
$2,0($5)
.set
noreorder
.set
nomacro
j
$31
sw
$3,4($5)
.set
macro
.set
reorder
.end
.rdata
.align
swap
2
$ gcc -S swap.c
[on a Pentium III machine]
swap:
pushl
movl
subl
movl
imull
movl
movl
movl
movl
imull
movl
movl
imull
addl
addl
movl
movl
movl
imull
addl
leal
movl
movl
leave
ret
%ebp
%esp, %ebp
$4, %esp
12(%ebp), %eax
$4, %eax, %edx
8(%ebp), %eax
(%eax,%edx), %eax
%eax, -4(%ebp)
12(%ebp), %eax
$4, %eax, %ecx
8(%ebp), %edx
12(%ebp), %eax
$4, %eax, %eax
8(%ebp), %eax
$4, %eax
(%eax), %eax
%eax, (%edx,%ecx)
12(%ebp), %eax
$4, %eax, %eax
8(%ebp), %eax
4(%eax), %edx
-4(%ebp), %eax
%eax, (%edx)
$ gcc -O3 -S swap.c
[on a Pentium III machine]
swap:
pushl
movl
movl
pushl
movl
movl
movl
movl
movl
movl
leave
ret
%ebp
%esp, %ebp
8(%ebp), %edx
%ebx
12(%ebp), %eax
(%edx,%eax,4), %ebx
4(%edx,%eax,4), %ecx
%ecx, (%edx,%eax,4)
%ebx, 4(%edx,%eax,4)
(%esp), %ebx
$ gcc -S swap.c
[on an Itanium I machine]
swap:
.prologue 2, 2
.vframe r2
mov r2 = r12 ;;
.body
st8 [r2] = r32
mov r14 = r2 ;;
adds r14 = 8, r2 ;;
st4 [r14] = r33
mov r14 = r2
adds r16 = 12, r2 ;;
mov r14 = r2 ;;
adds r14 = 8, r2 ;;
ld4 r14 = [r14] ;;
sxt4 r15 = r14
addl r14 = 4, r0 ;;
setf.sig f6 = r15
setf.sig f7 = r14 ;;
xma.l f6 = f6, f7, f0 ;;
getf.sig r15 = f6
ld8 r14 = [r2] ;;
add r14 = r15, r14 ;;
ld4 r14 = [r14] ;;
st4 [r16] = r14
mov r14 = r2 ;;
adds r14 = 8, r2 ;;
ld4 r14 = [r14] ;;
sxt4 r15 = r14
addl r14 = 4, r0 ;;
setf.sig f6 = r15
setf.sig f7 = r14 ;;
xma.l f6 = f6, f7, f0 ;;
getf.sig r15 = f6
ld8 r14 = [r2] ;;
add r16 = r15, r14
mov r14 = r2 ;;
adds r14 = 8, r2 ;;
#page 1
ld4 r14 = [r14] ;;
sxt4 r15 = r14
addl r14 = 4, r0 ;;
setf.sig f6 = r15
setf.sig f7 = r14 ;;
xma.l f6 = f6, f7, f0 ;;
getf.sig r15 = f6
ld8 r14 = [r2] ;;
add r14 = r15, r14 ;;
adds r14 = 4, r14 ;;
ld4 r14 = [r14] ;;
st4 [r16] = r14
mov r14 = r2 ;;
adds r14 = 8, r2 ;;
ld4 r14 = [r14] ;;
sxt4 r15 = r14
addl r14 = 4, r0 ;;
setf.sig f6 = r15
setf.sig f7 = r14 ;;
xma.l f6 = f6, f7, f0 ;;
getf.sig r15 = f6
ld8 r14 = [r2] ;;
add r14 = r15, r14 ;;
adds r15 = 4, r14
mov r14 = r2 ;;
adds r14 = 12, r2 ;;
ld4 r14 = [r14] ;;
st4 [r15] = r14
.restore sp
mov r12 = r2
br.ret.sptk.many b0
.endp swap#
.section
.rodata
.align 8
# page 2
$ gcc -O3 -S swap.c
[on an Itanium I machine]
swap:
.prologue
.body
sxt4 r33 = r33 ;;
shladd r33 = r33, 2, r32 ;;
mov r14 = r33 ;;
ld4 r16 = [r14], 4 ;;
ld4 r15 = [r14] ;;
st4 [r33] = r15
st4 [r14] = r16
br.ret.sptk.many b0
.endp swap#
Admin. Information
Instructor:
Office:
Phone:
email:
Office Hours:
Prof. José Nelson Amaral
Athabasca 3-42
492-5411
amaral@cs.ualberta.ca
Wednesday 10:00-11:00
Wednesday 1:00-2:00
(Open Door Policy --- check
published schedule)
http://www.cs.ualberta.ca/~amaral/courses/329
http://ugweb.cs.ualberta.ca/~c229
CMPUT 229 - Computer
Organization and Architecture I
14
Important Dates
September 15 (Monday) :
TBA
:
December 03 (Wednesday) :
December 10 (Wednesday) :
lab classes start this week
mid-term exam
last day of classes
final for section A1 (9 AM class)
Course work will carry the following weights towards your final grade:
Lab. Assignments(using try):
Midterm Exam:
Final Exam:
Homeworks:
27%
35%
38%
Zero
CMPUT 229 - Computer
Organization and Architecture I
15
Honor Code
By turning the solution of the homework for grading, I certify that I
have worked all the solutions on my own, that I have not copied or
transcribed solutions from a classmate, someone outside the class,
or from any other source. I also certify that I have not facilitated or
allowed any of my classmates to copy my own solutions.
I am aware that students are encouraged to discuss the material
covered in the class and to work examples together. However,
the joint solution of problems assigned as individual
homework exercises is not allowed.
I am aware that the violation of this honor code constitutes a breach of
the trust granted me by the teaching staff, compromises my reputation,
and subjects me to the penalties prescribed in Section 26.1 of the
University of Alberta 2001/2002 Calendar.
CMPUT 229 - Computer
Organization and Architecture I
16
Some Sad Statistics in
Computing Science
21 cases of plagiarism in the 2000/2001 Academic Year:
# of
Students
3
1
5
1
Length of
Suspension
1 year
2 years
4 months
8 months
29 cases of plagiarism in the 2002/2003 Academic Year.
CMPUT 229 - Computer
Organization and Architecture I
17
Late Submission Policy
For Labs:
There is no late submission for labs!
All deadlines are
“drop-dead deadlines”!
Deferred exams will be scheduled for
early January, and will be different from
the final given on the scheduled date.
CMPUT 229 - Computer
Organization and Architecture I
18
Did I mention?
NO Late Submissions!!!!
None.
At all.
CMPUT 229 - Computer
Organization and Architecture I
19
Reading Assignment
Hennessy Patterson Texbook:
Appendix A: Sections A.1 to A.4 and A.9
CMPUT 229 - Computer
Organization and Architecture I
20
Machine Organization
CPU
Interrupt
Controler
256-KB
L2
Bus interface
P-Pro bus (64-bit data, 36 bit address, 66 MHz)
PCI
Bridge
Memory
Controller
Memory Interleave Unit
PCI
PCI
I/O
PCI
I/O
Cards
I/O
Cards
CMPUT 229 - Computer
Cards
Organization and Architecture I
(See CullerSinghGupta, pp. 32)
PCI Bus
PCI Bus
PCI
PCI
I/O
PCI
I/O
Cards
I/O
Cards
Cards
PCI
Bridge
1-, 2-, 4-way
Interleaved
DRAM
21
Example of SMP machine:
Pentium “quad pack”
CPU
Interrupt
Controler
CPU
256-KB
L2
Interrupt
Controler
Bus interface
CPU
256-KB
L2
Interrupt
Controler
Bus interface
CPU
256-KB
L2
Interrupt
Controler
Bus interface
256-KB
L2
Bus interface
P-Pro bus (64-bit data, 36 bit address, 66 MHz)
PCI
Bridge
Memory
Controller
Memory Interleave Unit
PCI
PCI
I/O
PCI
I/O
Cards
I/O
Cards
CMPUT 229 - Computer
Cards
Organization and Architecture I
(See CullerSinghGupta, pp. 32)
PCI Bus
PCI Bus
PCI
PCI
I/O
PCI
I/O
Cards
I/O
Cards
Cards
PCI
Bridge
1-, 2-, 4-way
Interleaved
DRAM
22
Converting Source into
Executable Files
COPYRIGHT 1998 MORGAN KAUFMANN PUBLISHERS, INC. ALL RIGHTS RESERVED
CMPUT 229 - Computer
Organization and Architecture I
Henn-Pat, pp. A-4
23
A More Complete Story
Source
file
Source
file
Compiler
Assembler
file
Assembler
Object
file
Compiler
Assembler
file
Assembler
Object
file
Program
library
Linker
Source
file
Compiler
Assembler
file
Assembler
Object
file
CMPUT 229 - Computer
Organization and Architecture I
Executable
file
Program
library
24
Converting Source into
Executable Files
COPYRIGHT 1998 MORGAN KAUFMANN PUBLISHERS, INC. ALL RIGHTS RESERVED
CMPUT 229 - Computer
Organization and Architecture I
Henn-Pat, pp. A-8
25
The Linker
COPYRIGHT 1998 MORGAN KAUFMANN PUBLISHERS, INC. ALL RIGHTS RESERVED
CMPUT 229 - Computer
Organization and Architecture I
Henn-Pat, pp. A-18
26
When to use Assembly
Language?
When you don’t have the tools to program in
higher level:
new embedded processors
compilers that check deadlines for real time
system do not exist yet
When the tools fail:
Compilers still generate sub-optimal code
When you are building the tools:
Compiler designer/builders must know assembly
well
CMPUT 229 - Computer
Organization and Architecture I
27
Anatomy of an Object File
References that must change
if the program is moved
Machine Code
in memory.
Compilation information
to allow mapping of
addresses to source code.
Size and position
of other pieces.
Associate addresses
Binary Data
with external label.
Representation.
Unresolved references.
COPYRIGHT 1998 MORGAN KAUFMANN PUBLISHERS, INC. ALL RIGHTS RESERVED
Henn-Pat, pp. A-13
CMPUT 229 - Computer
Organization and Architecture I
28
Assembler Features
Data Layout Directives
string directives
Macros
Pseudo Instructions
Conditional Assembling
CMPUT 229 - Computer
Organization and Architecture I
Henn-Pat, pp. A-14/A-17
29
SPIM
SPIM is a software simulator that runs programs written for MIPS
R2000/R3000 processors.
Features:
- available
- self-contained
- has a debugger
- provides limited operating system-like services
- at least 100 slower than hardware
- implements pseudoinstructions
- virtual machine: simulates non-delayed branches
CMPUT 229 - Computer
Organization and Architecture I
Henn-Pat, pp. A-38/A-39
30
This is where SPIM CMPUT
error messages
229 - appear.
Computer
Organization and Architecture I
Pat-Hen. pp. A-41/A-47
COPYRIGHT 1998 MORGAN KAUFMANN PUBLISHERS, INC. ALL RIGHTS RESERVED
31
Register Usage Convention
Name Number
Usage
$zero
0
constant 0
$at
1
reserved for assembler
$v0
2
return value
$v1
3
return value
$a0
4
procedure argument 1
$a1
5
procedure argument 2
$a2
6
procedure argument 3
$a3
7
procedure argument 4
$t0
8
temporary caller-saved
$t1
9
temporary caller-saved
$t2
10
temporary caller-saved
$t3
11
temporary caller-saved
$t4
12
temporary caller-saved
$t5
13
temporary caller-saved
$t6
14
temporary caller-saved
$t7
15
temporary caller-saved
Name Number
Usage
$s0
16
temporary calle-saved
$s1
17
temporary calle-saved
$s2
18
temporary calle-saved
$s3
19
temporary calle-saved
$s4
20
temporary calle-saved
$s5
21
temporary calle-saved
$s6
22
temporary calle-saved
$s7
23
temporary calle-saved
$t8
24
temporary caller-saved
$t9
25
temporary caller-saved
$k0
26
reserved for OS kernel
$k1
27
reserved for OS kernel
$gp
28
pointer to global area
$sp
29
stack pointer
$fp
30
frame pointer
$ra
31
return address
4
CMPUT 229 - Computer
Organization and Architecture I
Patt-Hen., pp. A-23
32
Register Usage Convention
Name Number
Usage
$zero
0
constant 0
$at
1
reserved for assembler
$v0
2
return value
$v1
3
return value
$a0
4
procedure argument 1
$a1
5
procedure argument 2
$a2
6
procedure argument 3
$a3
7
procedure argument 4
$t0
8
temporary caller-saved
$t1
9
temporary caller-saved
$t2
10
temporary caller-saved
$t3
11
temporary caller-saved
$t4
12
temporary caller-saved
$t5
13
temporary caller-saved
$t6
14
temporary caller-saved
$t7
15
temporary caller-saved
Name Number
Usage
$s0
16
temporary calle-saved
$s1
17
temporary calle-saved
$s2
18
temporary calle-saved
$s3
19
temporary calle-saved
$s4
20
temporary calle-saved
$s5
21
temporary calle-saved
$s6
22
temporary calle-saved
$s7
23
temporary calle-saved
$t8
24
temporary caller-saved
$t9
25
temporary caller-saved
$k0
26
reserved for OS kernel
$k1
27
reserved for OS kernel
$gp
28
pointer to global area
$sp
29
stack pointer
$fp
30
frame pointer
$ra
31
return address
4
CMPUT 229 - Computer
Organization and Architecture I
Patt-Hen., pp. A-23
33
Register Usage Convention
Name Number
Usage
$zero
0
constant 0
$at
1
reserved for assembler
$v0
2
return value
$v1
3
return value
$a0
4
procedure argument 1
$a1
5
procedure argument 2
$a2
6
procedure argument 3
$a3
7
procedure argument 4
$t0
8
temporary caller-saved
$t1
9
temporary caller-saved
$t2
10
temporary caller-saved
$t3
11
temporary caller-saved
$t4
12
temporary caller-saved
$t5
13
temporary caller-saved
$t6
14
temporary caller-saved
$t7
15
temporary caller-saved
Name Number
Usage
$s0
16
temporary calle-saved
$s1
17
temporary calle-saved
$s2
18
temporary calle-saved
$s3
19
temporary calle-saved
$s4
20
temporary calle-saved
$s5
21
temporary calle-saved
$s6
22
temporary calle-saved
$s7
23
temporary calle-saved
$t8
24
temporary caller-saved
$t9
25
temporary caller-saved
$k0
26
reserved for OS kernel
$k1
27
reserved for OS kernel
$gp
28
pointer to global area
$sp
29
stack pointer
$fp
30
frame pointer
$ra
31
return address
4
CMPUT 229 - Computer
Organization and Architecture I
Patt-Hen., pp. A-23
34
Register Usage Convention
Name Number
Usage
$zero
0
constant 0
$at
1
reserved for assembler
$v0
2
return value
$v1
3
return value
$a0
4
procedure argument 1
$a1
5
procedure argument 2
$a2
6
procedure argument 3
$a3
7
procedure argument 4
$t0
8
temporary caller-saved
$t1
9
temporary caller-saved
$t2
10
temporary caller-saved
$t3
11
temporary caller-saved
$t4
12
temporary caller-saved
$t5
13
temporary caller-saved
$t6
14
temporary caller-saved
$t7
15
temporary caller-saved
Name Number
Usage
$s0
16
temporary calle-saved
$s1
17
temporary calle-saved
$s2
18
temporary calle-saved
$s3
19
temporary calle-saved
$s4
20
temporary calle-saved
$s5
21
temporary calle-saved
$s6
22
temporary calle-saved
$s7
23
temporary calle-saved
$t8
24
temporary caller-saved
$t9
25
temporary caller-saved
$k0
26
reserved for OS kernel
$k1
27
reserved for OS kernel
$gp
28
pointer to global area
$sp
29
stack pointer
$fp
30
frame pointer
$ra
31
return address
4
CMPUT 229 - Computer
Organization and Architecture I
Patt-Hen., pp. A-23
35
Register Usage Convention
Name Number
Usage
$zero
0
constant 0
$at
1
reserved for assembler
$v0
2
return value
$v1
3
return value
$a0
4
procedure argument 1
$a1
5
procedure argument 2
$a2
6
procedure argument 3
$a3
7
procedure argument 4
$t0
8
temporary caller-saved
$t1
9
temporary caller-saved
$t2
10
temporary caller-saved
$t3
11
temporary caller-saved
$t4
12
temporary caller-saved
$t5
13
temporary caller-saved
$t6
14
temporary caller-saved
$t7
15
temporary caller-saved
Name Number
Usage
$s0
16
temporary calle-saved
$s1
17
temporary calle-saved
$s2
18
temporary calle-saved
$s3
19
temporary calle-saved
$s4
20
temporary calle-saved
$s5
21
temporary calle-saved
$s6
22
temporary calle-saved
$s7
23
temporary calle-saved
$t8
24
temporary caller-saved
$t9
25
temporary caller-saved
$k0
26
reserved for OS kernel
$k1
27
reserved for OS kernel
$gp
28
pointer to global area
$sp
29
stack pointer
$fp
30
frame pointer
$ra
31
return address
4
CMPUT 229 - Computer
Organization and Architecture I
Patt-Hen., pp. A-23
36
Register Usage Convention
Name Number
Usage
$zero
0
constant 0
$at
1
reserved for assembler
$v0
2
return value
$v1
3
return value
$a0
4
procedure argument 1
$a1
5
procedure argument 2
$a2
6
procedure argument 3
$a3
7
procedure argument 4
$t0
8
temporary caller-saved
$t1
9
temporary caller-saved
$t2
10
temporary caller-saved
$t3
11
temporary caller-saved
$t4
12
temporary caller-saved
$t5
13
temporary caller-saved
$t6
14
temporary caller-saved
$t7
15
temporary caller-saved
Name Number
Usage
$s0
16
temporary calle-saved
$s1
17
temporary calle-saved
$s2
18
temporary calle-saved
$s3
19
temporary calle-saved
$s4
20
temporary calle-saved
$s5
21
temporary calle-saved
$s6
22
temporary calle-saved
$s7
23
temporary calle-saved
$t8
24
temporary caller-saved
$t9
25
temporary caller-saved
$k0
26
reserved for OS kernel
$k1
27
reserved for OS kernel
$gp
28
pointer to global area
$sp
29
stack pointer
$fp
30
frame pointer
$ra
31
return address
4
CMPUT 229 - Computer
Organization and Architecture I
Patt-Hen., pp. A-23
37
Register Usage Convention
Name Number
Usage
$zero
0
constant 0
$at
1
reserved for assembler
$v0
2
return value
$v1
3
return value
$a0
4
procedure argument 1
$a1
5
procedure argument 2
$a2
6
procedure argument 3
$a3
7
procedure argument 4
$t0
8
temporary caller-saved
$t1
9
temporary caller-saved
$t2
10
temporary caller-saved
$t3
11
temporary caller-saved
$t4
12
temporary caller-saved
$t5
13
temporary caller-saved
$t6
14
temporary caller-saved
$t7
15
temporary caller-saved
Name Number
Usage
$s0
16
temporary calle-saved
$s1
17
temporary calle-saved
$s2
18
temporary calle-saved
$s3
19
temporary calle-saved
$s4
20
temporary calle-saved
$s5
21
temporary calle-saved
$s6
22
temporary calle-saved
$s7
23
temporary calle-saved
$t8
24
temporary caller-saved
$t9
25
temporary caller-saved
$k0
26
reserved for OS kernel
$k1
27
reserved for OS kernel
$gp
28
pointer to global area
$sp
29
stack pointer
$fp
30
frame pointer
$ra
31
return address
4
CMPUT 229 - Computer
Organization and Architecture I
Patt-Hen., pp. A-23
38
Register Usage Convention
Name Number
Usage
$zero
0
constant 0
$at
1
reserved for assembler
$v0
2
return value
$v1
3
return value
$a0
4
procedure argument 1
$a1
5
procedure argument 2
$a2
6
procedure argument 3
$a3
7
procedure argument 4
$t0
8
temporary caller-saved
$t1
9
temporary caller-saved
$t2
10
temporary caller-saved
$t3
11
temporary caller-saved
$t4
12
temporary caller-saved
$t5
13
temporary caller-saved
$t6
14
temporary caller-saved
$t7
15
temporary caller-saved
Name Number
Usage
$s0
16
temporary calle-saved
$s1
17
temporary calle-saved
$s2
18
temporary calle-saved
$s3
19
temporary calle-saved
$s4
20
temporary calle-saved
$s5
21
temporary calle-saved
$s6
22
temporary calle-saved
$s7
23
temporary calle-saved
$t8
24
temporary caller-saved
$t9
25
temporary caller-saved
$k0
26
reserved for OS kernel
$k1
27
reserved for OS kernel
$gp
28
pointer to global area
$sp
29
stack pointer
$fp
30
frame pointer
$ra
31
return address
4
CMPUT 229 - Computer
Organization and Architecture I
Patt-Hen., pp. A-23
39
Register Usage Convention
Name Number
Usage
$zero
0
constant 0
$at
1
reserved for assembler
$v0
2
return value
$v1
3
return value
$a0
4
procedure argument 1
$a1
5
procedure argument 2
$a2
6
procedure argument 3
$a3
7
procedure argument 4
$t0
8
temporary caller-saved
$t1
9
temporary caller-saved
$t2
10
temporary caller-saved
$t3
11
temporary caller-saved
$t4
12
temporary caller-saved
$t5
13
temporary caller-saved
$t6
14
temporary caller-saved
$t7
15
temporary caller-saved
Name Number
Usage
$s0
16
temporary calle-saved
$s1
17
temporary calle-saved
$s2
18
temporary calle-saved
$s3
19
temporary calle-saved
$s4
20
temporary calle-saved
$s5
21
temporary calle-saved
$s6
22
temporary calle-saved
$s7
23
temporary calle-saved
$t8
24
temporary caller-saved
$t9
25
temporary caller-saved
$k0
26
reserved for OS kernel
$k1
27
reserved for OS kernel
$gp
28
pointer to global area
$sp
29
stack pointer
$fp
30
frame pointer
$ra
31
return address
4
CMPUT 229 - Computer
Organization and Architecture I
Patt-Hen., pp. A-23
40
Register Usage Convention
Name Number
Usage
$zero
0
constant 0
$at
1
reserved for assembler
$v0
2
return value
$v1
3
return value
$a0
4
procedure argument 1
$a1
5
procedure argument 2
$a2
6
procedure argument 3
$a3
7
procedure argument 4
$t0
8
temporary caller-saved
$t1
9
temporary caller-saved
$t2
10
temporary caller-saved
$t3
11
temporary caller-saved
$t4
12
temporary caller-saved
$t5
13
temporary caller-saved
$t6
14
temporary caller-saved
$t7
15
temporary caller-saved
Name Number
Usage
$s0
16
temporary calle-saved
$s1
17
temporary calle-saved
$s2
18
temporary calle-saved
$s3
19
temporary calle-saved
$s4
20
temporary calle-saved
$s5
21
temporary calle-saved
$s6
22
temporary calle-saved
$s7
23
temporary calle-saved
$t8
24
temporary caller-saved
$t9
25
temporary caller-saved
$k0
26
reserved for OS kernel
$k1
27
reserved for OS kernel
$gp
28
pointer to global area
$sp
29
stack pointer
$fp
30
frame pointer
$ra
31
return address
4
CMPUT 229 - Computer
Organization and Architecture I
Patt-Hen., pp. A-23
41
Register Usage Convention
Name Number
Usage
$zero
0
constant 0
$at
1
reserved for assembler
$v0
2
return value
$v1
3
return value
$a0
4
procedure argument 1
$a1
5
procedure argument 2
$a2
6
procedure argument 3
$a3
7
procedure argument 4
$t0
8
temporary caller-saved
$t1
9
temporary caller-saved
$t2
10
temporary caller-saved
$t3
11
temporary caller-saved
$t4
12
temporary caller-saved
$t5
13
temporary caller-saved
$t6
14
temporary caller-saved
$t7
15
temporary caller-saved
Name Number
Usage
$s0
16
temporary calle-saved
$s1
17
temporary calle-saved
$s2
18
temporary calle-saved
$s3
19
temporary calle-saved
$s4
20
temporary calle-saved
$s5
21
temporary calle-saved
$s6
22
temporary calle-saved
$s7
23
temporary calle-saved
$t8
24
temporary caller-saved
$t9
25
temporary caller-saved
$k0
26
reserved for OS kernel
$k1
27
reserved for OS kernel
$gp
28
pointer to global area
$sp
29
stack pointer
$fp
30
frame pointer
$ra
31
return address
4
CMPUT 229 - Computer
Organization and Architecture I
Patt-Hen., pp. A-23
42
Assembler Syntax
comments begin with a sharp sign (#) and run to the end of the line.
identifiers are alphanumeric sequences, underbars (_), and dots (.)
that do not begin with a number.
labels are identifiers placed at the beginning of a line, and followed
by a colon.
item:
main:
Loop:
Exit::
.data
.word 1
.text
.globl
lw
add
add
add
lw
bne
add
j
main
$s3, item
$t1, $s3, $s3
# $t1  2 * i
$t1, $t1, $t1
# $t1  4 * i
$t1, $t1, $s6
# $t1  Addr(save[i])
$t0, 0($t1)
# $t0  MEM[save[i]]
$t0, $s5, Exit
# if save[I]  k goto Exit
$s3, $s3, $s4
# ii+j
CMPUT 229 - Computer
Loop
# goto Loop
Organization and Architecture I
43
Pat-Hen. pp. A-51
Assembler Directives
.data
identifies the beginning of the data segment
(in this example this segment contains a single word).
.word 1
stores the decimal number 1 in 32-bits (4 bytes)
.text
identifies the beginning of the text segment
(where the instructions of the program are stored).
.globl
item:
main:
Loop:
Exit::
main
declares the label main global
(so that it can be accessed from other files).
.data
.word 1
.text
.globl
lw
add
add
add
lw
bne
add
j
main
$s3, item
$t1, $s3, $s3
# $t1  2 * i
$t1, $t1, $t1
# $t1  4 * i
$t1, $t1, $s6
# $t1  Addr(save[i])
$t0, 0($t1)
# $t0  MEM[save[i]]
$t0, $s5, Exit
# if save[I]  k goto Exit
$s3, $s3, $s4
# ii+j
CMPUT 229 - Computer
Loop
# goto Loop
Organization and Architecture I
Pat-Hen. pp. A-52
44
What’s next?
Loading
Memory Layout
But, before we talk about memory
layout, we need to talk about number
representation.
CMPUT 229 - Computer
Organization and Architecture I
45