Review. Steps to writing (stateless) circuits: Create a logic function (one per output)

Similar documents
Chapter 3 Arithmetic for Computers

CS/COE 0447 Example Problems for Exam 2 Spring 2011

Basic Arithmetic (adding and subtracting)

LECTURE 4. Logic Design

CPE 335 Computer Organization. MIPS Arithmetic Part I. Content from Chapter 3 and Appendix B

Lecture Topics. Announcements. Today: Integer Arithmetic (P&H ) Next: The MIPS ISA (P&H ) Consulting hours. Milestone #1 (due 1/26)

Computer Architecture Set Four. Arithmetic

Computer Organization and Structure. Bing-Yu Chen National Taiwan University

INF2270 Spring Philipp Häfliger. Lecture 4: Signed Binaries and Arithmetic

4. Write a sum-of-products representation of the following circuit. Y = (A + B + C) (A + B + C)

Chapter 3 Arithmetic for Computers. ELEC 5200/ From P-H slides

CSE 141 Computer Architecture Summer Session Lecture 3 ALU Part 2 Single Cycle CPU Part 1. Pramod V. Argade

Format. 10 multiple choice 8 points each. 1 short answer 20 points. Same basic principals as the midterm

Unsigned Binary Integers

Unsigned Binary Integers

Chapter 3: part 3 Binary Subtraction

60-265: Winter ANSWERS Exercise 4 Combinational Circuit Design

Review 1/2 MIPS assembly language instructions mapped to numbers in 3 formats. CS61C Negative Numbers and Logical Operations R I J.

Review: MIPS Organization

Operations On Data CHAPTER 4. (Solutions to Odd-Numbered Problems) Review Questions

CS/COE0447: Computer Organization

Chapter Two MIPS Arithmetic

CS/COE0447: Computer Organization

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

COMP MIPS instructions 2 Feb. 8, f = g + h i;

Advanced Computer Architecture-CS501

Binary Addition. Add the binary numbers and and show the equivalent decimal addition.

Chapter 3 Arithmetic for Computers (Part 2)

Lets Build a Processor

Register Transfer Level (RTL) Design

361 div.1. Computer Architecture EECS 361 Lecture 7: ALU Design : Division

COMP2611: Computer Organization. Data Representation

Computer Architecture and Organization: L04: Micro-operations

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

UC Berkeley College of Engineering, EECS Department CS61C: Combinational Logic Blocks

UC Berkeley College of Engineering, EECS Department CS61C: Combinational Logic Blocks

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

Digital Electronics & Computer Engineering (E85)

Chapter 4. The Processor

Merging datapaths: (add,lw, sw)

The MIPS Processor Datapath

CSE140: Components and Design Techniques for Digital Systems

Chapter 4. The Processor. Instruction count Determined by ISA and compiler. We will examine two MIPS implementations

To design a 4-bit ALU To experimentally check the operation of the ALU

Part I: Translating & Starting a Program: Compiler, Linker, Assembler, Loader. Lecture 4

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

Introduction. Datapath Basics

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

1010 2?= ?= CS 64 Lecture 2 Data Representation. Decimal Numbers: Base 10. Reading: FLD Digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9

Number System. Introduction. Decimal Numbers

Chapter 4 Arithmetic Functions

The Processor (1) Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

Arithmetic Logic Unit. Digital Computer Design

CO Computer Architecture and Programming Languages CAPL. Lecture 15

ECE260: Fundamentals of Computer Engineering

Levels of Programming. Registers

Review: Abstract Implementation View

ECE331: Hardware Organization and Design

CSCI 402: Computer Architectures

Chapter 4. The Processor

Computer Organization and Levels of Abstraction

CO Computer Architecture and Programming Languages CAPL. Lecture 9

Chapter 3: Arithmetic for Computers

Processor (I) - datapath & control. Hwansoo Han

Binary Adders: Half Adders and Full Adders

Operations, Operands, and Instructions

CENG3420 L05: Arithmetic and Logic Unit

COMPUTER ORGANIZATION AND DESIGN. 5 th Edition. The Hardware/Software Interface. Chapter 3. Arithmetic for Computers

Chapter 5: The Processor: Datapath and Control

Tailoring the 32-Bit ALU to MIPS

LECTURE 5. Single-Cycle Datapath and Control

Chapter 4 The Processor

Number Systems and Computer Arithmetic

ECE260: Fundamentals of Computer Engineering

I-Format Instructions (3/4) Define fields of the following number of bits each: = 32 bits

CAD4 The ALU Fall 2009 Assignment. Description

11. A Computing Machine

CS61C Machine Structures. Lecture 13 - MIPS Instruction Representation I. 9/26/2007 John Wawrzynek. www-inst.eecs.berkeley.

