CS/COE0447: Computer Organization

Similar documents
CS/COE0447: Computer Organization

Five classic components

We are quite familiar with adding two numbers in decimal

Chapter 3 Arithmetic for Computers

Chapter 3: Arithmetic for Computers

NUMBER OPERATIONS. Mahdi Nazm Bojnordi. CS/ECE 3810: Computer Organization. Assistant Professor School of Computing University of Utah

Computer Architecture Set Four. Arithmetic

Chapter Three. Arithmetic

Computer Architecture Chapter 3. Fall 2005 Department of Computer Science Kent State University

ECE260: Fundamentals of Computer Engineering

Lecture 8: Addition, Multiplication & Division

More complicated than addition. Let's look at 3 versions based on grade school algorithm (multiplicand) More time and more area

COMP 303 Computer Architecture Lecture 6

Week 7: Assignment Solutions

Arithmetic for Computers

CS/COE 0447 Example Problems for Exam 2 Spring 2011

CS/COE 0447 Example Problems for Exam 2 Fall 2010

Outline. EEL-4713 Computer Architecture Multipliers and shifters. Deriving requirements of ALU. MIPS arithmetic instructions

COMPUTER ARITHMETIC (Part 1)

ECE 30 Introduction to Computer Engineering

Chapter Two MIPS Arithmetic

Math in MIPS. Subtracting a binary number from another binary number also bears an uncanny resemblance to the way it s done in decimal.

EE 109 Unit 6 Binary Arithmetic

Number Systems and Their Representations

Fast Arithmetic. Philipp Koehn. 19 October 2016

ECE260: Fundamentals of Computer Engineering

Integer Multiplication and Division

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

CS 64 Week 1 Lecture 1. Kyle Dewey

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

Number Systems and Computer Arithmetic

Semester Transition Point. EE 109 Unit 11 Binary Arithmetic. Binary Arithmetic ARITHMETIC

MIPS Integer ALU Requirements

ECE260: Fundamentals of Computer Engineering

Chapter 10 - Computer Arithmetic

The ALU consists of combinational logic. Processes all data in the CPU. ALL von Neuman machines have an ALU loop.

LECTURE 4. Logic Design

Module 2: Computer Arithmetic

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

Computer Organisation CS303

CPS 104 Computer Organization and Programming

Homework 3. Assigned on 02/15 Due time: midnight on 02/21 (1 WEEK only!) B.2 B.11 B.14 (hint: use multiplexors) CSCI 402: Computer Architectures

MULTIPLICATION TECHNIQUES

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

Binary Arithmetic Intro to Assembly Language CS 64: Computer Organization and Design Logic Lecture #3

Computer Architecture and Organization

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

4/8/17. Admin. Assignment 5 BINARY. David Kauchak CS 52 Spring 2017

EEC 483 Computer Organization

Integer Arithmetic. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

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

COMPUTER ORGANIZATION AND DESIGN

Review of Last lecture. Review ALU Design. Designing a Multiplier Shifter Design Review. Booth s algorithm. Today s Outline

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

carry in carry 1101 carry carry

Chapter 2. Positional number systems. 2.1 Signed number representations Signed magnitude

CS 5803 Introduction to High Performance Computer Architecture: Arithmetic Logic Unit. A.R. Hurson 323 CS Building, Missouri S&T

Tailoring the 32-Bit ALU to MIPS

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

Principles of Computer Architecture. Chapter 3: Arithmetic

BINARY SYSTEM. Binary system is used in digital systems because it is:


ECE 341 Midterm Exam

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

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

Advanced Computer Architecture-CS501

Chapter 4. Combinational Logic

Data Representation Type of Data Representation Integers Bits Unsigned 2 s Comp Excess 7 Excess 8

Review: MIPS Organization

Operations, Operands, and Instructions

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

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

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

COMP 122/L Lecture 2. Kyle Dewey

CHW 261: Logic Design

Computer Arithmetic Ch 8

Computer Arithmetic Ch 8

CO Computer Architecture and Programming Languages CAPL. Lecture 9

Signed Multiplication Multiply the positives Negate result if signs of operand are different

Arithmetic Logic Unit

Thomas Polzer Institut für Technische Informatik

Arithmetic and Logical Operations

Organisasi Sistem Komputer

Number Systems. Readings: , Problem: Implement simple pocket calculator Need: Display, adders & subtractors, inputs

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

COMP2611: Computer Organization. Data Representation

Divide: Paper & Pencil

