Review Topics. Midterm Exam Review Slides

Similar documents
Review Topics. Midterm Exam Review Slides

Midterm Exam Review Slides

Review Topics. Final Exam Review Slides

Copyright The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Review Topics

Computing Layers. Chapter 5 The LC-3

ECE 2030B 1:00pm Computer Engineering Spring problems, 5 pages Exam Two 10 March 2010

Chapter 5 The LC-3. ACKNOWLEDGEMENT: This lecture uses slides prepared by Gregory T. Byrd, North Carolina State University 5-2

Copyright The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Computing Layers

CS/ECE 252: INTRODUCTION TO COMPUTER ENGINEERING UNIVERSITY OF WISCONSIN MADISON. Instructor: Rahul Nayar TAs: Annie Lin, Mohit Verma

Instruction Set Architecture

ECE 2030D Computer Engineering Spring problems, 5 pages Exam Two 8 March 2012

Experimental Methods I

Time: 8:30-10:00 pm (Arrive at 8:15 pm) Location What to bring:

Chapter 2 Bits, Data Types, and Operations

Copyright The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Review Topics. parameter passing, memory model)

Intro. to Computer Architecture Homework 4 CSE 240 Autumn 2005 DUE: Mon. 10 October 2005

Chapter 2 Bits, Data Types, and Operations

CS 2461: Computer Architecture I

Introduction to Computer Engineering. CS/ECE 252, Spring 2017 Rahul Nayar Computer Sciences Department University of Wisconsin Madison

Introduction to Computer Engineering. Chapter 5 The LC-3. Instruction Set Architecture

Chapter 11 Introduction to Programming in C

LC-3 Instruction Set Architecture

Chapter 11 Introduction to Programming in C

COSC121: Computer Systems: Review

COSC121: Computer Systems: Review

The LC3's micro-coded controller ("useq") is nothing more than a finite-state machine (FSM). It has these inputs:

컴퓨터개념및실습. 기말고사 review

Introduction to Computer Engineering. CS/ECE 252, Fall 2016 Prof. Guri Sohi Computer Sciences Department University of Wisconsin Madison

20/08/14. Computer Systems 1. Instruction Processing: FETCH. Instruction Processing: DECODE

Chapter 11 Introduction to Programming in C

EEL 5722C Field-Programmable Gate Array Design

Time (self-scheduled): Location Schedule Your Exam: What to bring:

Copyright The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Computing Layers

LC-3 Instruction Set Architecture. Textbook Chapter 5

ECE 2020B Fundamentals of Digital Design Spring problems, 6 pages Exam Two Solutions 26 February 2014

COMP2611: Computer Organization. Data Representation

ECE 2020B Fundamentals of Digital Design Spring problems, 6 pages Exam Two 26 February 2014

Chapter 10 Memory Model for Program Execution. Problem

Logic, Words, and Integers

Basic Arithmetic (adding and subtracting)

Binary. Hexadecimal BINARY CODED DECIMAL

CS/ECE 252: INTRODUCTION TO COMPUTER ENGINEERING COMPUTER SCIENCES DEPARTMENT UNIVERSITY OF WISCONSIN-MADISON

Digital Logic Design Exercises. Assignment 1

appendix a The LC-3 ISA A.1 Overview

Chapter 11 Introduction to Programming in C

Computer Organisation CS303

Computer Organization and Levels of Abstraction

Number System. Introduction. Decimal Numbers

EE292: Fundamentals of ECE

Chapter 12 Variables and Operators

CHW 261: Logic Design

Trap Vector Table. Interrupt Vector Table. Operating System and Supervisor Stack. Available for User Programs. Device Register Addresses

UNIT 7A Data Representation: Numbers and Text. Digital Data

Computer Organization and Levels of Abstraction

Ch. 5: The LC-3. PC-Relative Addressing Mode. Data Movement Instructions. James Goodman!

CSCI 2121 Computer Organization and Assembly Language PRACTICE QUESTION BANK

! What do we care about? n Fast program execution. n Efficient memory usage. n Avoid memory fragmentation. n Maintain data locality

