1 Processor Architecture. 2 Topics Write Y86 code Basic Logic design Hardware Control Language HCL Suggested Reading: 4.1, 4.2.

Slides:



Advertisements
Similar presentations
1 Seoul National University Logic Design. 2 Overview of Logic Design Seoul National University Fundamental Hardware Requirements  Computation  Storage.
Advertisements

David O’Hallaron Carnegie Mellon University Processor Architecture Logic Design Processor Architecture Logic Design
PipelinedImplementation Part I CSC 333. – 2 – Overview General Principles of Pipelining Goal Difficulties Creating a Pipelined Y86 Processor Rearranging.
Machine-Level Programming III: Procedures Apr. 17, 2006 Topics IA32 stack discipline Register saving conventions Creating pointers to local variables CS213.
PC hardware and x86 3/3/08 Frans Kaashoek MIT
1 ICS 51 Introductory Computer Organization Fall 2006 updated: Oct. 2, 2006.
Lecture Notes from Randal E. Bryant, CMU CS:APP Chapter 4 Computer Architecture Instruction Set Architecture CS:APP Chapter 4 Computer Architecture Instruction.
– 1 – , F’02 ICS05 Instructor: Peter A. Dinda TA: Bin Lin Recitation 4.
Instruction Set Architecture CSC 333. – 2 – Instruction Set Architecture Assembly Language View Processor state Registers, memory, … Instructions addl,
Assembly תרגול 8 פונקציות והתקפת buffer.. Procedures (Functions) A procedure call involves passing both data and control from one part of the code to.
September 22, 2014 Pengju (Jimmy) Jin Section E
CS:APP CS:APP Chapter 4 Computer Architecture Control Logic and Hardware Control Language CS:APP Chapter 4 Computer Architecture Control Logic and Hardware.
Stack Activation Records Topics IA32 stack discipline Register saving conventions Creating pointers to local variables February 6, 2003 CSCE 212H Computer.
Randal E. Bryant CS:APP Chapter 4 Computer Architecture SequentialImplementation CS:APP Chapter 4 Computer Architecture SequentialImplementation Slides.
6.828: PC hardware and x86 Frans Kaashoek
Y86 Processor State Program Registers
CS:APP2e CS:APP Chapter 4 Computer Architecture Instruction Set Architecture.
Processor Architecture: The Y86 Instruction Set Architecture
Randal E. Bryant adapted by Jason Fritts CS:APP2e CS:APP Chapter 4 Computer Architecture Instruction Set Architecture CS:APP Chapter 4 Computer Architecture.
Fabián E. Bustamante, Spring 2007 Machine-Level Programming III - Procedures Today IA32 stack discipline Register saving conventions Creating pointers.
HCL and ALU תרגול 10. Overview of Logic Design Fundamental Hardware Requirements – Communication: How to get values from one place to another – Computation.
Fall 2012 Chapter 2: x86 Processor Architecture. Irvine, Kip R. Assembly Language for x86 Processors 6/e, Chapter Overview General Concepts IA-32.
1 Seoul National University Pipelined Implementation : Part I.
1 Seoul National University Logic Design. 2 Overview of Logic Design Seoul National University Fundamental Hardware Requirements  Computation  Storage.
Chapter 4: Processor Architecture How does the hardware execute the instructions? We’ll see by studying an example system  Based on simple instruction.
Assembly תרגול 5 תכנות באסמבלי. Assembly vs. Higher level languages There are NO variables’ type definitions.  All kinds of data are stored in the same.
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.
Architecture (I) Processor Architecture. – 2 – Processor Goal Understand basic computer organization Instruction set architecture Deeply explore the CPU.
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 ~
Machine-level Programming III: Procedures Topics –IA32 stack discipline –Register saving conventions –Creating pointers to local variables.
CS:APP3e CS:APP Chapter 4 Computer Architecture Logic Design CS:APP Chapter 4 Computer Architecture Logic Design CENG331 - Computer Organization Murat.
Chapter 4: Processor Architecture
Computer Architecture
University of Amsterdam Computer Systems – the instruction set architecture Arnoud Visser 1 Computer Systems The instruction set architecture.
Abstraction. Not real, not concrete A view that is removed from the reality Definitely has a "base" in reality – the "base" may be non-intuitive and not.
CPSC 121: Models of Computation
CPSC 121: Models of Computation
Reading Condition Codes (Cont.)
Machine-Level Programming 2 Control Flow
Instruction Set Architecture
Lecture 12 Logic Design Review & HCL & Bomb Lab
Seoul National University
Ch. 2 Two’s Complement Boolean vs. Logical Floating Point
Computer Architecture adapted by Jason Fritts then by David Ferry
asum.ys A Y86 Programming Example
Y86 Processor State Program Registers
Machine-Level Programming 4 Procedures
Instruction Decoding Optional icode ifun valC Instruction Format
Condition Codes Single Bit Registers
C Prog. To Object Code text text binary binary Code in files p1.c p2.c
Machine-Level Programming 2 Control Flow
Systems I Pipelining II
Assembly Language Programming II: C Compiler Calling Sequences
Machine-Level Programming 2 Control Flow
Machine-Level Programming III: Procedures Sept 18, 2001
Machine-Level Programming 2 Control Flow
Pipelined Implementation : Part I
Introduction to Computer System
Recap: Performance Comparison
Machine-Level Programming: Introduction
Systems I Pipelining II
Chapter 4 Processor Architecture
Systems I Pipelining II
Introduction to Computer System
Introduction to the Architecture of Computers
Sequential Design תרגול 10.
Presentation transcript:

1 Processor Architecture

2 Topics Write Y86 code Basic Logic design Hardware Control Language HCL Suggested Reading: 4.1, 4.2

Writing Y86 Code Try to Use C Compiler as Much as Possible –Write code in C –Compile for IA32 with gcc –O1 –S Newer versions of GCC do too much optimization Use ls /usr/bin/gcc * to find what versions are available –Transliterate into Y86 Coding Example –Find number of elements in null-terminated list int len1(int a[]); a  3 3

Y86 Code Generation Example First Try –Write typical array code –Compile with gcc –O1 -S Problem –Hard to do array indexing on Y86 Since don’t have scaled addressing modes /* Find number of elements in null-terminated list */ int len1(int a[]) { int len; for (len = 0; a[len]; len++) ; return len; } L5: incl %eax cmpl $0, (%edx,%eax,4) jneL5 4

Y86 Code Generation Example #2 Second Try –Write with pointer code –Compile with gcc34 –O1 -S Result –Don’t need to do indexed addressing /* Find number of elements in null-terminated list */ int len2(int a[]) { int len = 0; while (*a++) len++; return len; }.L11: incl%ecx movl(%edx), %eax addl$4, %edx testl%eax, %eax jne.L11 5

Y86 Code Generation Example #3 IA32 Code –Setup Y86 Code –Setup len2: pushl %ebp movl %esp, %ebp movl 8(%ebp), %edx movl $0, %ecx movl (%edx), %eax addl $4, %edx testl %eax, %eax je.L13 len2: pushl %ebp# Save %ebp rrmovl %esp, %ebp# New FP pushl %esi # Save irmovl $4, %esi# Constant 4 pushl %edi# Save irmovl $1, %edi# Constant 1 mrmovl 8(%ebp), %edx# Get a irmovl $0, %ecx# len = 0 mrmovl (%edx), %eax# Get *a addl %esi, %edx# a++ andl %eax, %eax# Test *a je Done # If zero, goto Done Need constants 1 & 4 Store in callee-save registers Use andl to test register 6

Y86 Code Generation Example #4 IA32 Code –Loop Y86 Code –Loop.L11: incl %ecx movl (%edx), %eax addl $4, %edx testl %eax, %eax jne.L11 Loop: addl %edi, %ecx# len++ mrmovl (%edx), %eax# Get *a addl %esi, %edx# a++ andl %eax, %eax# Test *a jne Loop # If !0, goto Loop 7

Y86 Code Generation Example #5 IA32 Code –Finish Y86 Code –Finish.L13: movl %ecx, %eax leave ret Done: rrmovl %ecx, %eax# return len popl %edi # Restore %edi popl %esi # Restore %esi rrmovl %ebp, %esp # Restore SP popl %ebp # Restore FP ret 8

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

Y86 Program Structure #2 –Program starts at address 0 –Must set up stack –Must initialize data –Can use symbolic names init: irmovl Stack, %esp # Set up SP irmovl Stack, %ebp # Set up FP call Main # Execute main halt # Terminate # Array of 4 elements + terminating 0.align 4 array:.long 0x000d.long 0x00c0.long 0x0b00.long 0xa000.long 0 10

