You are on page 1of 19

Registers and Register Files

1
Registers
❑ Built-in memory locations in the processor
❑ Fastest memory location
❑ Can hold an instruction, a memory location, or data

2
RAM and Processor on Motherboard

3
Registers
❑ MIPS has 32 registers
❑ X86 has 8 registers
Why not add more?
❑ Each register is 32-bit wide
▪ Referred to as 32-bit architecture
▪ This means that you can have addresses that are 32-bit in size!

❑ Modern computers have 64-bit wide registers


▪ Referred to as 64-bit architectures

4
How many addresses a 32-bit register can refer?
32-bit Address

1 Byte
4 billion
232 Different values 1 Byte
unique
addresses 1 Byte
1 Byte
230 × 22 Different values 1 Byte
1 Byte
Giga 1 Byte
4Giga Different values 1 Byte

𝟒𝑮𝒊𝒈𝒂 × 𝟏 𝑩𝒚𝒕𝒆 = 𝟒 𝑮𝒊𝒈𝒂𝑩𝒚𝒕𝒆


What if memory chunk is of 4Bytes?

5
How many addresses a 32-bit register can refer?
32-bit Address

4 Byte
4 billion
232 Different values 4 Byte
unique
addresses 4 Byte
4 Byte
230 × 22 Different values 4 Byte
4 Byte
Giga 4 Byte
4Giga Different values 4 Byte

𝟒𝑮𝒊𝒈𝒂 × 𝟏 𝑩𝒚𝒕𝒆 = 𝟒 𝑮𝒊𝒈𝒂𝑩𝒚𝒕𝒆


What if memory chunk is of 4Bytes?

6
How many addresses a 32-bit register can refer?
4 Bytes chunk is known
32-bit Address as “word” in memory

4 Byte
4 billion
232 Different values 4 Byte
unique
addresses 4 Byte
4 Byte
230 × 22 Different values 4 Byte
4 Byte
Giga 4 Byte
4Giga Different values 4 Byte

𝟒𝑮𝒊𝒈𝒂 × 𝟒 𝑩𝒚𝒕𝒆 = 𝟏𝟔 𝑮𝒊𝒈𝒂𝑩𝒚𝒕𝒆


What if memory chunk is of 4Bytes?

7
Possible Word Sizes
❑ 8, 16, 24, 32, or 64 bits
How many Bytes?

❑ Modern general purpose computers usually use 32 or 64 bits

8
Register Files
❑ Consists of a set of registers that can be read and written by supplying a register
number to be accessed.
❑ Values must be fetched from memory before performing any operation on them

𝒍𝒘 𝑹𝟏, 𝒎𝒆𝒎𝒐𝒓𝒚 − 𝒂𝒅𝒅𝒓𝒆𝒔𝒔 But its not


that simple!
How is memory-
s𝒘 𝑹𝟏, 𝒎𝒆𝒎𝒐𝒓𝒚 − 𝒂𝒅𝒅𝒓𝒆𝒔𝒔
address
determined?
9
Recall from Assembly Language…

10
Recall from Assembly Language…

11
Example of an instruction

Because we have 32 registers so


Why 5-bits for
to refer to each register, we need
each register?
5 bits as 𝟐𝟓 = 𝟑𝟐
12
Registers and Main Memory
❑ Each “variable” is a location in memory
❑ Each memory access is expensive.
▪ If a variable “a” is accessed repeatedly, it makes the execution faster if we bring the variable
into an on-chip scratchpad and operate on the scratchpad (registers)

❑ To simplify the instructions, we require that each instruction only operate on


registers

Number of operands Number of operands


(variables) in a program (variables) in assembly is
are very large fixed (limited registers)
13
Memory Address
❑ The compiler organizes data in memory
▪ It knows the location of every variable (saved in a table)
▪ It can fill in the appropriate memory address for load-store instructions

❑ Compiler works with “Virtual Memory” aka “Virtual Address Space”

14
Memory Address
a b c a=b+c

Memory

a 0
lw R1, 4(R0) Load is performed with offset
Base Address from base address
b 4 lw R2, 8(R0)
(Lets say
stored in R0) c 8
add R3, R1, R2
sw R3, 0(R0)

15
Base Address in Arrays: Example
D[2]
a b c D[0]
D[1]
d = [100, 200, 300]
d[2] = d[0] + d[1]
Memory

a 0
lw R1, 12(R0)
Base Address
b 4 lw R2, 16(R0)
(Lets say
stored in R0) c 8
d[0] 12 add R3, R1, R2
d[1] 16
sw R3, 20(R0)
d[2] 20

16
Immediate Operands
❑ An immediate instruction uses a constant number as one of the inputs
(instead of a register operand)
R-Type
Instructions add R3, R1, R2

I-Type
Instructions add R3, R1, 1000 What if we want
to store a
constant value in
a register?

17
Immediate Operands
❑ Putting a constant in a register requires addition to register $zero
▪ A special register that always has a zero in it

❑ Since every instruction requires at least one operand to be a register


▪ Putting the constant 1000 into a register would require us to do:

add R10, $zero, 1000

18
Text Book Study
❑ T1: 1.6
❑ T2: 1.8, B.8

19

You might also like