Register Files. Single Bus Architecture. Register Files. Single Bus Processor. Term Project: using VHDL. Accumulator based architecture

Chapter 1. Digital Systems and Binary Numbers

Name: University of Michigan uniqname: (NOT your student ID number!)

P( Hit 2nd ) = P( Hit 2nd Miss 1st )P( Miss 1st ) = (1/15)(15/16) = 1/16. P( Hit 3rd ) = (1/14) * P( Miss 2nd and 1st ) = (1/14)(14/15)(15/16) = 1/16

CS/ECE 252: INTRODUCTION TO COMPUTER ENGINEERING UNIVERSITY OF WISCONSIN MADISON

Chapter 4. Combinational Logic

The LC-3 Instruction Set Architecture. ISA Overview Operate instructions Data Movement instructions Control Instructions LC-3 data path

11/22/1999 7pm - 9pm. Name: Login Name: Preceptor Name: Precept Number:

1. Prove that if you have tri-state buffers and inverters, you can build any combinational logic circuit. [4]

CS 107 Lecture 2: Bits and Bytes (continued)

ECE 109 Sections 602 to 605 Final exam Fall December, 2007

The type of all data used in a C++ program must be specified

LECTURE 4. Logic Design

DRAM uses a single capacitor to store and a transistor to select. SRAM typically uses 6 transistors.

ECE/CS 252 Fall 2011 Homework 4 (25 points) // Due in Lecture Mon Oct. 17, 2011

M1 Computers and Data

Inf2C - Computer Systems Lecture 2 Data Representation

Chapter 3: part 3 Binary Subtraction

10.1. Unit 10. Signed Representation Systems Binary Arithmetic

Chapter 4: The Building Blocks: Binary Numbers, Boolean Logic, and Gates. Invitation to Computer Science, C++ Version, Third Edition

Microcomputers. Outline. Number Systems and Digital Logic Review

CS/ECE 252: INTRODUCTION TO COMPUTER ENGINEERING UNIVERSITY OF WISCONSIN MADISON

Injntu.com Injntu.com Injntu.com R16

Lecture 2: Number Systems

Introduction to Computer. Chapter 5 The LC-3. Instruction Set Architecture

2.1. Unit 2. Integer Operations (Arithmetic, Overflow, Bitwise Logic, Shifting)

Basic Definition INTEGER DATA. Unsigned Binary and Binary-Coded Decimal. BCD: Binary-Coded Decimal

Chapter 10 Binary Arithmetics

CMPSCI 145 MIDTERM #1 Solution Key. SPRING 2017 March 3, 2017 Professor William T. Verts

VARDHAMAN COLLEGE OF ENGINEERING (AUTONOMOUS) Shamshabad, Hyderabad

Chapter 6 Programming the LC-3

CHAPTER SIX BASIC COMPUTER ORGANIZATION AND DESIGN

ECE 341 Midterm Exam

Instruction : A command to the microprocessor to perform a given task on specified data. Each instruction has two parts

Parallel logic circuits

Lecture Topics. Announcements. Today: Integer Arithmetic (P&H ) Next: continued. Consulting hours. Introduction to Sim. Milestone #1 (due 1/26)

CS 101: Computer Programming and Utilization

Introduction to Computer Science. Homework 1

Kinds Of Data CHAPTER 3 DATA REPRESENTATION. Numbers Are Different! Positional Number Systems. Text. Numbers. Other

Load -- read data from memory to register. Store -- write data from register to memory. Load effective address -- compute address, save in register

CS 265. Computer Architecture. Wei Lu, Ph.D., P.Eng.

Chapter 2 Bits, Data Types, and Operations

P( Hit 2nd ) = P( Hit 2nd Miss 1st )P( Miss 1st ) = (1/15)(15/16) = 1/16. P( Hit 3rd ) = (1/14) * P( Miss 2nd and 1st ) = (1/14)(14/15)(15/16) = 1/16

Transcription:

