Show Menu
Cheatography

cs2100 midterms Cheat Sheet (DRAFT) by

Midterm cheatsheet for CS2100, S1, AY23/24

This is a draft cheat sheet. It is a work in progress and is not finished yet.

Number System

 
1s-com­plement
2s-com­plement
Min
-(2n-1-1)
-(2n-1)
Max
2n-1-1
2n-1-1
Zero(s)
0, 2n-1
0
Negation
2n - X -1
2n-X
Addition[1]
Add carry out to result
Ignore carry out
 
Sign-M­agn­itude
Excess
Min
-(2n-1-1)
-excess
Max
2n-1-1
2n-excess-1
Zero(s)
0, 2n-1
excess
 
Diminished radix
(r-1)'s complement
Radix
r's complement
Definition[2]
(r^n - 1) - X
rn - X
ASCII: 1bit parity + 7bit content
C string: Should end with '\0'
[1] overflow if the result is opposite sign of A and B
[2] radix -> base (e.g. 999...99 - X for base-9)

MIPS - Assembly

branch­/jump labels
Does not count as instn.
lw & sw
Should use offset in multiple of 4
Instru­ction Executed
Initial instn.
+num of loops
  * loop instn.
+ exit loop instn.
+ end instn.

MIPS - Memory

32 registers, each 32-bit (4-byte) long
Each word contains 32 bits (4 bytes)
Memory addresses are 32-bit long
230 memory words[1]
[1] Consec­utive words differ by 4 bytes

MIPS - Encoding

branch
If the branch is not taken:
  PC=PC+4
If the branch is taken:
  PC=(PC+4)+immd*4
I-format[1]
16-bit immd only!
J-format[2]
26-bit target address
 
Max Jump: 256MB
[1]
li
=
lui
upper 16-bit +
ori
lower 16-bit
[2] Actual address: 4-bit PC MSB + 26-bits + 2-bit word-a­lig­ned(00)
 

ISA - Design Philosophy

RISC
CISC
E.g. x86-32
E.g. MIPS, ARM
Single instru­ction performs complex operation
Small and simple instru­ction set
Smaller program size as memory was premium
Complex implem­ent­ation, no room for hardware optimi­zatio
Complex implem­ent­ation, no room for hardware optimi­zatio
Burden on software to combine simpler operations to implement high-level language statements

ISA - Data Storage

Example for C = A+B
Stack
Accumu­lator
Register
(load-store)
Memory­-Memory
Push A
Load A
Load R1, A
Add C, A, B
Push B
Add B
Load R2, B
Add
Store C
Add R3, R1, R2
Pop C
 
Store R3, C

ISA - Memory Addressing Mode

Big-Endian
Little­-Endian
MSB stored in lowest address
LSB stored in lowest address
MIPS is Big-Endian

ISA - Operations in Instru­ctions Set

Frequently Used Instru­ctions
Rank
Instru­ction
Average %
1
Load
22%
2
Condit­ional Branch
20%
3
Compare
16%
4
Store
12%
Amdahl’s law – make the common cases fast!
If the total time origin­ally:
T = (0.7 * t) + (0.3 * t)
Decrease common by 50%, uncommon by 50%
T = (0.7 * 0.5 * t) + (0.3 * 1.5 * t)
T = (0.80 * t) -> Faster
 

Datapath

Instru­ction Execution Cycle
1. Fetch
Use the PC to fetch instn from memory
Increment PC by 4
2. Decode
Read the
opcode
to determine instru­ction type
Read from all necessary registers
3. Execute
Performs
- Arithm­etic, shifting, logical
 
- Address calcul­ation
 
- Register comparison
 
- Target address calcul­ation
4. Memory
Use memory address calculated by ALU Stage
Read from or write to data memory
5. Register Write
Write into registers

Control Path

Control Signal
Execution
Purpose
RegDst
Decode­/Fetch
0: Inst[20:16]
1: Inst[1­5:11]
RegWrite
Decode/Fetch
/RegWrite
0: Idle
1: Register write
ALUSrc
ALU
0: Register RD 2
1: SignEx­t(I­nst­[15:0])
ALUcontrol
ALU
Select the operation to be performed
MemRead

/
MemWrite
Memory
0: Idle
1: Performs
MemToReg
RegWrite
1: Memory RD
0: ALU result
PCSrc
Memory
/RegWrite
0: PC + 4
1: SignEx­t(I­nst­[15:0]) << 2 + (PC + 4)

ISA - Instru­ction

Fixed Length Instru­ction Encoding
Type-A
2 * 5-bit operands
Type-B
1 * 5-bit operand
Maximum
Maximise Type-B
 
1 + (26 - 1) * 25
Minimum
Maximise Type-A
 
26 - 1 + 25