CSC 220: Computer Organization Unit 10 Arithmetic-logic units

Similar documents
Arithmetic-logic units

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

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

(Refer Slide Time 6:48)

CS 24: INTRODUCTION TO. Spring 2015 Lecture 2 COMPUTING SYSTEMS

ALU Design. 1-bit Full Adder 4-bit Arithmetic circuits. Arithmetic and Logic Unit Flags. Add/Subtract/Increament/Decrement Circuit

EXPERIMENT #8: BINARY ARITHMETIC OPERATIONS

Addition and multiplication

Register Transfer Language and Microoperations (Part 2)

Arithmetic Circuits. Design of Digital Circuits 2014 Srdjan Capkun Frank K. Gürkaynak.

Binary Adders: Half Adders and Full Adders

Lecture 7: Primitive Recursion is Turing Computable. Michael Beeson

Arithmetic Logic Unit (ALU)

REGISTER TRANSFER LANGUAGE

Chapter 3: part 3 Binary Subtraction

Chapter 4. Operations on Data

For Example: P: LOAD 5 R0. The command given here is used to load a data 5 to the register R0.

CS 31: Intro to Systems Digital Logic. Kevin Webb Swarthmore College February 3, 2015

Basic operators, Arithmetic, Relational, Bitwise, Logical, Assignment, Conditional operators. JAVA Standard Edition

CS 31: Intro to Systems Digital Logic. Kevin Webb Swarthmore College February 2, 2016

6.1 Combinational Circuits. George Boole ( ) Claude Shannon ( )

4 Operations On Data 4.1. Foundations of Computer Science Cengage Learning

Lecture 6: Signed Numbers & Arithmetic Circuits. BCD (Binary Coded Decimal) Points Addressed in this Lecture

Lecture 10: Combinational Circuits

COMPUTER ARCHITECTURE AND ORGANIZATION Register Transfer and Micro-operations 1. Introduction A digital system is an interconnection of digital

Lecture 21: Combinational Circuits. Integrated Circuits. Integrated Circuits, cont. Integrated Circuits Combinational Circuits

UNCA CSCI 255 Exam 1 Spring February, This is a closed book and closed notes exam. It is to be turned in by 1:45 PM.

ECE 550D Fundamentals of Computer Systems and Engineering. Fall 2017

CSC 220: Computer Organization Unit 12 CPU programming

CS 261 Fall Mike Lam, Professor. Combinational Circuits

BUILDING BLOCKS OF A BASIC MICROPROCESSOR. Part 1 PowerPoint Format of Lecture 3 of Book

Let s put together a Manual Processor

CT 229. Java Syntax 26/09/2006 CT229

Chapter 4 Arithmetic Functions

6.1 Combinational Circuits. George Boole ( ) Claude Shannon ( )

Review. Pipeline big-delay CL for faster clock Finite State Machines extremely useful You ll see them again in 150, 152 & 164

CS140 Lecture 03: The Machinery of Computation: Combinational Logic

REGISTER TRANSFER AND MICROOPERATIONS

ECE468 Computer Organization & Architecture. The Design Process & ALU Design

LECTURE 4. Logic Design

C++ Data Types. 1 Simple C++ Data Types 2. 3 Numeric Types Integers (whole numbers) Decimal Numbers... 5

Chapter 4. Combinational Logic

Number Systems and Computer Arithmetic

Week 6: Processor Components

Boolean Arithmetic. From Nand to Tetris Building a Modern Computer from First Principles. Chapter 2

Parallel logic circuits

Computer Architecture and Organization: L04: Micro-operations

Arithmetic Circuits. Nurul Hazlina Adder 2. Multiplier 3. Arithmetic Logic Unit (ALU) 4. HDL for Arithmetic Circuit

Review: Standard forms of expressions

IA Digital Electronics - Supervision I

ECE2029: Introduction to Digital Circuit Design Lab 3 Implementing a 4-bit Four Function ALU

Advanced Computer Architecture-CS501

CPU Design John D. Carpinelli, All Rights Reserved 1