Review Topics Midterm Exam Review Slides Original slides from Gregory Byrd, North Carolina State University Modified slides by Chris Wilcox, Colorado State University Computer Arithmetic Combinational Logic Finite State Machines C Programming gdb Debugging 2 What can a binary number mean? Interpretations of a 32-bit memory location: 32-bit floating point (IEEE) 32-bit unsigned/signed integer 6-bit unsigned/signed integer (2) 8-bit unsigned/signed bytes (4) ASCII characters (4) RISC instruction Control or status register.jpg..mpg,.mp3.,.avi, 3 Hexadecimal to Binary Conversion Method: Convert hexadecimal digits to binary using table. Question: What is hexadecimal 0xFEBD4570 in binary? F E B D 4 5 7 0 0 0 0 000 00 0 0000 Answer: 0000000000000 Hexadecimal Binary 0 0000 000 2 000 3 00 4 000 5 00 6 00 7 0 8 000 9 00 A 00 B 0 C 00 D 0 E 0 F 4

Binary to Hexadecimal Conversion Method: Group binary digits, convert to hex digits using table. Question: What is binary 0000000000000000 in hexadecimal? 00 0 0 000 000 00 0000 C D E F 2 3 0 Answer: 0xCDEF230 Hexadecimal Binary 0 0000 000 2 000 3 00 4 000 5 00 6 00 7 0 8 000 9 00 A 00 B 0 C 00 D 0 E 0 F 5 Decimal to Binary Conversion Method: Convert decimal to binary with divide by 2, check odd/even. Question: What is decimal 49 in binary? 49 is odd, prepend a 49 / 2 = 24 is even, prepend a 0 0 24 / 2 = 2 is even, prepend a 0 00 2 / 2 = 6 is even, prepend a 0 000 6 / 2 = 3 is odd, prepend a 000 3 / 2 = is odd, prepend a 000 Answer: 000 2 n Decimal 2 0 2 2 2 2 4 2 3 8 2 4 6 2 5 32 2 6 64 2 7 28 2 8 256 2 9 52 2 0 024 6 Binary to Decimal Conversion Method: Convert binary to decimal by multiplying by 2, add if bit set. Question: What is binary 00 in decimal? Start with 0 0 Left bit set, multiply by 2, add Left bit set, multiply by 2, add 3 Left bit clear, multiply by 2 6 Left bit set, multiply by 2, add 3 Left bit clear, multiply by 2 26 Left bit set, multiply by 2, add 53 Answer: 53 2 n Decimal 2 0 2 2 2 2 4 2 3 8 2 4 6 2 5 32 2 6 64 2 7 28 2 8 256 2 9 52 2 0 024 7 Binary to Floating Point Conversion Single-precision IEEE floating point number: 0 0000000000000000000000 sign exponent fraction Sign is number is negative. Exponent field is 0 = 27 27 = 0 (decimal). Fraction is.00000000000 =.5 (decimal). Value = -.5 x 2 (27-27) = -.5 x 2 0 = -.5 8 2

Floating Point to Binary Conversion Value = 6.25 Number is positive sign is 0 Fraction is 0.00 (binary), normalize to.000 * 2 2 Exponent is 2 + 27 = 29 (decimal) = 000000 Single-precision IEEE floating point number: 0 000000 000000000000000000000 sign exponent fraction 9 Hexadecimal to ASCII Conversion Method: Convert values to ASCII by table lookup. Each two (hex) digits is a single character. Question: What is hex 0x4245444 in ASCII? 0x42 = 'B' 0x45 = 'E' 0x4 = 'A' 0x44 = 'D' Answer: BEAD Char ASCII Code Char ASCII Code 'A' 0x4 '0' 0x30 'B' 0x42 '' 0x3 'C' 0x43 '2' 0x32 'D' 0x44 '3' 0x33 'E' 0x45 '4' 0x34 'F' 0x46 '5' 0x35 'G' 0x47 '6' 0x36 0 Computer Arithmetic Signed Integer Representations Binary Number Signed Magnitude s Complement 2 s Complement 0000 0 0 0 000 000 2 2 2 00 3 3 3 000 4 4 4 00 5 5 5 00 6 6 6 0 7 7 7 000-0 -7-8 00 - -6-7 00-2 -5-6 0-3 -4-5 00-4 -3-4 0-5 -2-3 0-6 - -2-7 -0 - Computer Arithmetic 2 s Complement Arithmetic Binary Arithmetic (unsigned integers): 0 0 0 0 0 + 0 0 0 0 0 0 0 0 Hex Equivalent: 0x92 + 0x35 = 0xC7 Decimal Equivalent: 46 + 53 = 99 Binary Arithmetic (signed integers): 0 0 0 0 0 + 0 0 0 0 0 0 0 0 Hex Equivalent: 0x92 + 0x35 = 0xC7 Decimal Equivalent: -0 + 53 = -57 2 3

