ECE222 - Notes
ECE222 - Notes
What is a computer
just a machine that does whatever the software tells it
to do
computer digital circuits logic gates transistors
Software just a series of instructions
is
The five classic components of a computer
CPU Central Arithmetic ALU and Central Control
Memory System
Input and output
e
CPU
cache
110 Bus
main
memory
contistier 8 It
I
disk disk graphics Network
Architecture vs Microarchitecture
compilers
in this case
Processor architecture
Functional appearance to software ISA
Memory Hierarchy
speed coast size
CPU processor
CPU Cache
Physical Memory RAM
Solid State Memory SSD USB stick
Virtual Memory hard drive a
Example
Enhancement 1 speedup of 20 on 10 of time
I
1
1.105
1 0.1
If 0.9 0.005
I
0.210.5 1.43
1 0.8 98 0
P C V2 f a
where C capacitance chip area
V power supply voltage
f clock frequency
a activity factor
Static Power consumed when powered on but
idle leaking current
What is an ISA
CISC RISC vs
Instruction Set
Arithmetic and logic add subtract multiply divide
AND OR XOR
Data movement move load store
Control flow branch and jump
System privileged used to manage processor
state handle exceptions etc
Each instruction has a
specific format and encoding
Registers
General Purpose Registers can be used for
various purposes as determined by the programme
orcompiler
Special Purpose Registers have specific roles
such as
Addressing Modes
Immediate the operand is included directly in
the instruction itself
often used for small constants and quick
arithmetic operations
Register the operand stored in
is a CPU register
often used for frequently accessed variables and
intermediate results
Direct the instruction contains the memory address
where the operand is located
often used for accessing static variables or
2 stack pointer sp
10 17 function arguments return values ao a7
Eg add x1 x2 3
a bt C where a is stored at register
1 b in register 2 and c 3
in register
add 10 x1 x2 a btc
add 10 10 3 a a d
sub 10 10 4 a a e
register
addi rd rsd number
addi 3 3 6 3 3 6
if 99
Eg add 3 4 0 f g
of
Eg add 3 0 Oxff f Oxff
negating a number
RISC V is a load store architecture
Load store aka register register architecture memory
access is limited to load and store instructions All other
instructions arithmetic logical etc operate only on
registers
size rd immerss
A to h A 3
A of
ptemp register
1W 10 126 15 temp gets A 3
add 18 121 10 temp h temp h A 3
If store temp in A
SW
48 10
p
2 5 becomes 11 1001001031 F5
outcome of comparison
beg bne bitcu bgt u
regs reg2
blt stands for branch on less than
if
regs regs registers containing the operands to compare
L label to branch to
add 11 0 0 int i o
Logical Operators
significant byte
and with OXFF 000000 isolates the most
significant byte
XOR gate with x and I gives x̅
Example Sui 11 12 2
Arithmetic Shifting
Example Srai 10 10 4
replace the contents of register 10 by bit
shifting 4 bits to the right with the same
sign
a program
Registers are faster than memory so use them
ao at 10 17 8 argument registers to
point of origin x1
50 51 8 9 52 511 18 27 saved
registers
register ra
register jr ra
Eg jair rd rs imm
Stack last in first out LIFO queue
it's in
memory so need to register to point it
This is called the stack pointer Sp 2
convention is to grow stack down from high to
low addresses
push places data onto stack decrements sp
pop removes data from stack increments sp
Stack Frame
includes
return instruction address
parameters arguments
space for other variables local
Stack frames are contiguous blocks of memory
sp tells where bottom of stack frame
when a procedure is called a new stack
frame opens
when a procedure returns the stack frame
collapses
g h i and in ao al a2 and a f in 50
Leaf
addi sp sp 8 adjust stack for 2 items
SW 51 4 sp save 51 for later
sub ao so 52 f f SI
Register Conventions
Caller the calling function
callee the function being called
Six basic
types of instruction formats
R Format register register arithmetic operations
I Format register immediate arithmetic operations loads
S Format Stores
B Format branches minor variant of S Format
U Format 20 bit upper immediate instructions
J Format jumps minor variant of U Format
R Format Instruction Layout opname rd rs1 rs2
fun 7
v32 r 2 fun ct3
rgd opcode
i the I Format
arithmetic operation
signed immediates
imm
2,01 10 57 imm 4 11 immgid i2 rsd opsode
Example
lui x 10 0 87654 10 0 87654000
addi 10 10 0 321 10 0 87654321
rd PC immed c 12
Translator converts a
program from the source
Compiler
Input high level language code eg foo c
Assembler
Input assembly language code foo s
Output machine language module object file
eg foo o
Reads and uses directives
Replaces pseudo instructions with true assembly
Directives give directions to the assembler
often generated by the compiler
directives do not produce machine instructions Rather
they inform how to build different parts of the
object file
data subsequent items put in user Data segment source file data in binary
globl sym declares sym global and can be referenced from other file
string Str store the string str in memory and null tÉminate it
Word W Wn store the n 32 bit quantities in successive memory words
2 text segment
machine code pall necessary info already in the instruction
3 data segment
however some references such as to other files or to
static data cannot yet be determined i the
assembler jots them down in the Relocation Information
and the
symbol Table
4 Symbol table
list of items in this file
Instruction Labels
used to compute machine code for PC Relative
addressing in branches function calling etc
global directive labels can be referenced by
other files
Data anything in the data section
5 relocation table
lines of code to fix later by linker
list of items whose address this file needs
any external label jumped to
Output runs
program
stored on disk
when an executable is run loader loads it into
in more detail
Loads program into a
newly created address space
reads executable's file header for sizes of text and
data segments
creates new address space for program large
enough to hold text and data segments along
with a stack segment
copy instructions and data from executable file
into new address space
copy arguments passed to the program onto
the stack
Initialize machine registers
most registers cleared stack pointer assigned address
of first free stack location
Jump to start up routine which does the following
copy program arguments from stack to registers
set PC
If main routine returns terminate program with
exit system call
language
offsite affine
program
loader memory
[Link] [Link]
[Link] ut
Conclusion
Compiler converts a single high level language file into
single assembly
a language file
Assembler removes pseudo instructions