King Fahd University of Petroleum and Minerals King Fahd University of Petroleum and Minerals Computer Engineering Department Computer Engineering Department.

Slides:



Advertisements
Similar presentations
B261 Systems Architecture
Advertisements

©UCB CPSC 161 Lecture 6 Prof. L.N. Bhuyan
Computer Structure - Computer Arithmetic Goal: Representing Numbers in Binary  Base 10 (decimal) - Numbers are represented using 10 numerals: 0, 1, 2,
CS 61C L02 Number Representation (1)Harvey / Wawrzynek Fall 2003 © UCB 8/27/2003  Brian Harvey ( John Wawrzynek  (Warznek) (
King Fahd University of Petroleum and Minerals
Arithmetic CPSC 321 Computer Architecture Andreas Klappenecker.
Data Representation COE 205
1 Representing Numbers Using Bases Numbers in base 10 are called decimal numbers, they are composed of 10 numerals ( ספרות ) = 9* * *10.
Assembly Language and Computer Architecture Using C++ and Java
Prof. John Nestor ECE Department Lafayette College Easton, Pennsylvania ECE Computer Organization Lecture 6 - Logic &
1  2004 Morgan Kaufmann Publishers Chapter Three.
Integer Multiplication and Division ICS 233 Computer Architecture and Assembly Language Dr. Aiman El-Maleh College of Computer Sciences and Engineering.
CS 61C L02 Number Representation (1) Garcia, Spring 2004 © UCB Lecturer PSOE Dan Garcia inst.eecs.berkeley.edu/~cs61c CS61C.
Assembly Language and Computer Architecture Using C++ and Java
1 Chapter 4: Arithmetic Where we've been: –Performance (seconds, cycles, instructions) –Abstractions: Instruction Set Architecture Assembly Language and.
Integer Multiplication and Division
1 Lecture 8: Binary Multiplication & Division Today’s topics:  Addition/Subtraction  Multiplication  Division Reminder: get started early on assignment.
Arithmetic I CPSC 321 Andreas Klappenecker. Administrative Issues Office hours of TA Praveen Bhojwani: M 1:00pm-3:00pm.
Number Representation (1) Fall 2005 Lecture 12: Number Representation Integers and Computer Arithmetic.
1  1998 Morgan Kaufmann Publishers Chapter Four Arithmetic for Computers.
DIGITAL SYSTEMS TCE1111 Representation and Arithmetic Operations with Signed Numbers Week 6 and 7 (Lecture 1 of 2)
Chapter 3 Arithmetic for Computers. Arithmetic Where we've been: Abstractions: Instruction Set Architecture Assembly Language and Machine Language What's.
Arithmetic for Computers
CSCI-365 Computer Organization Lecture Note: Some slides and/or pictures in the following are adapted from: Computer Organization and Design, Patterson.
CENG 311 Machine Representation/Numbers
1 Bits are just bits (no inherent meaning) — conventions define relationship between bits and numbers Binary numbers (base 2)
CMPE 325 Computer Architecture II Cem Ergün Eastern Mediterranean University Integer Representation and the ALU.
1 CS/COE0447 Computer Organization & Assembly Language Chapter 3.
Computing Systems Basic arithmetic for computers.
Introduction to Computer Engineering ECE/CS 252, Fall 2010 Prof. Mikko Lipasti Department of Electrical and Computer Engineering University of Wisconsin.
1 EGRE 426 Fall 08 Chapter Three. 2 Arithmetic What's up ahead: –Implementing the Architecture 32 operation result a b ALU.
King Fahd University of Petroleum and Minerals King Fahd University of Petroleum and Minerals Computer Engineering Department Computer Engineering Department.
Lecture 2 Binary Values and Number Systems. The number 943 is an example of a number written in positional notation. The relative positions of the digits.
CS Data representation 1 Ch. 2.1 Data Representation Unsigned and Signed Integers – representation, addition, subtraction.
Integer Multiplication and Division
King Fahd University of Petroleum and Minerals King Fahd University of Petroleum and Minerals Computer Engineering Department Computer Engineering Department.
Integer Multiplication and Division ICS 233 Computer Architecture and Assembly Language Dr. Aiman El-Maleh College of Computer Sciences and Engineering.
Digital Representations ME 4611 Binary Representation Only two states (0 and 1) Easy to implement electronically %0= (0) 10 %1= (1) 10 %10= (2) 10 %11=
1 Lecture 7: MARS, Computer Arithmetic Today’s topics:  MARS intro  Numerical representations  Addition and subtraction.
1 ELEN 033 Lecture 4 Chapter 4 of Text (COD2E) Chapters 3 and 4 of Goodman and Miller book.
Addition, Subtraction, Logic Operations and ALU Design
CHAPTER 3 Arithmetic For Computers 1/31/ Topics for discussion 1/31/ Number system: { radix/base, a set of distinct digits, operations} Radix.
CML CML CS 230: Computer Organization and Assembly Language Aviral Shrivastava Department of Computer Science and Engineering School of Computing and Informatics.
순천향대학교 정보기술공학부 이 상 정 1 3. Arithmetic for Computers.
1 Signed Arithmetic Logical Operations Ellen Spertus MCS 111 October 1, 2002.
Lec 11Systems Architecture1 Systems Architecture Lecture 11: Arithmetic for Computers Jeremy R. Johnson Anatole D. Ruslanov William M. Mongan Some or all.
In decimal we are quite familiar with placing a “-” sign in front of a number to denote that it is negative The same is true for binary numbers a computer.
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.
Integer Multiplication and Division COE 301 Computer Organization Dr. Muhamed Mudawar College of Computer Sciences and Engineering King Fahd University.
King Fahd University of Petroleum and Minerals King Fahd University of Petroleum and Minerals Computer Engineering Department Computer Engineering Department.
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.
May 2, 2001System Architecture I1 Systems Architecture I (CS ) Lecture 11: Arithmetic for Computers * Jeremy R. Johnson May 2, 2001 *This lecture.
Data Representation COE 301 Computer Organization Dr. Muhamed Mudawar
By Wannarat Computer System Design Lecture 3 Wannarat Suntiamorntut.
1 CPTR 220 Computer Organization Computer Architecture Assembly Programming.
MIPS Arithmetic and Logic Instructions
Based on slides from D. Patterson and www-inst.eecs.berkeley.edu/~cs152/ COM 249 – Computer Organization and Assembly Language Chapter 3 Arithmetic For.
1 (Based on text: David A. Patterson & John L. Hennessy, Computer Organization and Design: The Hardware/Software Interface, 3 rd Ed., Morgan Kaufmann,
Data Representation COE 308 Computer Architecture
Computer System Design Lecture 3
Computer Arthmetic Chapter Four P&H.
Integer Multiplication and Division
King Fahd University of Petroleum and Minerals
Computer Architecture & Operations I
COMS 361 Computer Organization
MIPS Arithmetic and Logic Instructions
GCSE COMPUTER SCIENCE Topic 3 - Data 3.3 Logical and Arithmetic Shifts.
MIPS Arithmetic and Logic Instructions
Data Representation COE 308 Computer Architecture
Presentation transcript:

King Fahd University of Petroleum and Minerals King Fahd University of Petroleum and Minerals Computer Engineering Department Computer Engineering Department College of Computer Science And Engineering College of Computer Science And Engineering Dr. A. BouhraouaArithmetic for Computers 1 COE 308 Lectures 3: Arithmetic for Computers – Application to the MIPS Architecture

King Fahd University of Petroleum and Minerals King Fahd University of Petroleum and Minerals Computer Engineering Department Computer Engineering Department College of Computer Science And Engineering College of Computer Science And Engineering Dr. A. BouhraouaArithmetic for Computers 2 COE 308 Why Arithmetics Microprocessors perform: –Data Movement –Additions –Subtractions –Logical Operations –Comparisons Arithmetic Operations Understand Arithmetic for the Computer Algorithms Architectures Circuits Goal

King Fahd University of Petroleum and Minerals King Fahd University of Petroleum and Minerals Computer Engineering Department Computer Engineering Department College of Computer Science And Engineering College of Computer Science And Engineering Dr. A. BouhraouaArithmetic for Computers 3 COE 308 Binary Numbers N = d w-1 B w-1 +…+ d i B i + d 1 B 1 +d 0 B 0 Base B is Ten  Decimal Number Base B is Two  Binary Number In MIPS, 32 bits words two = 3 ten two = 21 ten two = 4,294,967,294 ten two =4,294,967,295 ten

King Fahd University of Petroleum and Minerals King Fahd University of Petroleum and Minerals Computer Engineering Department Computer Engineering Department College of Computer Science And Engineering College of Computer Science And Engineering Dr. A. BouhraouaArithmetic for Computers 4 COE 308 ACSII or Decimal vs Binary Numbers Attractive because: Human- Friendly representation Non attractive to computers: –Understand only binary –Binary operations easy to perform –Does not know how to perform operations on ASCII or Decimal number. –Need to convert ASCII/Decimal to binary before and after operation Used only for I/O (User Interface) Use Binary Representation For Internal Computations Convert to/from ASCII for I/O Only

King Fahd University of Petroleum and Minerals King Fahd University of Petroleum and Minerals Computer Engineering Department Computer Engineering Department College of Computer Science And Engineering College of Computer Science And Engineering Dr. A. BouhraouaArithmetic for Computers 5 COE 308 Number Representation Numbers in computers –Just a representation of real numbers –Real numbers have an infinite number of digits 153 ten = … …………………… two = two in a 32 bits word Add, Subtract, Multiply, Divide Result bigger than number of available slots (bits) Overflow

King Fahd University of Petroleum and Minerals King Fahd University of Petroleum and Minerals Computer Engineering Department Computer Engineering Department College of Computer Science And Engineering College of Computer Science And Engineering Dr. A. BouhraouaArithmetic for Computers 6 COE 308 Signed Numbers Subtraction of a big number from small number is a negative number Need for Signed Numbers Representation Intuitive Representation: Sign + Magnitude SignMagnitude Many Shortcomings –Where to put the Sign bit? Left? Right? –Extra step to set the sign for addition and subtraction –Positive and negative 0 leads to programming problems

King Fahd University of Petroleum and Minerals King Fahd University of Petroleum and Minerals Computer Engineering Department Computer Engineering Department College of Computer Science And Engineering College of Computer Science And Engineering Dr. A. BouhraouaArithmetic for Computers 7 COE 308 Two’s Complement What is the result of A – B when B >> A? Will Try to borrow from a string of leading 0s. Result will have a string of leading 1s. Leading 0s: Positive number Leading 1s: Negative number Imbalance between the number of negative numbers and the number of positive numbers –Not a worry anymore. Used by ALL Computers today Easy recognition of positive/negative numbers Easy arithmetics

King Fahd University of Petroleum and Minerals King Fahd University of Petroleum and Minerals Computer Engineering Department Computer Engineering Department College of Computer Science And Engineering College of Computer Science And Engineering Dr. A. BouhraouaArithmetic for Computers 8 COE 308 Negation and Sign Extension Two’s complement negation –Invert all bits of number one by one –Add the value 1 Coming from: x + x = -1 (0 + (-1) = -1) –Means – x = x + 1 Two’s Complement Sign Extension: –Copy the Most Significant Bit to the left Coming from the fact that –Positive numbers have an infinite number of 0s to the left –Negative numbers have an infinite number of 1s to the left

King Fahd University of Petroleum and Minerals King Fahd University of Petroleum and Minerals Computer Engineering Department Computer Engineering Department College of Computer Science And Engineering College of Computer Science And Engineering Dr. A. BouhraouaArithmetic for Computers 9 COE 308 Addition Straight Forward Operation –Adding two number 6 and 7: two = 6 ten two = 7 ten two = 13 ten +=+= (0) 0 (0) 0 (1) 0 (1) 1 (0) (0)0 (0)0 (0)0 (1)1 (1)1 (0)1 … … Overflow can occur MIPS instructions: add, addi, addu, addui

King Fahd University of Petroleum and Minerals King Fahd University of Petroleum and Minerals Computer Engineering Department Computer Engineering Department College of Computer Science And Engineering College of Computer Science And Engineering Dr. A. BouhraouaArithmetic for Computers 10 COE 308 Subtraction Subtract A from B Add A to Two’s Complement of B two = 7 ten two = -6 ten two = 1 ten +=+= Result either >0, 0 or <0 Overflow can occur MIPS instructions: sub, subi, subu, subiu

King Fahd University of Petroleum and Minerals King Fahd University of Petroleum and Minerals Computer Engineering Department Computer Engineering Department College of Computer Science And Engineering College of Computer Science And Engineering Dr. A. BouhraouaArithmetic for Computers 11 COE 308 Overflow Condition Addition is operation between A and B (any sign) Subtraction is addition of two’s complement Overflow in addition/subtraction –33 rd bit set with the value of result instead of the proper sign OperationOperand AOperand BResult A+B> 0 < 0 A+B< 0 > 0 A-B> 0< 0 A-B< 0> 0 Add (add), add immediate (addi) and subtract (sub) cause exceptions on overflow Add unsigned(addu), add immediate unsigned(addiu) and subtract unsigned (subu) do NOT cause exceptions on overflow

King Fahd University of Petroleum and Minerals King Fahd University of Petroleum and Minerals Computer Engineering Department Computer Engineering Department College of Computer Science And Engineering College of Computer Science And Engineering Dr. A. BouhraouaArithmetic for Computers 12 COE 308 Logical Operations And: Bit to bit logical AND –Used to Clear specified bits Or: Bit to Bit logical OR: –Used to Set specified bits Shift Operations: –Many uses: Many algorithms, available in some high level languages like C/C++ –SLL, SLR Logical OperationsC OperatorsMIPS Instruction Shift Left<<sll Shift Right>>slr Bit-by-bit AND&and, andi Bit-by-bit OR|or, ori