Contents. Chapter 9 Datapaths Page 1 of 28

EE577A FINAL PROJECT REPORT Design of a General Purpose CPU

Lecture Set 4: More About Methods and More About Operators

5 Arithmetic Logic Unit

CHAPTER 4: Register Transfer Language and Microoperations

Tailoring the 32-Bit ALU to MIPS

UNIT-III REGISTER TRANSFER LANGUAGE AND DESIGN OF CONTROL UNIT

COMBINATIONAL LOGIC CIRCUITS

EGC221: Digital Logic Lab

cis20.1 design and implementation of software applications I fall 2007 lecture # I.2 topics: introduction to java, part 1

GC03 Boolean Algebra

Submitted by 1

Circuit analysis summary

Arithmetic and Bitwise Operations on Binary Data

Music. Numbers correspond to course weeks EULA ESE150 Spring click OK Based on slides DeHon 1

4 Operations On Data 4.1. Foundations of Computer Science Cengage Learning

Le L c e t c ur u e e 2 To T p o i p c i s c t o o b e b e co c v o e v r e ed e Variables Operators

CS101 Lecture 25: The Machinery of Computation: Computer Architecture. John Magee 29 July 2013 Some material copyright Jones and Bartlett

Computer Science 324 Computer Architecture Mount Holyoke College Fall Topic Notes: Data Paths and Microprogramming

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

Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal

CARLETON UNIVERSITY. Laboratory 2.0

ESE534 Computer Organization. Previously. Today. Spatial Programmable. Spatially Programmable. Needs?

1 /10 2 /12 3 /16 4 /30 5 /12 6 /20

Topic Notes: Bits and Bytes and Numbers

Decisions, Decisions. Testing, testing C H A P T E R 7

structure syntax different levels of abstraction

Here is a list of lecture objectives. They are provided for you to reflect on what you are supposed to learn, rather than an introduction to this

Standard Forms of Expression. Minterms and Maxterms

Lecture Set 4: More About Methods and More About Operators

EE 231 Fall EE 231 Lab 3. Decoders and Multiplexers. Figure 1: 7-Segment Display. Memory: where the program is stored.

Register Transfer and Micro-operations

CS61C : Machine Structures

Topic Notes: Bits and Bytes and Numbers

The Arithmetic Operators. Unary Operators. Relational Operators. Examples of use of ++ and

The Arithmetic Operators

2/5/2018. Expressions are Used to Perform Calculations. ECE 220: Computer Systems & Programming. Our Class Focuses on Four Types of Operator in C

Basic circuit analysis and design. Circuit analysis. Write algebraic expressions or make a truth table

Computer Organization and Levels of Abstraction

(+A) + ( B) + (A B) (B A) + (A B) ( A) + (+ B) (A B) + (B A) + (A B) (+ A) (+ B) + (A - B) (B A) + (A B) ( A) ( B) (A B) + (B A) + (A B)

Boolean Unit (The obvious way)

S1 Teknik Telekomunikasi Fakultas Teknik Elektro FEH2H3 2016/2017

ESE 150 Lab 07: Digital Logic

Combinational and sequential circuits (learned in Chapters 1 and 2) can be used to create simple digital systems.

CS61C : Machine Structures

Expressions and Data Types CSC 121 Fall 2015 Howard Rosenthal

CS 261 Fall Mike Lam, Professor. Logic Gates

Transcription:

College of Computer and Information Sciences Department of Computer Science CSC 220: Computer Organization Unit 10 Arithmetic-logic units 1

Remember: 2

Arithmetic-logic units An arithmetic-logic unit, or ALU, performs many different arithmetic and logic operations. The ALU is the heart of a processor you could say that everything else in the CPU is there to support the ALU. Here s the plan: We ll show an arithmetic unit first, by building off ideas from the adder-subtractor circuit. Then we ll talk about logic operations a bit, and build a logic unit. Finally, we put these pieces together using multiplexers. We show the same examples as from the book. 3