Signed Binary Numbers

Arithmetic Operations

Computer Arithmetic Multiplication & Shift Chapter 3.4 EEC170 FQ 2005

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

Chapter 3. Arithmetic Text: P&H rev

ECE331: Hardware Organization and Design

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

Chapter 10 Binary Arithmetics

Chapter 5 : Computer Arithmetic

Representation of Non Negative Integers

UNIT IV: DATA PATH DESIGN

Slide Set 5. for ENCM 369 Winter 2014 Lecture Section 01. Steve Norman, PhD, PEng

CPE300: Digital System Architecture and Design

Transcription:

Five classic components CS/COE0447: Computer Organization and Assembly Language I am like a control tower I am like a pack of file folders Chapter 3 I am like a conveyor belt + service stations I exchange information with outside world Sangyeun Cho Dept. of Computer Science 2 Binary arithmetic Binary number representations (Sounds scary) So far we studied Instruction ti set architecture t basic MIPS architecture & assembly language We will review binary arithmetic i algorithms and their implementations Binary arithmetic will form the basis for CPU s datapath design We looked at how to represent a number (in fact the value represented by a number) in binary Unsigned numbers everything is positive We will deal with more complicated cases Negative numbers Real numbers (a.k.a. floating-point i t numbers) The first question: How do we represent a negative number in decimal? 3 4

Method 1: sign-magnitude This is the same method we use for decimal numbers {sign bit, absolute value (magnitude)} Sign bit 0 positive, 1 negative Examples, assume 4-bit representation 0000 0 0011 3 1001-1 1111-7 1000? Properties Two 0s a positive 0 and a negative 0? There are equal # of positive and negative numbers Method 2: one s complement ((2 N 1) number) A + (-A) = 2 N 1 Given a number A, it s negation is done by (1111 1111 A) In fact, simple bit-by-bit inversion will give the same-magnitude number with a different sign Examples, assume 4-bit representation 0000 0 0011 3 1001-6 1111-0 1000? Properties There are two 0s There are equal # of positive and negative numbers 5 6 Method 3: two s complement Summary (2 N number) A + (-A) = 2 N Given a number A, it s negation is done by (1111 1111 A) + 1 In fact, simple bit-by-bit inversion followed by adding 1 will give the same-magnitude magnitude number with a different sign Examples, assume 4-bit representation 0000 0 0011 3 1001-7 1111-1 1000? Properties There is a single 0 There are unequal # of positive and negative numbers Code Sign-Magnitude 1 s Complement 2 s Complement 000 +0 +0 +0 001 +1 +1 +1 010 +2 +2 +2 011 +3 +3 +3 100-0 -3-4 101-1 -2-3 110-2 -1-2 111-3 -0-1 Issues # of zeros Balance Arithmetic ti algorithm implementation ti 7 8

When N = 32 Two s complement operations If we use the two s complement method 0000 0000 0000 0000 0000 0000 0000 0000 = 0 0000 0000 0000 0000 0000 0000 0000 0001 = +1 0000 0000 0000 0000 0000 0000 0000 0010 = +2 0111 1111 1111 1111 1111 1111 1111 1110 = +2,147,483,646 0111 1111 1111 1111 1111 1111 1111 1111 = +2,147,483,647 1000 0000 0000 0000 0000 0000 0000 0000 = - 2,147,483,648 483 1000 0000 0000 0000 0000 0000 0000 0001 = - 2,147,483,647 1000 0000 0000 0000 0000 0000 0000 0010 = - 2,147,483,646 1111 1111 1111 1111 1111 1111 1111 1101 = - 3 1111 1111 1111 1111 1111 1111 1111 1110 = - 2 1111 1111 1111 1111 1111 1111 1111 1111 = - 1 Negating g Invert all bits and add 1 This operation is equivalent to subtracting the number from 2 N (why?) Converting an N-bit number into an M-bit number, M>N E.g., MIPS 16-bit immediate (it s a signed number) converted into a 32-bit number This operation is called sign-extension E.g., from 4-bit encoding to 8-bit encoding 0010 0000 0010 1010 1111 1010 What is zero-extension? extension? 9 10 Addition Overflow We are quite familiar with adding two numbers in decimal What about adding two binary numbers? If we use the two s complement method to represent binary numbers, addition can be done in a straightforward way Examples (4-bit representation) 0010 (2) + 0011 (3) = 0101 (5) 1111 (-1) + 0100 (4) = 0011 (3) 0111 (7) + 0010 (2) = 1001 (-7) Let s talk about overflow now Because we use a limited number of digits to represent a number, the result of an operation may not fit No overflow when We add two numbers with different signs We subtract a number from another number having the same sign Overflow detection Adding two positive numbers yields a negative number Adding two negative numbers yields a positive number How about subtraction? 11 12

