Docsity

Basic Processor Implementation - Lecture Slides | CSE 141, Study notes of Computer Architecture and Organization

Toggle sidebar
bg1
Page 1
Chien CSE141 1 October 17, 2002
Linking & Loading / Processor I
Last Time
– Procedure Call Complexities
– Assembly/Machine alternatives: Addressing modes
– RISC vs. CISC, typical tradeoffs and examples
This Time
– How Linking and Loading works
– Basic Processor Implementation
Reminders/Announcements
– Read H&P 5.1-5.5 (we’re skipping chapter #4)
– HW#2 is due Tuesday October 22, in CSE141 lecture
Chien CSE141 2 October 17, 2002
How do programs become
executable?
C -> Assembly language (compiler)
Assembly -> Machine code (assembler)
Machine code modules -> Image in machine (loader)
What happens at each step?
C Program
Compiler
Assembly
Lang
Modules Assembler Link +
Loader
Machine
Code
Modules Running Program
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13

Partial preview of the text

Download Basic Processor Implementation - Lecture Slides | CSE 141 and more Study notes Computer Architecture and Organization in PDF only on Docsity!

Chien CSE141 1 October 17, 2002

Linking & Loading / Processor I

„ Last Time

  • Procedure Call Complexities
  • Assembly/Machine alternatives: Addressing modes
  • RISC vs. CISC, typical tradeoffs and examples

„ This Time

  • How Linking and Loading works
  • Basic Processor Implementation

„ Reminders/Announcements

  • Read H&P 5.1-5.5 (we’re skipping chapter #4)
  • HW#2 is due Tuesday October 22, in CSE141 lecture

Chien CSE141 2 October 17, 2002

How do programs become

executable?

„ C -> Assembly language (compiler)

„ Assembly -> Machine code (assembler)

„ Machine code modules -> Image in machine (loader)

„ What happens at each step?

C Program Compiler

Assembly Lang Modules (^) Assembler Link + Loader

Machine Code Modules Running Program

Chien CSE141 3 October 17, 2002

Compiler: High Level Language

-> Assembly Code

„ Parsing, recognition of language features

„ Translation into appropriate assembly language

  • Synthesis of control structures
  • Construction of computation
  • Management of storage: registers, stack, memory

„ Performed on separate program modules, “separate

compilation”

C Program

Compiler

Assembly

Lang

Modules

Chien CSE141 4 October 17, 2002

Assembler: Assembly ->

Machine Language

„ Translates instructions and operands into appropriate bit

patterns

„ Translates assembler directives (data, strings, etc.) to

appropriate bit patterns, alignment, etc.

„ What about labels that cannot be resolved?

  • External labels? (declared and undefined here)
  • Relocatable modules (don’t want to resolve)
  • Produces “.o” files, some compilers generate this directly

Assembly

Lang

Modules Assembler

Machine

Code

Modules

Chien CSE141 7 October 17, 2002

Why is this such a big

production?

„ Separate compilation (cross module labels,

reasonable compile times)

„ Relocatable modules (can’t decide where things will

go in advance, compatibility across modules)

„ Additional context (besides the image) for a Unix

process -- system specific

„ How do systems deal with dynamic linked libraries?

  • Shared libraries across different programs
  • Known interfaces, dynamic patching of the connections
  • JAL and JR allow call ins from different programs, programs

must be “reentrant”

Chien CSE141 8 October 17, 2002

How to Run a Program

„ Steps from high level program to executable

  • Compilation
  • Assembly
  • Linking
  • Loading

„ => Finally can execute the program!

Chien CSE141 9 October 17, 2002

Processor Implementation

„ Focus: Software -> hardware

„ How do we implement the machine language design

that we have?

„ Objectives: speed, size, cost, performance

„ First: basic functionality

Chien CSE141 10 October 17, 2002

Control

Datapath

Memory

Processor Input

Output

The Big Picture: Where are We

Now?

„ The Five Classic Components of a Computer

„ Today’s Topic: Datapath Design, then Control Design

Chien CSE141 13 October 17, 2002

op target address

6 bits 26 bits

op rs rt rd shamt funct

6 bits 5 bits 5 bits 5 bits 5 bits 6 bits

op rs rt immediate

6 bits 5 bits 5 bits 16 bits

Review: The MIPS Instruction

Formats

„ All MIPS instructions are 32 bits long. The three

instruction formats:

  • R-type
  • I-type
  • J-type

Chien CSE141 14 October 17, 2002

op rs rt rd shamt funct

6 bits 5 bits 5 bits 5 bits 5 bits 6 bits

op rs rt immediate

6 bits 5 bits 5 bits 16 bits

op rs rt displacement

6 bits 5 bits 5 bits 16 bits

The MIPS Subset

„ R-type

  • add rd, rs, rt
  • sub, and, or, slt

„ LOAD and STORE

  • lw rt, rs, imm
  • sw rt, rs, imm

„ BRANCH:

  • beq rs, rt, imm

Chien CSE141 15 October 17, 2002

Elements of Instruction

Execution

„ Machine Instructions (focus on R class, arith + logic)

  • Instruction Fetch
  • Instruction Decode (decide what to do)
  • Read registers
  • Execute the Operation
  • Write the registers
  • Increment the program counter
  • Repeat the cycle

Chien CSE141 16 October 17, 2002

Elements of Instruction

Execution: An Example

„ add $1, $2, $

  • Read the instruction at PC
  • Decode instruction format, determine the operation
  • Read values from registers 2 and 3
  • Add the values
  • Write the results into register 1
  • PC = PC+4 (byte addressable)
  • on to the next instruction

„ Same basic sequence of operations for each of the R

class instructions

„ First, focus on the “internal steps” - decode, read,

execute, write results

Chien CSE141 19 October 17, 2002

Clk

Don’t Care

Setup Hold

Setup Hold

Clocking Methodology

„ All storage elements are clocked by the same clock edge

Chien CSE141 20 October 17, 2002

Clk

Data In

Write Enable

N N

Data Out

Storage Element: Register

„ Register

  • Similar to the D Flip Flop except
    • N-bit input and output
    • Write Enable input
  • Write Enable:
    • 0: Data Out will not change
    • 1: Data Out will become Data In (on the clock edge)

Chien CSE141 21 October 17, 2002

Clk

busW

Write Enable

busA

busB

RW RA RB

32 32-bit Registers

Storage Element: Register File

„ Register File consists of (32)

registers:

  • Two 32-bit output buses:
  • One 32-bit input bus: busW

„ Register is selected by:

  • RA selects the register to put on

busA

  • RB selects the register to put on

busB

  • RW selects the register to be

written

via busW when Write Enable is 1

„ Clock input (CLK)

Chien CSE141 22 October 17, 2002

Clk

Data In

Write Enable

DataOut

Address

Storage Element: Memory

„ Memory

  • One input bus: Data In
  • One output bus: Data Out

„ Memory word is selected by:

  • Address selects the word to put on Data Out
  • Write Enable = 1: address selects the memory word to

be written via the Data In bus

„ Clock input (CLK)

  • The CLK input is a factor ONLY during write operation
  • During read operation, behaves as a combinational

logic block:

  • Address valid => Data Out valid after “access time.”

Chien CSE141 25 October 17, 2002

Instruction Fetch Unit Overview

„ The common RTL operations

  • Fetch the Instruction: inst <- mem[PC]
  • Update the program counter:
    • Sequential Code: PC <- PC + 4
    • Branch and Jump PC <- “something else”

Chien CSE141 26 October 17, 2002

op rs rt rd shamt funct

6 bits 5 bits 5 bits 5 bits 5 bits 6 bits

Datapath for Register-Register

Operations

„ R[rd] <- R[rs] op R[rt] Example: add rd, rs, rt

  • Ra, Rb, and Rw comes from instruction’s rs, rt, and rd fields
  • ALUctr and RegWr: control logic after decoding the

instruction

Chien CSE141 27 October 17, 2002

op rs rt immediate

6 bits 5 bits 5 bits 16 bits

Datapath for Load Operations

„ R[rt] <- Mem[R[rs] + SignExt[imm16]]

„ Example: lw rt, rs, imm

Chien CSE141 28 October 17, 2002

op rs rt immediate

6 bits 5 bits 5 bits 16 bits

Datapath for Store Operations

„ Mem[R[rs] + SignExt[imm16]] <- R[rt]

„ Example: sw rt, rs, imm

Chien CSE141 31 October 17, 2002

Next Address Logic

Chien CSE141 32 October 17, 2002

Putting it All Together: A Single

Cycle Datapath

„ We have everything except control signals!

Chien CSE141 33 October 17, 2002

The R-Format (e.g. add)

Datapath

Chien CSE141 34 October 17, 2002

The Load Datapath

Chien CSE141 37 October 17, 2002

Summary

„ Linking and Loading

  • Compiler, Assembler, Linker, Loader => execute it!

„ CPU is just a collection of state and combinational

logic

  • We just designed a very rich processor, at least in terms of

functionality

„ Performance = Insts * CPI * Cycle Time

  • where does the single-cycle machine fit in?

„ Next time:

  • Control for the Single Cycle CPU