Introduction to Computer System

Slides:



Advertisements
Similar presentations
INSTRUCTION SET ARCHITECTURES
Advertisements

Chapter 10- Instruction set architectures
1 Seoul National University Logic Design. 2 Overview of Logic Design Seoul National University Fundamental Hardware Requirements  Computation  Storage.
David O’Hallaron Carnegie Mellon University Processor Architecture Logic Design Processor Architecture Logic Design
Chapter 4 Processor Technology and Architecture. Chapter goals Describe CPU instruction and execution cycles Explain how primitive CPU instructions are.
Instruction Set Architecture CSC 333. – 2 – Instruction Set Architecture Assembly Language View Processor state Registers, memory, … Instructions addl,
CS:APP CS:APP Chapter 4 Computer Architecture Control Logic and Hardware Control Language CS:APP Chapter 4 Computer Architecture Control Logic and Hardware.
An Introduction Chapter Chapter 1 Introduction2 Computer Systems  Programmable machines  Hardware + Software (program) HardwareProgram.
Y86 Processor State Program Registers
Processor Architecture: The Y86 Instruction Set Architecture
HCL and ALU תרגול 10. Overview of Logic Design Fundamental Hardware Requirements – Communication: How to get values from one place to another – Computation.
1 Seoul National University Logic Design. 2 Overview of Logic Design Seoul National University Fundamental Hardware Requirements  Computation  Storage.
Computer Architecture and Organization
Randal E. Bryant Carnegie Mellon University CS:APP CS:APP Chapter 4 Computer Architecture SequentialImplementation CS:APP Chapter 4 Computer Architecture.
Datapath Design I Topics Sequential instruction execution cycle Instruction mapping to hardware Instruction decoding Systems I.
Computer Architecture Carnegie Mellon University
1 Sequential CPU Implementation. 2 Outline Logic design Organizing Processing into Stages SEQ timing Suggested Reading 4.2,4.3.1 ~
CS:APP3e CS:APP Chapter 4 Computer Architecture Logic Design CS:APP Chapter 4 Computer Architecture Logic Design CENG331 - Computer Organization Murat.
Computer Architecture I: Outline and Instruction Set Architecture
1 Processor Architecture. 2 Topics Write Y86 code Basic Logic design Hardware Control Language HCL Suggested Reading: 4.1, 4.2.
1 Processor Architecture. Coverage Our Approach –Work through designs for particular instruction set Y86---a simplified version of the Intel IA32 (a.k.a.
Computer Architecture
What is a program? A sequence of steps
CS161 – Design and Architecture of Computer Systems
Control Unit Lecture 6.
Y86-64 Instructions 8-byte integer operations (no floating point!)  “word” (it is considered a long word for historical reasons, because the original.
Lecture 13 Y86-64: SEQ – sequential implementation
Lecture 14 Y86-64: PIPE – pipelined implementation
Lecture 12 Logic Design Review & HCL & Bomb Lab
Introduction CPU performance factors
Computer Architecture
Seoul National University
Morgan Kaufmann Publishers The Processor
Morgan Kaufmann Publishers
RISC Concepts, MIPS ISA Logic Design Tutorial 8.
Computer Architecture and Organization Miles Murdocca and Vincent Heuring Chapter 4 – The Instruction Set Architecture.
Course Outline Background Sequential Implementation Pipelining
Sequential Implementation
Processor (I).
Samira Khan University of Virginia Feb 14, 2017
Computer Architecture adapted by Jason Fritts then by David Ferry
Y86 Processor State Program Registers
Instructions - Type and Format
Pipelined Implementation : Part I
Processor Architecture: The Y86-64 Instruction Set Architecture
Seoul National University
Pipelined Implementation : Part I
Processor Architecture: The Y86-64 Instruction Set Architecture
Morgan Kaufmann Publishers The Processor
Topic 5: Processor Architecture Implementation Methodology
Instruction encoding We’ve already seen some important aspects of processor design. A datapath contains an ALU, registers and memory. Programmers and compilers.
Seoul National University
Pipeline Architecture I Slides from: Bryant & O’ Hallaron
Introduction to Computer System
The Processor Lecture 3.1: Introduction & Logic Design Conventions
Topic 5: Processor Architecture
Recap: Performance Comparison
Computer Instructions
Other ISAs Next, we’ll first we look at a longer example program, starting with some C code and translating it into our assembly language. Then we discuss.
Branch instructions We’ll implement branch instructions for the eight different conditions shown here. Bits 11-9 of the opcode field will indicate the.
Computer Architecture
Control units In the last lecture, we introduced the basic structure of a control unit, and translated our assembly instructions into a binary representation.
Computer Architecture
Carnegie Mellon Ithaca College
CS201- Lecture 8 IA32 Flow Control
Sequential CPU Implementation
Introduction to the Architecture of Computers
Computer Architecture I: Outline and Instruction Set Architecture
Chapter 10 Instruction Sets: Characteristics and Functions
Chapter 4 The Von Neumann Model
Presentation transcript:

Introduction to Computer System

Topics Introducing to Y86-64 Logical Design & HCL Y86 instruction set architecture Suggested Reading: 4.1 Logical Design & HCL Logic design Hardware Control Language HCL Suggested Reading: 4.2

Introducing to Y86-64

IBM’s Machine before 360 By early 1960s, IBM had several incompatible families of computer: 701  7094 650  7074 702  7080 1401  7010 Each system had its own Instruction set I/O system and secondary storage assemblers, compilers, libraries,... market niche (business, scientific, real time, ...) 3

IBM 360: Initial Implementations Model 30 . . . Model 70 Storage 8K - 64 KB 256K - 512 KB Datapath 8-bit 64-bit Circuit Delay 30 nsec/level 5 nsec/level Local Store Main Store Transistor Registers Control Store Read only 1usec Conventional circuits IBM 360 instruction set architecture (ISA) completely hid the underlying technological differences between various models. Milestone: The first true ISA designed as portable hardware-software interface! With minor modifications it still survives today!

Understanding the instruction encodings Preparing for designing your Goal of Y86-64 Understanding the instruction encodings Preparing for designing your assembler simulator computer

Instruction Set Architecture Assembly Language View Processor state Registers, memory, … Instructions addq, pushq, ret, … How instructions are encoded as bytes Layer of Abstraction Above: how to program machine Processor executes instructions in a sequence Below: what needs to be built Use variety of tricks to make it run fast E.g., execute multiple instructions simultaneously ISA Compiler OS CPU Design Circuit Chip Layout Application Program

Y86-64 Processor State Program Registers Condition Codes RF: Program registers CC: Condition codes Stat: Program status %r8 %r9 %r10 %r11 %r12 %r13 %r14 %rax %rcx %rdx %rbx %rsp %rbp %rsi %rdi ZF SF OF DMEM: Memory PC Program Registers 15 registers (omit %r15). Each 64 bits Condition Codes Single-bit flags set by arithmetic or logical instructions ZF: Zero SF: Negative OF: Overflow Program Counter Indicates address of next instruction Program Status Indicates either normal operation or some error condition Memory Byte-addressable storage array Words stored in little-endian byte order

Y86-64 Instruction Set #1 Byte 1 2 3 4 5 6 7 8 9 halt nop 1 1 2 3 4 5 6 7 8 9 halt nop 1 cmovXX rA, rB 2 fn rA rB irmovq V, rB 3 F rB V rmmovq rA, D(rB) 4 rA rB D mrmovq D(rB), rA 5 rA rB D OPq rA, rB 6 fn rA rB jXX Dest 7 fn Dest call Dest 8 Dest ret 9 pushq rA A rA F popq rA B rA F

Y86-64 Instructions Format 1–10 bytes of information read from memory Can determine instruction length from first byte Not as many instruction types, and simpler encoding than with x86-64 Each accesses and modifies some part(s) of the program state

Y86-64 Instructions Format 1–10 bytes of information read from memory Can determine instruction length from first byte Not as many instruction types, and simpler encoding than with x86-64 Each accesses and modifies some part(s) of the program state

Y86-64 Instruction Set #2 Byte rrmovq 7 1 2 3 4 5 6 7 8 9 cmovle 7 1 Byte 1 2 3 4 5 6 7 8 9 cmovle 7 1 halt cmovl 7 2 nop 1 cmove 7 3 cmovXX rA, rB 2 fn rA rB cmovne 7 4 irmovq V, rB 3 F rB V cmovge 7 5 rmmovq rA, D(rB) 4 rA rB D cmovg 7 6 mrmovq D(rB), rA 5 rA rB D OPq rA, rB 6 fn rA rB jXX Dest 7 fn Dest call Dest 8 Dest ret 9 pushq rA A rA F popq rA B rA F

Y86-64 Instruction Set #3 Byte 1 2 3 4 5 6 7 8 9 halt nop 1 1 2 3 4 5 6 7 8 9 halt nop 1 cmovXX rA, rB 2 fn rA rB irmovq V, rB 3 F rB V rmmovq rA, D(rB) 4 rA rB D addq 6 subq 1 andq 2 xorq 3 mrmovq D(rB), rA 5 rA rB D OPq rA, rB 6 fn rA rB jXX Dest 7 fn Dest call Dest 8 Dest ret 9 pushq rA A rA F popq rA B rA F

Y86-64 Instruction Set #4 Byte 1 2 3 4 5 6 7 8 9 jmp 7 jle 1 jl 2 je 3 1 2 3 4 5 6 7 8 9 jmp 7 jle 1 jl 2 je 3 jne 4 jge 5 jg 6 halt nop 1 cmovXX rA, rB 2 fn rA rB irmovq V, rB 3 F rB V rmmovq rA, D(rB) 4 rA rB D mrmovq D(rB), rA 5 rA rB D OPq rA, rB 6 fn rA rB jXX Dest 7 fn Dest call Dest 8 Dest ret 9 pushq rA A rA F popq rA B rA F

Each register has 4-bit ID Encoding Registers Each register has 4-bit ID Same encoding as in x86-64 Register ID 15 (0xF) indicates “no register” Will use this in our hardware design in multiple places %rax %rcx %rdx %rbx 1 2 3 %rsp %rbp %rsi %rdi 4 5 6 7 %r8 %r9 %r10 %r11 8 9 A B %r12 %r13 %r14 No Register C D E F

Instruction Example Addition Instruction Generic Form Add value in register rA to that in register rB Store result in register rB Note that Y86-64 only allows addition to be applied to register data Set condition codes based on result e.g., addq %rax,%rsi Encoding: 60 06 Two-byte encoding First indicates instruction type Second gives source and destination registers Generic Form Encoded Representation addq rA, rB 6 rA rB

Arithmetic and Logical Operations Instruction Code Function Code Refer to generically as “OPq” Encodings differ only by “function code” Low-order 4 bytes in first instruction word Set condition codes as side effect Add addq rA, rB 6 rA rB Subtract (rA from rB) subq rA, rB 6 1 rA rB And andq rA, rB 6 2 rA rB Exclusive-Or xorq rA, rB 6 3 rA rB

Move Operations Like the x86-64 movq instruction Register  Register rrmovq rA, rB 2 rA rB Immediate  Register irmovq V, rB 3 F rB V Register  Memory rmmovq rA, D(rB) 4 rA rB D Memory  Register mrmovq D(rB), rA 5 rA rB D Like the x86-64 movq instruction Simpler format for memory addresses Give different names to keep them distinct

Move Instruction Examples Y86-64 movq $0xabcd, %rdx irmovq $0xabcd, %rdx Encoding: 30 82 cd ab 00 00 00 00 00 00 movq %rsp, %rbx rrmovq %rsp, %rbx Encoding: 20 43 movq -12(%rbp),%rcx mrmovq -12(%rbp),%rcx Encoding: 50 15 f4 ff ff ff ff ff ff ff movq %rsi,0x41c(%rsp) rmmovq %rsi,0x41c(%rsp) Encoding: 40 64 1c 04 00 00 00 00 00 00

Conditional Move Instructions Move Unconditionally Refer to generically as “cmovXX” Encodings differ only by “function code” Based on values of condition codes Variants of rrmovq instruction (Conditionally) copy value from source to destination register rrmovq rA, rB 2 rA rB Move When Less or Equal cmovle rA, rB 2 1 rA rB Move When Less cmovl rA, rB 2 rA rB Move When Equal cmove rA, rB 2 3 rA rB Move When Not Equal cmovne rA, rB 2 4 rA rB Move When Greater or Equal cmovge rA, rB 2 5 rA rB Move When Greater cmovg rA, rB 2 6 rA rB

Jump Instructions Refer to generically as “jXX” Jump (Conditionally) jXX Dest 7 fn Dest Refer to generically as “jXX” Encodings differ only by “function code” fn Based on values of condition codes Same as x86-64 counterparts Encode full destination address Unlike PC-relative addressing seen in x86-64

Jump Instructions Jump Unconditionally jmp Dest 7 Dest Jump When Less or Equal jle Dest 7 1 Dest Jump When Less jl Dest 7 2 Dest Jump When Equal je Dest 7 3 Dest Jump When Not Equal jne Dest 7 4 Dest Jump When Greater or Equal jge Dest 7 5 Dest Jump When Greater jg Dest 7 6 Dest

Y86-64 Program Stack %rsp Stack “Bottom” Region of memory holding program data Used in Y86-64 (and x86-64) for supporting procedure calls Stack top indicated by %rsp Address of top stack element Stack grows toward lower addresses Top element is at highest address in the stack When pushing, must first decrement stack pointer After popping, increment stack pointer • Increasing Addresses %rsp Stack “Top”

Stack Operations Decrement %rsp by 8 pushq rA A rA F Decrement %rsp by 8 Store word from rA to memory at %rsp Like x86-64 Read word from memory at %rsp Save in rA Increment %rsp by 8 popq rA B rA F

Subroutine Call and Return call Dest 8 Dest Push address of next instruction onto stack Start executing instructions at Dest Like x86-64 Pop value from stack Use as address for next instruction ret 9

Miscellaneous Instructions nop 1 Don’t do anything Stop executing instructions x86-64 has comparable instruction, but can’t execute it in user mode We will use it to stop the simulator Encoding ensures that program hitting memory initialized to zero will halt halt

Status Conditions Desired Behavior Normal operation Mnemonic Code AOK 1 Normal operation Halt instruction encountered Bad address (either instruction or data) encountered Invalid instruction encountered Desired Behavior If AOK, keep going Otherwise, stop program execution Mnemonic Code HLT 2 Mnemonic Code ADR 3 Mnemonic Code INS 4

Writing Y86-64 Code Try to Use C Compiler as Much as Possible Write code in C Compile for x86-64 with gcc –Og –S Transliterate into Y86-64 Modern compilers make this more difficult Coding Example Find number of elements in null-terminated list int len1(int a[]); 5043 6125 7395 a  3

Y86-64 Code Generation Example First Try Write typical array code Compile with gcc -Og -S Problem Hard to do array indexing on Y86-64 Since don’t have scaled addressing modes /* Find number of elements in null-terminated list */ long len(long a[]) { long len; for (len = 0; a[len]; len++) ; return len; } L3: addq $1,%rax cmpq $0, (%rdi,%rax,8) jne L3

Y86-64 Code Generation Example #2 Second Try Write C code that mimics expected Y86-64 code Result Compiler generates exact same code as before! Compiler converts both versions into same intermediate form long len2(long *a) { long ip = (long) a; long val = *(long *) ip; long len = 0; while (val) { ip += sizeof(long); len++; val = *(long *) ip; } return len;

Y86-64 Code Generation Example #3 len: irmovq $1, %r8 # Constant 1 irmovq $8, %r9 # Constant 8 irmovq $0, %rax # len = 0 mrmovq (%rdi), %rdx # val = *a andq %rdx, %rdx # Test val je Done # If zero, goto Done Loop: addq %r8, %rax # len++ addq %r9, %rdi # a++ jne Loop # If !0, goto Loop Done: ret Register Use %rdi a %rax len %rdx val %r8 1 %r9 8

Y86-64 Sample Program Structure #1 init: # Initialization . . . call Main halt .align 8 # Program data array: Main: # Main function call len . . . len: # Length function .pos 0x100 # Placement of stack Stack: Program starts at address 0 Must set up stack Where located Pointer values Make sure don’t overwrite code! Must initialize data

Y86-64 Program Structure #2 Program starts at address 0 init: # Set up stack pointer irmovq Stack, %rsp # Execute main program call Main # Terminate halt # Array of 4 elements + terminating 0 .align 8 Array: .quad 0x000d000d000d000d .quad 0x00c000c000c000c0 .quad 0x0b000b000b000b00 .quad 0xa000a000a000a000 .quad 0 Program starts at address 0 Must set up stack Must initialize data Can use symbolic names

Y86-64 Program Structure #3 Set up call to len Main: irmovq array,%rdi # call len(array) call len ret Set up call to len Follow x86-64 procedure conventions Push array address as argument

Assembling Y86-64 Program unix> yas len.ys Generates “object code” file len.yo Actually looks like disassembler output 0x054: | len: 0x054: 30f80100000000000000 | irmovq $1, %r8 # Constant 1 0x05e: 30f90800000000000000 | irmovq $8, %r9 # Constant 8 0x068: 30f00000000000000000 | irmovq $0, %rax # len = 0 0x072: 50270000000000000000 | mrmovq (%rdi), %rdx # val = *a 0x07c: 6222 | andq %rdx, %rdx # Test val 0x07e: 73a000000000000000 | je Done # If zero, goto Done 0x087: | Loop: 0x087: 6080 | addq %r8, %rax # len++ 0x089: 6097 | addq %r9, %rdi # a++ 0x08b: 50270000000000000000 | mrmovq (%rdi), %rdx # val = *a 0x095: 6222 | andq %rdx, %rdx # Test val 0x097: 748700000000000000 | jne Loop # If !0, goto Loop 0x0a0: | Done: 0x0a0: 90 | ret

Simulating Y86-64 Program Instruction set simulator unix> yis len.yo Instruction set simulator Computes effect of each instruction on processor state Prints changes in state from original Stopped in 33 steps at PC = 0x13. Status 'HLT', CC Z=1 S=0 O=0 Changes to registers: %rax: 0x0000000000000000 0x0000000000000004 %rsp: 0x0000000000000000 0x0000000000000100 %rdi: 0x0000000000000000 0x0000000000000038 %r8: 0x0000000000000000 0x0000000000000001 %r9: 0x0000000000000000 0x0000000000000008 Changes to memory: 0x00f0: 0x0000000000000000 0x0000000000000053 0x00f8: 0x0000000000000000 0x0000000000000013

CISC Instruction Sets Stack-oriented instruction set Complex Instruction Set Computer IA32 is example Stack-oriented instruction set Use stack to pass arguments, save program counter Explicit push and pop instructions Arithmetic instructions can access memory addq %rax, 12(%rbx,%rcx,8) requires memory read and write Complex address calculation Condition codes Set as side effect of arithmetic and logical instructions Philosophy Add instructions to perform “typical” programming tasks

RISC Instruction Sets Fewer, simpler instructions Reduced Instruction Set Computer Internal project at IBM, later popularized by Hennessy (Stanford) and Patterson (Berkeley) Fewer, simpler instructions Might take more to get given task done Can execute them with small and fast hardware Register-oriented instruction set Many more (typically 32) registers Use for arguments, return pointer, temporaries Only load and store instructions can access memory Similar to Y86-64 mrmovq and rmmovq No Condition codes Test instructions return 0/1 in register

MIPS Registers

MIPS Instruction Examples Op Ra Rb Rd Fn 00000 R-R addu $3,$2,$1 # Register add: $3 = $2+$1 Op Ra Rb Immediate R-I addu $3,$2, 3145 # Immediate add: $3 = $2+3145 sll $3,$2,2 # Shift left: $3 = $2 << 2 Branch Op Ra Rb Offset beq $3,$2,dest # Branch when $3 = $2 Load/Store Op Ra Rb Offset lw $3,16($2) # Load Word: $3 = M[$2+16] sw $3,16($2) # Store Word: M[$2+16] = $3

CISC vs. RISC Original Debate Current Status Strong opinions! CISC proponents---easy for compiler, fewer code bytes RISC proponents---better for optimizing compilers, can make run fast with simple chip design Current Status For desktop processors, choice of ISA not a technical issue With enough hardware, can make anything run fast Code compatibility more important x86-64 adopted many RISC features More registers; use them for argument passing For embedded processors, RISC makes sense Smaller, cheaper, less power Most cell phones use ARM processor

Summary Y86-64 Instruction Set Architecture Similar state and instructions as x86-64 Simpler encodings Somewhere between CISC and RISC How Important is ISA Design? Less now than before With enough hardware, can make almost anything go fast

Logical Design & HCL

Hardware Control Language (HCL) Logic Design Digital circuit What is digital circuit? Know what a CPU will base on? Hardware Control Language (HCL) A simple and functional language to describe our CPU implementation Syntax like C

Category of Circuit Analog Circuit Use all the range of Signal Most part is amplifier Hard to model and automatic design Use transistor and capacitance as basis We will not discuss it here

Category of Circuit Digital Circuit Has only two values, 0 and 1 Easy to model and design Use true table and other tools to analyze Use gate as the basis The voltage of 1 is differ in different kind circuit. E.g. TTL circuit using 5 voltage as 1

Digital Signals 1 Voltage Time 1 Use voltage thresholds to extract discrete values from continuous signal Simplest version: 1-bit signal Either high range (1) or low range (0) With guard range between them Not strongly affected by noise or low quality circuit elements Can make circuits simple, small, and fast

Overview of Logic Design Fundamental Hardware Requirements Communication How to get values from one place to another Computation Storage (Memory) Clock Signal A periodic signal Clock

Overview of Logic Design Bits are Our Friends Everything expressed in terms of values 0 and 1 Communication Low or high voltage on wire Computation Compute Boolean functions Storage Clock Signal

Category of Digital Circuit Combinational Circuit Without memory. So the circuit can’t have state. Any same input will get the same output at any time. Needn’t clock signal Typical application: ALU

Category of Digital Circuit Sequential Circuit = Combinational circuit + memory and clock signal Have state. Two same inputs may not generate the same output. Use clock signal to control the run of circuit. Typical application: CPU

Computing with Logic Gates And Or Not a a out out a out b b out = a && b out = a || b out = !a Outputs are Boolean functions of inputs Not an assignment operation, just give the circuit a name Respond continuously to changes in inputs With some, small delay Rising Delay Falling Delay a && b b Voltage a Time

Combinational Circuits

Combinational Circuits Acyclic Network Inputs Outputs Acyclic Network of Logic Gates Continuously responds to changes on inputs Outputs become (after some delay) Boolean functions of inputs

Hardware Control Language (HCL) Bit Equality Bit equal a b eq HCL Expression bool eq = (a&&b)||(!a&&!b) Generate 1 if a and b are equal Hardware Control Language (HCL) Very simple hardware description language Boolean operations have syntax similar to C logical operations We’ll use it to describe control logic for processors

Word Equality Word-Level Representation B = eq A HCL Representation Bit equal a31 eq31 b30 a30 eq30 b1 a1 eq1 b0 a0 eq0 eq = B A eq HCL Representation bool Eq = (A == B) 32-bit word size HCL representation Equality operation Generates Boolean value

Bit-Level Multiplexor HCL Expression Bit MUX b s a out bool out = (s&&a)||(!s&&b) Control signal s Data signals a and b Output a when s=1, b when s=0 Its name: MUX Usage: Select one signal from a couple of signals

Word Multiplexor Word-Level Representation HCL Representation ? s s b31 s a31 out31 b30 a30 out30 b0 a0 out0 Word-Level Representation s B A Out MUX HCL Representation ?

Word Multiplexor HCL Representation Select input word A or B depending on control signal s HCL representation Case expression Series of test : value pairs (Don’t require mutually) Output value for first successful test int Out = [ s : A; 1 : B; ]; default case

HCL Word-Level Examples Minimum of 3 Words HCL Representation A Min3 MIN3 B C int Min3 = [ A < B && A < C : A; B < A && B < C : B; 1 : C; ]; 好像这个Min可以简化的。求B时,条件可以为:B<C Find minimum of three input words HCL case expression Final case guarantees match

HCL Word-Level Examples 4-Way Multiplexor HCL Representation D0 D3 Out4 s0 s1 MUX4 D2 D1 int Out4 = [ !s1&&!s0: D0; !s1 : D1; !s0 : D2; 1 : D3; ]; 好像这个Min可以简化的。求B时,条件可以为:B<C Select one of 4 inputs based on two control bits HCL case expression Simplify tests by assuming sequential matching

Arithmetic Logic Unit Combinational logic Y X X + Y A L U Y X X - Y 1 A L U Y X X & Y 2 A L U Y X X ^ Y 3 A B A B A B A B OF ZF SF OF ZF SF OF ZF SF OF ZF SF Combinational logic Continuously responding to inputs Control signal selects function computed Corresponding to 4 arithmetic/logical operations in Y86-64 Also computes values for condition codes We will use it as a basic component for our CPU

Storage

Storing 1 Bit Bistable Element Q+ Q– q !q q = 0 or 1 Vin V1 V2

Storing 1 Bit (cont.) Bistable Element Q+ Q– Stable 1 Vin V1 V2 q = 0 or 1 Stable 1 Vin V1 V2 Vin = V2 Vin V1 V2 Metastable Stable 0

Physical Analogy . . . Stable 1 Metastable Stable 0 Metastable Stable left Stable right . .

Storing and Accessing 1 Bit Bistable Element Q+ Q– q !q q = 0 or 1 Q+ Q– R S R-S Latch Resetting 1 Setting 1 Storing !q q

1-Bit Latch D Latch Q+ Q– R S D C Latching Storing 1 d !d d !d q !q Data Clock Latching 1 d !d Storing d !d q !q

Transparent 1-Bit Latch Latching 1 d !d C D Q+ Time Changing D When in latching mode, combinational propogation from D to Q+ and Q– Value latched depends on value of D as C falls

Edge-Triggered Latch D R Q+ Q– C S T Data Q+ Q– C S T Clock Trigger Only in latching mode for brief period Rising clock edge Value latched depends on data as clock rises Output remains stable at all other times C D Q+ Time T

Storage Clocked Registers Clock e.g. Program Counter(PC), Condition Codes(CC) Hold single words or bits Loaded as clock rises Not “program registers” Clock A periodic signal that determines when new values are to be loaded into the devices I O Clock Clock Rising edge falling

For most of time acts as barrier between input and output Register Operation State = x Rising clock State = y Output = y y x Input = y Output = x Stores data bits For most of time acts as barrier between input and output As clock rises, loads input

State Machine Example Comb. Logic A L U Out MUX 1 Clock In Load

State Machine Example Out In Load Clock Comb. Logic Clock Load In Out State Machine Example Comb. Logic A L U Out MUX 1 Clock In Load ? X0 Clock Load In Out X0

State Machine Example Out In Load Clock Comb. Logic Clock Load In Out State Machine Example Comb. Logic A L U Out MUX 1 Clock In Load X0 X0+X0 X0 X0 Clock Load In Out X0 X0

State Machine Example Out In Load Clock Comb. Logic Clock Load In Out State Machine Example Comb. Logic A L U Out MUX 1 Clock In Load X1 X0+X1 X0 X0 Clock Load In Out X0 X1 X0

State Machine Example Out In Load Clock Comb. Logic Clock Load In Out State Machine Example Comb. Logic A L U Out MUX 1 Clock In Load X1 X0+X1+X1 X0+X1 X0+X1 Clock Load In Out X0 X1 X0 X0+X1

State Machine Example Out In Load Clock Comb. Logic Clock Load In Out State Machine Example Comb. Logic A L U Out MUX 1 Clock In Load X2 X0+X1+X2 X0+X1 X0+X1 Clock Load In Out X0 X1 X2 X0 X0+X1

State Machine Example Out In Load Clock Comb. Logic Clock Load In Out State Machine Example Comb. Logic A L U Out MUX 1 Clock In Load X2 X0…X2+X2 X0…X2 X0…X2 Clock Load In Out X0 X1 X2 X0 X0+X1 X0…X2

State Machine Example Out In Load Clock Comb. Logic Clock Load In Out State Machine Example Comb. Logic A L U Out MUX 1 Clock In Load X3 X0…X2 X0…X2 Clock Load In Out X0 X1 X2 X3 X0 X0+X1 X0…X2

State Machine Example Out In Load Clock Comb. Logic Clock Load In Out State Machine Example Comb. Logic A L U Out MUX 1 Clock In Load X3 X3 X3 Clock Load In Out X0 X1 X2 X3 X0 X0+X1 X0…X2 X3

State Machine Example Accumulator circuit State Machine Example Comb. Logic A L U Out MUX 1 Clock In Load Accumulator circuit Load or accumulate on each cycle Clock Load In Out X0 X1 X2 X3 X4 X5 X0 X0+X1 X0…X2 X3 X3+X4 X3…X5

Random-access memories Storage Random-access memories e.g. Register File, Memory Hold multiple words Address input specifies which word to read or write Possible multiple read or write ports Read word when address input changes Write word as clock rises

Register File Register file Multiple Ports A B W dstW srcA valA srcB valB valW Read ports Write port Clock Register file Holds values of program registers %eax, %esp, etc. Register identifier serves as address ID “F” implies no read or write performed Multiple Ports Can read and/or write multiple words in one cycle Each has separate address and data input/output

Register File Timing Reading x Writing x 2 y x Rising clock y 2 Like combinational logic Output data generated based on input address (After some delay) Writing Like register Update only as clock rises valA Register file 2 x A srcA x valB srcB B 2 Register file W dstW valW Clock y 2 Register file W dstW valW Clock 2 x Rising clock y 2

Memory Memory Ports Holds program data and instructions Data Memory address read write Clock data in data out error Memory Holds program data and instructions Ports A single address input A data input for writing, and a data output for reading Error signal means invalid address

Hardware Control Language Very simple hardware description language Can only express limited aspects of hardware operation Parts we want to explore and modify Data Types bool: Boolean a, b, c, … int: words A, B, C, … Does not specify word size---bytes, 64-bit words, … Statements bool a = bool-expr ; int A = int-expr ;

HCL Operations Boolean Expressions Word Expressions Classify by type of value returned Boolean Expressions Logic Operations a && b, a || b, !a Word Comparisons A == B, A != B, A < B, A <= B, A >= B, A > B Set Membership A in { B, C, D } Same as A == B || A == C || A == D Word Expressions Case expressions [ a : A; b : B; c : C ] Evaluate test expressions a, b, c, … in sequence Return word expression A, B, C, … for first successful test

Summary Storage Clocked Registers Random-access memories Hold single words (e.g., PC, CC) Loaded as clock rises Random-access memories Hold multiple words (e.g., Register File, Memory) Possible multiple read or write ports Read word when address input changes Write word as clock rises