Instructions: MIPS ISA. Chapter 2 Instructions: Language of the Computer 1

CENG 3420 Lecture 05: Arithmetic and Logic Unit

ECE232: Hardware Organization and Design

ECE331: Hardware Organization and Design

ECE260: Fundamentals of Computer Engineering

Systems Architecture

EEM 486: Computer Architecture. Lecture 2. MIPS Instruction Set Architecture

MIPS Integer ALU Requirements

Announcements HW1 is due on this Friday (Sept 12th) Appendix A is very helpful to HW1. Check out system calls

Parallel logic circuits

Chapter 2. Instruction Set. RISC vs. CISC Instruction set. The University of Adelaide, School of Computer Science 18 September 2017

Boolean Algebra. Chapter 3. Boolean Algebra. Chapter 3 Arithmetic for Computers 1. Fundamental Boolean Operations. Arithmetic for Computers

The Processor: Datapath and Control. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

ECE260: Fundamentals of Computer Engineering

Chapter 4. The Processor. Computer Architecture and IC Design Lab

CS101 Lecture 04: Binary Arithmetic

A complement number system is used to represent positive and negative integers. A complement number system is based on a fixed length representation

Chapter 10 Binary Arithmetics

CpE242 Computer Architecture and Engineering Designing a Single Cycle Datapath

CARLETON UNIVERSITY. Laboratory 2.0

Computer Organization and Levels of Abstraction

Learning Log Title: CHAPTER 3: ARITHMETIC PROPERTIES. Date: Lesson: Chapter 3: Arithmetic Properties

Transcription:

MIPS ALU

Review Steps to writing (stateless) circuits: Create a truth table Go through all different combinations of inputs For each row, generate each output based on the problem description Create a logic function (one per output) Use only output rows that are true Use inversion if the input is 0 And all of the inputs on a row Or all of the rows

Review Steps to writing (stateless) circuits: K-map (one per logic function) Split half of your inputs and label them as columns and the other half as rows Make your labels differ by 1 bit across columns/rows Plot true outputs in cells Draw circles around cells in powers of two Minimize number of circles Maximize the size of the circle

Review Steps to writing (stateless) circuits: Recreate logic function (one per K-map) Again, use inversion if the input is a 0 And together the constant (not changing) inputs in a given circle Or together the results from each circle

In-Class Exercise 4-1 Question Assuming that X consists of 3 bits x2, x1, x0 write a logic function that is true if and only if X when interpreted as an unsigned binary integer is less than 4

In-Class Exercise 4-1 Answer X2 X1 X0 O 0 0 0 1 0 0 1 1 0 1 0 1 0 1 1 1 1 0 0 0 1 0 1 0 1 1 0 0 1 1 1 0

In-Class Exercise 4-1 Answer X2 X1 X0 O 0 0 0 1 0 0 1 1 0 1 0 1 0 1 1 1 1 0 0 0 1 0 1 0 1 1 0 0 1 1 1 0 O = X2 X1 X0 + X2 X1 X0 + X2 X1X0 + X2 X1X0

In-Class Exercise 4-1 Answer O = X2 X1 X0 + X2 X1 X0 + X2 X1X0 + X2 X1X0 X2X1 X0 00 01 11 10 0 1 1 1 1 1

In-Class Exercise 4-1 Answer X2X1 X0 00 01 11 10 0 1 1 1 1 1 O = X2

In-Class Exercise 4-2 Question Assuming that X consists of 3 bits x2, x1, x0 write a logic function that is true if and only if X when interpreted as an unsigned binary integer is odd

In-Class Exercise 4-2 Answer X2 X1 X0 O 0 0 0 0 0 0 1 1 0 1 0 0 0 1 1 1 1 0 0 0 1 0 1 1 1 1 0 0 1 1 1 1

In-Class Exercise 4-2 Answer X2 X1 X0 O 0 0 0 0 0 0 1 1 0 1 0 0 0 1 1 1 1 0 0 0 1 0 1 1 1 1 0 0 1 1 1 1 O =X2 X1 X0 + X2 X1X0 + X2X1 X0 + X2X1X0

In-Class Exercise 4-2 Answer O =X2 X1 X0 + X2 X1X0 + X2X1 X0 + X2X1X0 X0 X2X1 00 01 11 10 0 1 1 1 1 1

In-Class Exercise 4-2 Answer X2X1 X0 00 01 11 10 0 1 1 1 1 1 O = X0

Exercise Design a selector? I need a circuit that takes two input bits, a and b, and a selector bit s. The function output, f, is: if s=0, f=a if s=1, f=b.

