Recap of Lecture 7 and Homework Check
- Classes: stack, accumulator, register-memory, load-store.
- MIPS is (0, 3); x86 is (1, 2); VAX is memory-memory.
- Count instructions and data accesses.
- Registers won: fast, compiler-friendly, short names.
Homework check
- 1. Y = (A + B) x (C - D) in four classes: instructions and data accesses?
- 2. Code size (bits) of each D = (A + B) x (A - C) sequence?
Today's Plan (50 minutes)
0-5
Recap and homework check Lecture 7
5-8
Plan and learning outcomes
8-18
Module 1: Memory addressing byte addresses, alignment, byte order
18-31
Module 2: Addressing modes ten modes, effective address, worked example
31-38
Module 3: What to support usage statistics, field sizes, MIPS modes
38-45
Class activity effective addresses and choosing a mode
45-50
Mistakes, quiz and homework
Learning Outcomes (SLOs)
By the end of this lecture you will be able to:
SLO 8.1
Explain byte addressing, alignment and byte order (big- and little-endian), and check whether an access is aligned.
→ CLO3 · C2 Understand
SLO 8.2
Identify the common addressing modes and compute the effective address an instruction uses.
→ CLO3 · C3 Apply
SLO 8.3
Use usage statistics to justify which modes an ISA should support, and map them to the MIPS modes.
→ CLO3 · C2 Understand
CLO3: Explain instruction set principles and advanced instruction-level and thread-level parallelism techniques.
Module 1: Memory Addressing
How the machine numbers its bytes
Byte Addressing and Data Sizes
Bus seats
- Each seat has a number.
- A family of 4 in seats 12-15 is booked as 'seat 12'.
Rule: an object is named by its lowest byte address. Element i of a word array is at base + 4i.
Practical 6: sll $t2, $t1, 2 gave i x 4 for exactly this reason.
Alignment
OUTPUT
- Runtime exception at 0x00400008:
- fetch address not aligned on
- word boundary 0x10010002
Parking
A car across two painted spaces blocks both.
MARS: lw $t1, 2($t0) with $t0 = 0x10010000.
Byte Order: Little- and Big-Endian
Dates
When it matters
- 22-10-2026: small unit first (little)
- 2026-10-22: big unit first (big)
Sending binary data between machines; reading a word as bytes.
Practical 6: 168496141 = 0x0A0B0C0D printed 13 12 11 10 from offsets 0-3: MARS is little-endian.
Worked Example: Aligned or Not?
Shortcut
- Multiple of 4: last hex digit 0, 4, 8, C.
- Multiple of 8: last hex digit 0 or 8.
Also: half word 0xCAFE at 0x200, little-endian: FE at 0x200, CA at 0x201.
Module 2: Addressing Modes
How an instruction says where its operand is
Effective Address and the Basic Modes
Effective address (EA): the memory address the instruction actually uses after the calculation.
More Complex Modes
Trade-off: complex modes cut instruction count but make instructions harder to decode and pipeline (Lecture 7, Unit 3).
Worked Example: Find the Effective Address
- Given: R1 = 0x1000 R2 = 0x20 R3 = 4
- Mem[0x1000] = 0x2000 d = 4 (word)
Module 3: Which Modes to Support?
Let the measurements decide (focus on the common case)
How Often Is Each Mode Used?
Common case
Three modes do almost all the work. Make them fast.
How Many Bits for Displacement and Immediate?
12-16 bits
8-16 bits
16 bits
displacement
immediate
MIPS chose
covers 75-99%
covers 50-80%
-32768 to +32767
- addi $t1, $t0, 25 # 16-bit immediate
- lw $t2, 16($s1) # 16-bit displacement
- lui $at, 0x1001 # big constant: upper 16 bits first
Recommendation: support displacement, immediate and register indirect - and make them fast.
The MIPS Addressing Modes
MARS Basic column (real)
- # source: lw $t0, x
- lui $at, 0x1001
- lw $t0, 4($at)
- # beq at 0x00400008, field = 2
- target = 0x0040000C + 2x4
- = 0x00400014
Note: register indirect in MIPS is just displacement 0: lw $t0, 0($s1).
Complex Modes Built from Simple MIPS
Tested in MARS 4.5
- # autoincrement
- lw $t4, 0($s3) # 10
- addi $s3, $s3, 4 # next
- lw $t5, 0($s3) # 20
- # scaled a[i], i = 3
- sll $t9, $s2, 2
- add $t9, $s1, $t9
- lw $t2, 0($t9) # 40
- # memory indirect via ptr
- la $t8, ptr
- lw $t8, 0($t8) # 0x10010008
- lw $t3, 0($t8) # 30
OUTPUT
- $t2 = 40 $t3 = 30
- $t4 = 10 $t5 = 20
- $s3 = 0x10010004
RISC idea: more instructions, but each one is simple and fast to pipeline.
Class Activity: Addresses and Modes
7 min · pairs
In pairs. Given R1 = 0x10010000, R2 = 8, Mem[0x10010000] = 0x10010010, d = 4.
Find the EA of 12(R1), (R1 + R2) and @(R1).
Find the EA of 4(R1)[R2] (scaled, d = 4).
Is a word at 0x1001000A aligned? A half word? Show A mod s.
Which mode suits: x = 7; x = a[i]; y = value at pointer p; walking a string with p++?
Common Mistakes
Wrong idea
Correct idea
✗ Little-endian stores the word backwards in every way.
✓ Only the byte order changes; bits inside each byte stay the same.
✗ Any address is fine for lw.
✓ lw needs A mod 4 = 0; MIPS gives a runtime exception otherwise.
✗ lw $t0, x is direct addressing in MIPS hardware.
✓ It is a pseudo-instruction: lui $at + lw with displacement.
✗ Memory indirect needs one memory access.
✓ It needs two: one for the address, one for the operand.
Recap Quiz
Answer on paper in 3 minutes, then we check together.
Q1
Write 0xA1B2C3D4 at address 0x40 in little-endian and in big-endian byte order.
Q2
Which of these words are aligned: 0x1004, 0x1006, 0x1010?
Q3
R1 = 0x2000, R2 = 3. EA of 8(R1)? EA of 0(R1)[R2] with d = 4?
Q4
Which three modes cover 75-99% of memory-mode uses?
Q5
Which MIPS mode do branches use, and which do loads and stores use?
Homework and Next Lecture
- Read Hennessy and Patterson, Appendix A, section A.3.
- Byte order: show the bytes of 0xCAFEBABE stored at 0x100 in both byte orders. What does a little-endian machine read as a half word at 0x102?
- Effective addresses: R1 = 0x400, R2 = 0x10, Mem[0x400] = 0x800. Find the EA for 0x20(R1), (R1 + R2), @(R1), -(R1) (d = 4).
- MIPS: rewrite Add R1, (R2)+ and Add R1, @(R3) using only MIPS instructions.
NEXT LECTURE
Lecture 9: Operations in the Instruction Set and Control Flow
Kinds of operations, conditional branches, jumps, procedure call and return, and operand types.