Computer Arithmetic Bitwise Logical Operations Bitwise AND (&): 0 0 0 0 & 0 0 0 0 0 0 0 0 0 0 Hex Equivalent: 0xF0 & 035 = 0xC0 Bitwise OR ( ): 0 0 0 0 0 0 0 0 0 0 Hex Equivalent: 0xF0 035 = 0xF5 Transistor Basics (p-type and n-type) Gate voltage determines current flow between source and drain. P-type: 0V closes circuit, 2.9V opens circuit. N-type: 2.9V closes circuit, 0V opens circuit. 3 4 Transistor Basics (p-type and n-type) NOT Gate Transistors are switches which have a propagation delay, waveform is not ideal, and voltage transition is not instantaneous! A T T2 B 0 Closed Open Open Closed 0 5 6 4

NOR Gate NAND Gate A B T T2 T3 T4 C 0 0 Closed Closed Open Open 0 Closed Open Open Closed 0 0 Open Closed Closed Open 0 Open Open Closed Closed 0 A B T T2 T3 T4 C 0 0 Open Open Closed Closed 0 Open Closed Closed Open 0 Closed Open Open Closed Closed Closed Open Open 0 7 8 De Morgan s Law Converting AND to OR (with some help from NOT) Consider the following gate: A B A B A B 0 0 0 0 0 0 0 0 0 0 0 0 Same as A OR B! A B To convert AND to OR (or vice versa), invert inputs and output. NOT(NOT(A) AND NOT(B)) = A OR B NOT(NOT(A) OR NOT(B)) = A AND B Logical Completeness. AND/OR/NOT are logically complete, if you have enough gates you can build any truth table. 2. NAND/NOR are logically complete, same as above, so only these gates are sufficient! Proof : Programmable logic array proves that any truth table can be built from AND/OR/NOT. Proof 2: Can synthesize AND/OR/NOT from NAND/NOR, though it may take more gates. 9 20 5

Combinational Logic Combinational Circuit to Truth Table Combinational Logic Truth Table to Combinational Circuit A B C V W X Y Z 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 A B C X Y 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 22 Combinational Logic Decoder Circuit n inputs, 2 n outputs exactly one output is for each input pattern Combinational Logic Multiplexer Circuit n-bit selector and 2 n inputs, one output output equals one of the inputs, depending on selector A B O00 O0 O0 O 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 23 24 6

Combinational Logic Full Adder Circuit Add two bits and carry-in, produce one-bit sum and carry-out. A B C in S C out 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Difference from Combinational Sequential circuits differ from combinational circuits because they have persistent state. For a combinational circuit, the outputs depend only on the inputs. For a sequential circuit, the outputs depend on the inputs and the state. Sequential circuits can be used to implement a finite state machine. 25 26 S-R Latch Circuit Suppose we start with output = 0, then change S to zero (Set), latch state will change to. Or we start with output =, then change R to zero (Reset), latch state will change to 0. Setting S or R back to makes latch quiescent, never do S = R = 0! 0 Output changes to one. 0 0 D-Latch Circuit Two inputs: D (data) and WE (write enable) when WE =, latch is set to value of D S = NOT(D), R = D when WE = 0, latch holds previous value S = R = 0 0 27 28 7

