Quiz 2
Registry Synced

Instruction Set Architecture (ISA)

497 words
2 min read

Reading compass

Now · 🎯 Learning Objectives

Instruction Set Architecture (ISA)

🎯 Learning Objectives

  • Identify MIPS instruction formats (R, I, J)
  • Explain addressing modes
  • Encode and decode machine instructions
  • Compare RISC and CISC philosophies

1. MIPS Instruction Formats

1.1 R-Type (Register)

31-2625-2120-1615-1110-65-0
opcode (6)rs (5)rt (5)rd (5)shamt (5)funct (6)
Example: add $t0, $s1, $s2 → opcode=0, rs=17(s1),rt=18(s1), rt=18(s2), rd=8($t0), shamt=0, funct=32 Encoding: 000000 10001 10010 01000 00000 100000 = 0x02324020

1.2 I-Type (Immediate)

31-2625-2120-1615-0
opcode (6)rs (5)rt (5)immediate (16)
Example: addi $t0, $s1, 100 → opcode=8, rs=17, rt=8, imm=100 Encoding: 001000 10001 01000 0000000001100100 = 0x22280064

1.3 J-Type (Jump)

31-2625-0
opcode (6)address (26)
Example: j 10000 → opcode=2, address=10000

2. Addressing Modes

ModeExampleEffective AddressMIPS Example
Registeradd $t0, $t1, $t2t1,t1, t2 valuesAll R-type
Immediateaddi $t0, $t1, 100$t1 + 100addi, andi, ori
Base/Displacementlw $t0, 100($s1)$s1 + 100lw, sw, lb, sb
PC-relativebeq $t0, $t1, labelPC + 4 + 4×offsetbeq, bne
Pseudo-directj target(PC+4)[31:28] ∥ addr × 4j, jal
Indexedadd $t0, $s1, $s2s1+s1 + s2(via register)

3. MIPS Core Instruction Set

CategoryInstructions
Arithmeticadd, sub, addi, addu, subu
Logicaland, or, nor, andi, ori
Shiftsll, srl, sra, sllv, srlv
Compareslt, slti, sltu
Memorylw, sw, lb, sb, lh, sh
Branchbeq, bne, blez, bgtz, bltz
Jumpj, jal, jr

4. Instruction Encoding Example

Assembly: lw $t0, 32($sp)
Fieldopcodersrtimmediate
Value35 (lw)29 ($sp)8 ($t0)32
Binary10001111101010000000000000100000
Hex: 0x8FA80020

5. Common Pitfalls

Pitfall: MIPS Branch Addressing

The mistake: Forgetting that branch offsets are relative to PC+4 and multiplied by 4. Correct approach: Target = PC + 4 + (offset × 4). The offset is number of instructions to skip (not bytes). Maximum forward/backward range: ±128KB.

6. Key Concepts Reference

ConceptDescription
R-typeRegister operands (3 registers)
I-typeImmediate operand (16-bit)
J-typeJump target (26-bit address)
PC-relativeBranch target = PC + offset
Base+offsetMemory address = register + constant
EndiannessByte order in memory
Word alignment32-bit words at addresses divisible by 4

7. 📝 Practice Questions

Q1: Encode sub $t3, $s0, $s7 in MIPS.
Answer: R-type: opcode=0, rs=16(s0),rt=23(s0), rt=23(s7), rd=11($t3), shamt=0, funct=34(sub). Binary: 000000 10000 10111 01011 00000 100010 = 0x02175822 Q2: Decode 0xAD550004.
Answer: Binary: 101011 01010 10101 0000000000000100. opcode=43=sw, rs=10(t2),rt=21(t2), rt=21(s5), imm=4. Assembly: sw $s5, 4($t2) Q3: For beq $t0, $t1, loop where loop is at PC-24, what's the offset?
Answer: Target = PC + 4 + 4×offset. -24 = 4 + 4×offset → offset = -7. In 16-bit: 0xFFF9 (2's complement). Q4: How many MIPS registers are there and why?
Answer: 32 general-purpose registers (5-bit addressing). MIPS is a RISC architecture — more registers require more bits in instruction encoding. 32 registers balances: (1) enough for variables, (2) reasonable instruction size (32-bit), (3) 5-bit register fields leave room for opcode, funct, immediate in 32-bit words.

8. 🔗 Cross-References

Document outline

Keep your place and jump directly to a heading.

Table of Contents
System Normal // Awaiting Context

Intelligence Hub

Navigate the knowledge graph to generate context. The Hub adapts dynamically to surface backlinks, related notes, and metadata insights.