The four-bit adder The basic four-bit adder always computes S = A + B + CI. But by changing what goes into the adder inputs A, B and CI, we can change the adder output S. This is also what we did to build the combined adder-subtractor circuit. 4

It s the adder-subtractor again! Here the signal Sub and some XOR gates alter the adder inputs. When Sub = 0, the adder inputs A, B, CI are Y, X, 0, so the adder produces G = X + Y + 0, or just X + Y. When Sub = 1, the adder inputs are Y, X and 1, so the adder output is G = X + Y + 1, or the two s complement operation X - Y. 5

The multi-talented adder So we have one adder performing two separate functions. Sub acts like a function select input which determines whether the circuit performs addition or subtraction. Circuit-wise, all Sub does is modify the adder s inputs A and CI. 6

Modifying the adder inputs By following the same approach, we can use an adder to compute other functions as well. We just have to figure out which functions we want, and then put the right circuitry into the Input Logic box. 7

Some more possible functions We already saw how to set adder inputs A, B and CI to compute either X + Y or X - Y. How can we produce the increment function G = X + 1? One way: Set A = 0000, B = X, and CI = 1 How about decrement: G = X - 1? A = 1111 (- 1 ), B = X, CI = 0 How about transfer: G = X? (This can be useful.) A = 0000, B = X, CI = 0 This is almost the same as the increment function! 8

The role of CI The transfer and increment operations have the same A and B inputs, and differ only in the CI input. In general we can get additional functions (not all of them useful) by using both CI = 0 and CI = 1. Another example: Two s-complement subtraction is obtained by setting A = Y, B = X, and CI = 1, so G = X + Y + 1. If we keep A = Y and B = X, but set CI to 0, we get G = X + Y. This turns out to be a ones complement subtraction operation. 9

Table of arithmetic functions Here are some of the different possible arithmetic operations. We ll need some way to specify which function we re interested in, so we ve randomly assigned a selection code to each operation. G 10

Mapping the table to an adder This second table shows what the adder s inputs should be for each of our eight desired arithmetic operations. Selection code Desired arithmetic operation Required adder inputs S 2 S 1 S 0 G (A + B + CI) A B CI 0 0 0 X (transfer) 0000 X 0 0 0 1 X + 1 (increment) 0000 X 1 0 1 0 X + Y (add) Y X 0 0 1 1 X + Y + 1 Y X 1 1 0 0 X + Y (1C subtraction) Y X 0 1 0 1 X + Y + 1 (2C subtraction) Y X 1 1 1 0 X 1 (decrement) 1111 X 0 1 1 1 X (transfer) 1111 X 1 Adder input CI is always the same as selection code bit S 0. B is always set to X. A depends only on S 2 and S 1. These equations depend on both the desired operations and the assignment of selection codes. 11

Building the input logic All we need to do is compute the adder input A, given the arithmetic unit input Y and the function select code S (actually just S 2 and S 1 ). Here is an abbreviated truth table: inputs output S 2 S 1 A 0 0 0000 0 1 Y 1 0 Y 1 1 1111 S 2 S 1 Y i A i 0 0 0 0 0 0 1 0 0 1 0 0 0 1 1 1 1 0 0 1 1 0 1 0 1 1 0 1 1 1 1 1 We want to pick one of these four possible values for A, depending on S 2 and S 1. 12

Primitive gate-based input logic We could build this circuit using primitive gates. If we want to use K-maps for simplification, then we should first expand out the abbreviated truth table. The Y that appears in the output column (A) is actually an input. We make that explicit in the table on the right. Remember A and Y are each 4 bits long! inputs output S 2 S 1 A 0 0 0000 0 1 Y 1 0 Y 1 1 1111 S 2 S 1 Y i A i 0 0 0 0 0 0 1 0 0 1 0 0 0 1 1 1 1 0 0 1 1 0 1 0 1 1 0 1 1 1 1 1 13

Primitive gate implementation From the truth table, we can find an MSP: S 1 0 0 1 0 S 2 1 0 1 1 Y i A i = S 2 Y i + S 1 Y i Again, we have to repeat this once for each bit Y3-Y0, connecting to the adder inputs A3-A0. This completes our arithmetic unit. 14