Selector s a b f 0 0 0 0 0 1 0 1 0 0 1 1 1 0 0 1 0 1 1 1 0 1 1 1

Selector s a b f 0 0 0 0 0 0 1 0 0 1 0 1 0 1 1 1 1 0 0 0 1 0 1 1 1 1 0 0 1 1 1 1

F=s ab +s ab+sa b+sab s 0 1 ab K-map 00 01 11 10 1 1 1 1

F=s ab +s ab+sa b+sab s 0 1 ab K-map 00 01 11 10 1 1 1 1 F=s a+sb

Building from the adder to ALU ALU Arithmetic Logic Unit, does the major calculations in the computer, including Add And Or Sub In MIPS, the ALU takes two 32-bit inputs and produces one 32-bit output, plus some additional signals Add is only one of the functions, and in this lecture, we are going to see how an full ALU is designed

ALU

1-bit full adder Review

32-bit adder

Building 32-bit ALU with 1-bit ALU Build 32-bit ALU with 1-bit ALU. Deal with the easy ones first and and or

And and Or operations And a b And result Or a b Or result

Putting them together Sometimes the instruction is add, sometimes it is or, sometimes is and, how to put them together? In MIPS instructions, there are many fields: op, funct, rs, rt, rd, shamt

Putting them together Just do everything (add, and, or) and then select one AS the output with a selector.

Subtraction? How to implement subtraction?

Subtraction Using two s complement representation, we can implement subtraction through addition The reason is that a negative number -b in 2 s complement is actually 2 n -b. So if you do a+2 n -b and take only the lower n bits, it becomes a-b because 2 n is a one bit at bit n (bit indices are 0,1,2,, n-1, n). What do we need to add to the ALU we have in order to be able to perform subtraction? 29

1-Bit ALU That can Do Subtraction To do a-b, three things: 1. Invert every bit of b. 2. Add 1. 3. Add with a. So, if it is a subtraction, invert the second operand, set the CarryIn of the last one-bit full adder to be 1, then select the adder output. 30

Subtraction Notice that every time we want the ALU to subtract, we set both CarryIn and Binvert to 1. For add or logical operations, we want both control lines to be 0. We can therefore simplify control of the ALU by combining the CarryIn and Binvert to a single control line called Bnegate.

Supporting Branch Instructions We need to be able to test if two numbers are the same 32

Supporting Set Less Than Set less than instruction produces 1 if rs < rt, and 0 otherwise It needs to set all but the least significant bit to 0 The least significant bit is set according to the comparison Which can be done using subtraction That is, do a subtraction, check the sign bit (bit 31). 33

Complication If we only use the sign bit of the adder, sometimes we will be wrong For the following example (using 4 bits only), we have Then we have 7, which is clearly wrong ten 6 ten 34

Overflow The problem is that sometimes we have overflow. If we have only 4 bits, a number greater than 7 or a number less than -8 will cause an overflow because it cannot be represented in 4 bits. In the previous example, -7-6=-13, overflowed.

Dealing with overflow Overflow happens when the two numbers are of the same sign. If they are of different signs, the addition result will be less than the larger one (the absolute value) and should be still within the range, assuming the two original numbers are within the range.

Overflow Detection One way to detect overflow is to check whether the sign bit is consistent with the sign of the inputs when the two inputs are of the same sign if you added two positive numbers and got a negative number, something is wrong, and vice versa. 37

Dealing with overflow For two positive numbers, after the addition, The carryout of ALU31 must be 0, because in 2 s complement, positive numbers go from 000 1 to 011..1. The largest number is 011 1 and adding two 011 1 will lead to 111 10, the carry out is still 0. if no overflow, the sign bit (bit 31) should be 0, because the result is a positive number. If overflowed, the sign bit (bit 31) will be 1, caused by a carryin to ALU31.

Dealing with overflow For two negative numbers, after the addition, The carryout of ALU31 must be 1, because in 2 s complement, negative numbers go from 100 0 to 111..1. Even if you are just adding two 100 0, you will have 1000 00, the carry out is 1. if no overflow, the sign bit (bit 31) should be 1, because the result is a negative number. If overflowed, the sign bit (bit 31) will be 0, caused by having no carryin to ALU31.

Overflow Detection So, we can detect the overflow by checking if the CarryIn and CarryOut of the most significant bit are different 40

Overflow The sign bit is correct if there is no overflow If there is overflow, the sign bit will be wrong and needs to be inverted 41

32-bit ALU that Supports Set Less Than 42

Final 32-Bit ALU

Final 32-Bit ALU ALU control lines are 1-bit Ainvert line, 1-bit Bnegate line, and 2-bit operation lines 44

ALU Symbol 45