D-Latch Truth Table Exhaustive Testing WE D Previous Q New Q 0 x 0 0 0 x 0 x 0 x How many test cases for combinational logic? 2 n, where n is the number of input bits Example: 4-bit decoder requires 6 test cases How many test cases for sequential logic? 2 n * 2 m, where m is number of states Example: -bit D-latch requires 8 test cases 29 30 - Memory Architecture address write enable word select word WE input bits Memory Address Space and Width Now that we know how to store bits, we can build a memory a logical k m array of stored bits. Address Space: number of locations (usually a power of 2) k = 2 n locations address decoder output bits 3 Address Width (Addressability): number of bits per location (e.g., byte-addressable) m bits 32 8

Finite State Machines Finding States from Inputs Just follow the arrows, for example: Starting state is A Inputs given: 64, 3, 29, 47 States visited: C, D, C, E State outputs: 2, 3, 2, 4 Finite State Machines Finding Inputs from States Just follow the arrows, for example: Starting state is C States visited: E, A, B, A, C Inputs given: 47, 33, 27, 99, 64 Not all paths are possible! 33 34 C Programming Bit Manipulation C Programming Control Structures C code to read or write a bit: int readbit(int value, int bit) { return (value >> bit) & 0; // return!!(value >> bit); } void writebit(int *value, int bit) { *value = <<bit; } C conditional and iterative statements if statement if (value == 0x2345678) printf("value matches 0x2345678\n"); for loop for (int i = 0; i < 8; ++i) printf("i = %d\n", i); while loop int j = 6; while (j--) printf("j = %d\n", j); 35 36 9

C Programming Pointers and Arrays C pointers and arrays void foo(int *pointer) { *(pointer+0) = pointer[2] = 0x234; *(pointer+) = pointer[3] = 0x5678; } int main(int argc, char *argv[]) { int array[]= {0,, 2, 3}; foo(array); for (int i = 0; i <= 3; ++i) printf("array[%d] = %x\n", i, array[i]); } 37 gdb Debugger Basic Commands How to debug a program using gdb: $ gdb a.out // debug a program (gdb) break main // set breakpoint on function (gdb) break 23 // set breakpoint in file (gdb) run (gdb) list 20 (gdb) step (gdb) print v (gdb) print *p (gdb) quit // run program // list current file // single step // display value of variable // deference pointer and display // quit debugger Commands can be single letters (b, r, l, s, p, q) 38 Programming Basics Programming Constructs Task Combinational Logic Storage State Machine True Test False Test Subtask condition condition True Subtask Subtask 2 Subtask 2 Subtask Sequential Conditional Iterative False 39 LC-3 Architecture System Architecture 40 0

Instruction Set (First Half) Instruction Set (Second Half) 4 42 Addressing Modes Load -- read data from memory to register LD: PC-relative mode LDR: base+offset mode LDI: indirect mode Store -- write data from register to memory ST: PC-relative mode STR: base+offset mode STI: indirect mode Load pointer: compute address, save in register LEA: immediate mode does not access memory 43 Machine Code to Assembly What is the assembly code for machine instruction 0000000? Step ) Identify opcode: 00 = AND Step 2) Parse entire instruction (use reference) Step 3) Get values from each field OPCODE DR SR imm5 5:2 :9 8:6 5 4:0 00 00 00 0 AND R2 R2-3 Step 4) Translate to mnemonics: AND R2,R2,#-3 44

Assembly to Machine Code What is the machine code for assembly instruction NOT R7,R6? Step ) Identify opcode: NOT = 00 Step 2) Put values into each field: NOT R7 R6 OPCODE DR SR 5:2 :9 8:6 5:0 00 0 Step 3) Build machine instruction: 000 Assembly Code Syntax.ORIG x3000 MAIN AND R0,R0,#0 ; Initialize Sum JSR COMPUTE ; Call function ST R0, SUM ; Store Sum HALT ; Program complete COMPUTE LD R,OPERAND ; Load Operand LD R2,OPERAND2 ; Load Operand2 ADD R0,R,R2 ; Compute Sum RET ; Function return ;; Input data set OPERAND.FILL x234 ; Operand OPERAND2.FILL x432 ; Operand2 SUM.BLKW ; Sum.END 45 46 2