Y86 Program Structure #3 Set up call to len2 –Follow IA32 procedure conventions –Push array address as argument Main: pushl %ebp rrmovl %esp,%ebp irmovl array,%edx pushl %edx # Push array call len2# Call len2(array) rrmovl %ebp,%esp popl %ebp ret 11

Assembling Y86 Program –Generates “object code” file len.yo Actually looks like disassembler output unix> yas len.ys 0x000: |.pos 0 0x000: 30f | init:irmovl Stack, %esp # Set up stack pointer 0x006: 30f | irmovl Stack, %ebp # Set up base pointer 0x00c: | call Main# Execute main program 0x011: 00 | halt# Terminate program | | # Array of 4 elements + terminating 0 0x014: |.align 4 0x014: | array: 0x014: 0d |.long 0x000d 0x018: c |.long 0x00c0 0x01c: 000b0000 |.long 0x0b00 0x020: 00a00000 |.long 0xa000 0x024: |.long 0 12

Simulating Y86 Program –Instruction set simulator Computes effect of each instruction on processor state Prints changes in state from original unix> yis len.yo Stopped in 50 steps at PC = 0x11. Status 'HLT', CC Z=1 S=0 O=0 Changes to registers: %eax:0x x %ecx:0x x %edx:0x x %esp:0x x %ebp:0x x Changes to memory: 0x00ec:0x x000000f8 0x00f0:0x x x00f4:0x x x00f8:0x x x00fc:0x x

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 14

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

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 Store bits of information 16

Digital Signals –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 Voltage Time

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 18

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

Category of Digital Circuit Combinational Circuit –Without memory. So the circuit is stateless. The same input always gets the same output at any time. –Needn’t clock signal –Typical application: ALU 20

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 21

Computing with Logic Gates –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 Voltage Time a b a && b Rising Delay Falling Delay 22

Combinational Circuits Acyclic Network of Logic Gates –Continously responds to changes on inputs –Outputs become (after some delay) Boolean functions of inputs Acyclic Network InputsOutputs 23

Bit Equality –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 Bit equal a b eq bool eq = (a&&b)||(!a&&!b) HCL Expression 24

Word Equality –32-bit word size –HCL representation Equality operation Generates Boolean value b 31 Bit equal a 31 eq 31 b 30 Bit equal a 30 eq 30 b1b1 Bit equal a1a1 eq 1 b0b0 Bit equal a0a0 eq 0 Eq = = B A Word-Level Representation bool Eq = (A == B) HCL Representation 25

Bit-Level Multiplexor –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 Bit MUX b s a out bool out = (s&&a)||(!s&&b) HCL Expression 26

Word Multiplexor Word-Level Representation s B A Out MUX b 31 s a 31 out 31 b 30 a 30 out 30 b0b0 a0a0 out 0 27 int out = (s&&A)||(!s&&B)

Word Multiplexor HCL Representation –Select input word A or B depending on control signal s –HCL representation Case expression Series of test : value pairs Output value for first successful test int Out = [ s : A; 1 : B; ]; 28

HCL Word-Level Examples Find minimum of three input words HCL case expression Final case guarantees match A Min3 MIN3 B C int Min3 = [ A < B && A < C : A; B < A && B < C : B; 1 : C; ]; Minimum of 3 Words 29

HCL Word-Level Examples D0 D3 Out4 s0 s1 MUX4 D2 D1 Select one of 4 inputs based on two control bits HCL case expression Simplify tests by assuming sequential matching int Out4 = [ !s1&&!s0: D0; !s1 : D1; !s0 : D2; 1 : D3; ]; 4-Way Multiplexor 30

Storage 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 31

Random-Access Memory Stores multiple words of memory –Address input specifies which word to read or write Register file –Holds values of program registers – %eax, %esp, etc. –Register identifier serves as address ID 0xF 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 Register file A B W dstW srcA valA srcB valB valW Read portsWrite port Clock 32

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

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, 32-bit words, … Statements – bool a = bool-expr ; – int A = int-expr ; 34

HCL Operations –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 –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 35

Summary Writing Y86 code –Translate from x86 assembly code Computation –Performed by combinational logic –Computes Boolean functions –Continuously reacts to input changes 36