15

16

Bitwise operations Most computers also support logical operations like AND, OR and NOT, but extended to multi-bit words instead of just single bits. To apply a logical operation to two words X and Y, apply the operation on each pair of bits X i and Y i : 1 0 1 1 AND 1 1 1 0 1 0 1 0 1 0 1 1 OR 1 1 1 0 1 1 1 1 1 0 1 1 XOR 1 1 1 0 0 1 0 1 We ve already seen this informally in two s-complement arithmetic, when we talked about complementing all the bits in a number. 17

Bitwise operations in programming Languages like C, C++ and Java provide bitwise logical operations: & (AND) (OR) ^ (XOR) ~ (NOT) These operations treat each integer as a bunch of individual bits: 13 & 25 = 9 because 01101 & 11001 = 01001 They are not the same as the operators &&, and!, which treat each integer as a single logical value (0 is false, everything else is true): 13 && 25 = 1 because true && true = true Bitwise operators are often used in programs to set a bunch of Boolean options, or flags, with one argument. Easy to represent sets of fixed universe size with bits: 1: is member, 0 not a member. Unions: OR, Intersections: AND 18

Defining a logic unit A logic unit supports different logical functions on two multi-bit inputs X and Y, producing an output G. This abbreviated table shows four possible functions and assigns a selection code S to each. S 1 S 0 Output 0 0 G i = X i Y i 0 1 G i = X i + Y i 1 0 G i = X i Y i 1 1 G i = X i We ll just use multiplexers and some primitive gates to implement this. Again, we need one multiplexer for each bit of X and Y. 19

Our simple logic unit Inputs: X (4 bits) Y (4 bits) S (2 bits) Outputs: G (4 bits) 20

Combining the arithmetic and logic units Now we have two pieces of the puzzle: An arithmetic unit that can compute eight functions on 4-bit inputs. A logic unit that can perform four functions on 4-bit inputs. We can combine these together into a single circuit, an arithmetic-logic unit (ALU). 21

Our ALU function table This table shows a sample function table for an ALU. All of the arithmetic operations have S 3 =0, and all of the logical operations have S 3 =1. These are the same functions we saw when we built our arithmetic and logic units a few minutes ago. Since our ALU only has 4 logical operations, we don t need S 2. The operation done by the logic unit depends only on S 1 and S 0. S 3 S 2 S 1 S 0 Operation 0 0 0 0 G = X 0 0 0 1 G = X + 1 0 0 1 0 G = X + Y 0 0 1 1 G = X + Y + 1 0 1 0 0 G = X + Y 0 1 0 1 G = X + Y + 1 0 1 1 0 G = X 1 0 1 1 1 G = X 1 x 0 0 G = X and Y 1 x 0 1 G = X or Y 1 x 1 0 G = X Y 1 x 1 1 G = X 22

A complete ALU circuit The / and 4 on a line indicate that it s actually four lines. 4 4 4 C out should be ignored when logic operations are performed (when S3=1). 4 4 The arithmetic and logic units share the select inputs S1 and S0, but only the arithmetic unit uses S2. G is the final ALU output. When S3 = 0, the final output comes from the arithmetic unit. When S3 = 1, the output comes from the logic unit. 23

Comments on the multiplexer Both the arithmetic unit and the logic unit are active and produce outputs. The mux determines whether the final result comes from the arithmetic or logic unit. The output of the other one is effectively ignored. Our hardware scheme may seem like wasted effort, but it s not really. Deactivating one or the other wouldn t save that much time. We have to build hardware for both units anyway, so we might as well run them together. This is a very common use of multiplexers in logic design. 24

The completed ALU This ALU is a good example of hierarchical design. With the 12 inputs, the truth table would have had 2 12 = 4096 lines. That s an awful lot of paper. Instead, we were able to use components that we ve seen before to construct the entire circuit from a couple of easy-to-understand components. As always, we encapsulate the complete circuit in a black box so we can reuse it in fancier circuits. 4 4 4 4 25