MIPS ALU. Building from the adder to ALU ALU – Arithmetic Logic Unit, does the major calculations in the computer, including – Add – And – Or – Sub –

Slides:



Advertisements
Similar presentations
Combinational Circuits. Analysis Diagram Designing Combinational Circuits In general we have to do following steps: 1. Problem description 2. Input/output.
Advertisements

EET 1131 Unit 7 Arithmetic Operations and Circuits
Lab 10 : Arithmetic Systems : Adder System Layout: Slide #2 Slide #3 Slide #4 Slide #5 Arithmetic Overflow: 2’s Complement Conversions: 8 Bit Adder/Subtractor.
Mohamed Younis CMCS 411, Computer Architecture 1 CMCS Computer Architecture Lecture 7 Arithmetic Logic Unit February 19,
Kevin Walsh CS 3410, Spring 2010 Computer Science Cornell University Arithmetic See: P&H Chapter 3.1-3, C.5-6.
1 Representing Numbers Using Bases Numbers in base 10 are called decimal numbers, they are composed of 10 numerals ( ספרות ) = 9* * *10.
Computer Structure - The ALU Goal: Build an ALU  The Arithmetic Logic Unit or ALU is the device that performs arithmetic and logical operations in the.
Our ultimate goal: building the datapath
Chap 3.3~3.5 Construction an Arithmetic Logic Unit (ALU) Jen-Chang Liu, Spring 2006.
1 COMP541 Arithmetic Circuits Montek Singh Mar 20, 2007.
COMPUTER ARCHITECTURE & OPERATIONS I Instructor: Hao Ji.
Computer Science 210 Computer Organization The Arithmetic Logic Unit.
Prof. Hakim Weatherspoon CS 3410, Spring 2015 Computer Science Cornell University See: P&H Chapter 2.4, 3.2, B.2, B.5, B.6.
Arithmetic for Computers
1 Bits are just bits (no inherent meaning) — conventions define relationship between bits and numbers Binary numbers (base 2)
Binary Arithmetic Stephen Boyd March 14, Two's Complement Most significant bit represents sign. 0 = positive 1 = negative Positive numbers behave.
1 CHAPTER 4: PART I ARITHMETIC FOR COMPUTERS. 2 The MIPS ALU We’ll be working with the MIPS instruction set architecture –similar to other architectures.
1 Modified from  Modified from 1998 Morgan Kaufmann Publishers Chapter Three: Arithmetic for Computers citation and following credit line is included:
Chapter 6-1 ALU, Adder and Subtractor
07/19/2005 Arithmetic / Logic Unit – ALU Design Presentation F CSE : Introduction to Computer Architecture Slides by Gojko Babić.
Csci 136 Computer Architecture II – Constructing An Arithmetic Logic Unit Xiuzhen Cheng
CPS3340 COMPUTER ARCHITECTURE Fall Semester, /19/2013 Lecture 7: 32-bit ALU, Fast Carry Lookahead Instructor: Ashraf Yaseen DEPARTMENT OF MATH &
Numbers and Arithmetic Hakim Weatherspoon CS 3410, Spring 2013 Computer Science Cornell University See: P&H Chapter , 3.2, C.5 – C.6.
1 Arithmetic Logic Unit ALU. 2 The Bus Concept 3 CPU Building Blocks  Registers (IR, PC, ACC)  Control Unit (CU)  Arithmetic Logic Unit (ALU)
Arithmetic Logic Unit (ALU) Anna Kurek CS 147 Spring 2008.
1 Lecture 6 BOOLEAN ALGEBRA and GATES Building a 32 bit processor PH 3: B.1-B.5.
CDA 3101 Fall 2013 Introduction to Computer Organization The Arithmetic Logic Unit (ALU) and MIPS ALU Support 20 September 2013.
Lecture 18: Hardware for Arithmetic Today’s topic –Intro to Boolean functions (Continued) –Designing an ALU 1.
Ch3b- 2 EE/CS/CPE Computer Organization  Seattle Pacific University There is logic to it andRd, Rs, RtRd
1 Arithmetic I Instructor: Mozafar Bag-Mohammadi Ilam University.
N, Z, C, V in CPSR with Adder & Subtractor Prof. Taeweon Suh Computer Science Education Korea University.
08 ARTH Page 1 ECEn/CS 224 Number Representation and Binary Arithmetic.
The Karnaugh Map.
Kavita Bala CS 3410, Spring 2014 Computer Science Cornell University.
COMP541 Arithmetic Circuits
Chapter 4 Integer Data Representation. Unsigned Integers.
Appendix C Basics of Digital Logic Part I. Florida A & M University - Department of Computer and Information Sciences Modern Computer Digital electronics.
Computer Architecture Lecture 9 MIPS ALU and Data Paths Ralph Grishman Oct NYU.
Addition, Subtraction, Logic Operations and ALU Design
1 Digital Logic Design Lecture 2 More Number Systems/Complements.
ECE 171 Digital Circuits Chapter 2 Binary Arithmetic Herbert G. Mayer, PSU Status 1/14/2016 Copied with Permission from prof. Mark PSU ECE.
Gates AND, OR, NOT NAND, NOR Combinational logic No memory A set of inputs uniquely and unambiguously specifies.
ECEN 248: INTRODUCTION TO DIGITAL SYSTEMS DESIGN Lecture 8 Dr. Shi Dept. of Electrical and Computer Engineering.
Lecture #23: Arithmetic Circuits-1 Arithmetic Circuits (Part I) Randy H. Katz University of California, Berkeley Fall 2005.
Computer Arthmetic Chapter Four P&H. Data Representation Why do we not encode numbers as strings of ASCII digits inside computers? What is overflow when.
MIPS ALU. Exercise – Design a selector? I need a circuit that takes two input bits, a and b, and a selector bit s. The function is that if s=0, f=a. if.
Simple ALU  Half adder  Full adder  Constructing 4 bits adder  ALU does several operations  General ALU structure  Timing diagram of adder  Overflow.
9/23/2004Comp 120 Fall September Chapter 4 – Arithmetic and its implementation Assignments 5,6 and 7 posted to the class web page.
EE204 L03-ALUHina Anwar Khan EE204 Computer Architecture Lecture 03- ALU.
Computer Engineering page 1 Integer arithmetic Depends what you mean by “integer”. Assume at 3-bit string. –Then we define: zero = 000 one = 001 Use zero,
Arithmetic Circuits I. 2 Iterative Combinational Circuits Like a hierachy, except functional blocks per bit.
Combinational Circuits
Prof. Sin-Min Lee Department of Computer Science
Lecture 11: Hardware for Arithmetic
Computer Architecture & Operations I
Computer Science 210 Computer Organization
MIPS ALU.
5. Combinational circuits
King Fahd University of Petroleum and Minerals
MIPS ALU.
Systems Architecture I
Lecture 11: Hardware for Arithmetic
COSC 2021: Computer Organization Instructor: Dr. Amir Asif
COMS 361 Computer Organization
A 1-Bit Arithmetic Logic Unit
Combinational Circuits
COMS 361 Computer Organization
靜夜思 床前明月光, 疑是地上霜。 舉頭望明月, 低頭思故鄉。 ~ 李白 李商隱.
MIPS ALU.
MIPS ALU.
Presentation transcript:

MIPS ALU

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

Review 1-bit full adder

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?

11 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?

12 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.

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.

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

15 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).

16 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, which is clearly wrong

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, overflow.

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.

19 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.

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 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 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.

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

23 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

24 32-bit ALU that Supports Set Less Than

Final 32-Bit ALU

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

27 ALU Symbol

Midterm Statistics