What happens on overflow? MIPS example The CPU can Generate an exception (what is an exception?) Set a flag in the status register (what is the status register?) Do nothing Languages may have different notions about overflow I looked at the MIPS32 instruction set manual ADD, ADDI instructions generate an exception on overflow ADDU, ADDIU are silent Do we have overflows in the case of unsigned, always positive numbers? Example: addu, addiu, subu 13 14 C language example Subtraction We know how to add We know how to negate a number We will use the above two known operations to perform subtraction A B = A + (-B) The hardware used for addition can be extended to handle subtraction! 15 16

1-bit adder N-bit adder We will look at a single-bit adder Will build on this adder to design a 32-bit adder 3 inputs A: 1 st input B: 2 nd input C in : carry input 2 outputs S: sum C out : carry out An N-bit adder can be constructed with N single-bit adders A carry out generated in a stage is 3 inputs propagated to the next ( ripple-carry adder A: N-bit, 1 st input B: N-bit, 2 nd input C in : carry input 2 outputs S: N-bit sum C out : carry out 17 18 N-bit ripple-carry adder Describing a single-bit adder A truth table will tell us about the operation of a single-bit adder (0) Input Output A B C in C out S carry in at each stage 0 0 0 0 0 0 0 1 0 1 0 1 0 0 1 (0) (1) (1) (0) (0) 0 1 1 1 0 0 0 1 1 1 0 0 1 1 0 1 0 0 0 1 1 0 1 1 0 1 1 0 1 0 1 1 1 1 1 (0) 0 (0) 1 (1) 1 (1) 0 (0) 1 carry out at each stage 19 20

Multiplication Straightforward algorithm More complicated than addition A straightforward implementation will involve addition and shifting x 01010010 (multiplicand) 01101101 (multiplier) A more complex operation implies More area (on silicon) and/or More time (more clock cycles or longer clock cycle time) Let s begin from a simple, straightforward method For now, consider only unsigned numbers! 21 22 Hardware design 1 Hardware design 2 64-bit ALU 64-bit 32-bit 32-bit ALU 64-bit 32-bit Straightforward but naïve design 32-bit ALU instead of 64-bit ALU! 23 24

Hardware design 3 Example 32-bit ALU Let s do 0010 0110 (2 6), unsigned 64-bit Iteration Multiplicand Implementation 3 Step Product 0 0010 initial values 0000 0110 1 0010 1: 0 -> no op 0000 0110 2: shift right 0000 0011 2 0010 1: 1 -> product = product + multiplicand 0010 0011 2: shift right 0001 0001 3 0010 1: 1 -> product = product + multiplicand 0011 0001 2: shift right 0001 1000 Removed a 32-bit! 4 0010 1: 0 -> no op 0001 1000 2: shift right 0000 1100 25 26 Booth s encoding Booth s encoding Three symbols to represent a binary number: {1,0,-1} Examples (8-bit encoding) -1 14 11111111 (two s complement) 0000000-1 (Booth s encoding) 00001110 (two s complement) 000100-10 (Booth s encoding) Bit transitions in number (in two s complement encoding) show how Booth s encoding works 0 to 0 (from right to left): 0 0 to 1: -1 1 to 1: 0 1 to 0: 1 Key ypoint A 1 in he multiplier implies an addition operation If you have many 1 s that means many addition operations Booth s encoding is useful because it can reduce the number of addition operations you have to perform With Booth s encoding, partial results are obtained by Adding multiplicand Adding 0 Subtracting multiplicand 27 28

Booth s algorithm in action Booth s algorithm in action Let s do 0010 1101 (2-3) Iteration Multiplicand Step Booth s algorithm Product Iteration Multiplicand Booth s algorithm Step Product 0 1 0 0010 initial values 0000 1101 0 1 0010 2 0010 10 -> product = product multiplicand 1110 1101 0 shift right 1111 0110 1 01 -> product = product + multiplicand 0001 0110 1 shift right 0000 1011 0 2 3 4 3 0010 10 -> product= product multiplicand 1110 1011 0 shift right 1111 0101 1 5 4 0010 11 -> no op 1111 0101 1 shift right 1111 1010 1 6 29 30