CSCI206 - Computer Organization & Programming

Slides:



Advertisements
Similar presentations
Computer ArchitectureFall 2008 © August 25, CS 447 – Computer Architecture Lecture 3 Computer Arithmetic (1)
Advertisements

DIGITAL SYSTEMS TCE1111 Representation and Arithmetic Operations with Signed Numbers Week 6 and 7 (Lecture 1 of 2)
Computer ArchitectureFall 2007 © August 29, 2007 Karem Sakallah CS 447 – Computer Architecture.
1.6 Signed Binary Numbers.
1 Arithmetic and Logical Operations - Part II. Unsigned Numbers Addition in unsigned numbers is the same regardless of the base. Given a pair of bit sequences.
Digital Computer Concept and Practice Copyright ©2012 by Jaejin Lee Logic Circuits I.
Chapter 6-1 ALU, Adder and Subtractor
Topic: Arithmetic Circuits Course: Digital Systems Slide no. 1 Chapter # 5: Arithmetic Circuits.
CSE 241 Computer Organization Lecture # 9 Ch. 4 Computer Arithmetic Dr. Tamer Samy Gaafar Dept. of Computer & Systems Engineering.
Number Systems. Today Decimal Hexadecimal Binary –Unsigned Binary –1’s Complement Binary –2’s Complement Binary.
46 Number Systems Problem: Implement simple pocket calculator Need: Display, adders & subtractors, inputs Display: Seven segment displays Inputs: Switches.
ECE 301 – Digital Electronics Unsigned and Signed Numbers, Binary Arithmetic of Signed Numbers, and Binary Codes (Lecture #2)
ECEN 248 Lab 4: Multiplexer Based Arithmetic Logic Unit
Charles Kime & Thomas Kaminski © 2004 Pearson Education, Inc. Terms of Use (Hyperlinks are active in View Show mode) Terms of Use Logic and Computer Design.
By Jariya Phongsai A two's-complement system is a system in which negative numbers are represented by the two's complement of the absolute value; this.
1 Arithmetic I Instructor: Mozafar Bag-Mohammadi Ilam University.
Data Representation in Computer Systems. 2 Signed Integer Representation The conversions we have so far presented have involved only positive numbers.
07/12/ Data Representation Two’s Complement & Binary Arithmetic.
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=
69 Decimal (Base 10) Numbers n Positional system - each digit position has a value n 2534 = 2*1, * *10 + 4*1 n Alternate view: Digit position.
CPS3340 Computer Architecture Fall Semester, 2013
Addition, Subtraction, Logic Operations and ALU Design
2's Complement Arithmetic
ECE 171 Digital Circuits Chapter 2 Binary Arithmetic Herbert G. Mayer, PSU Status 1/14/2016 Copied with Permission from prof. Mark PSU ECE.
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.
ECEN 248: INTRODUCTION TO DIGITAL SYSTEMS DESIGN Lecture 8 Dr. Shi Dept. of Electrical and Computer Engineering.
President UniversityErwin SitompulDigital Systems 7/1 Lecture 7 Digital Systems Dr.-Ing. Erwin Sitompul President University
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,
1 Integer Representations V1.0 (22/10/2005). 2 Integer Representations  Unsigned integer  Signed integer  Sign and magnitude  Complements  One’s.
Arithmetic Circuits I. 2 Iterative Combinational Circuits Like a hierachy, except functional blocks per bit.
Binary Addition The simplest arithmetic operation in binary is addition. Adding two single-digit binary numbers is relatively simple, using a form of carrying:
Lecture 4: Digital Systems & Binary Numbers (4)
Cosc 2150: Computer Organization
Design of Digital Circuits Reading: Binary Numbers
Computer Architecture & Operations I
Addition and Subtraction
Prof. Sin-Min Lee Department of Computer Science
Negative Integers Unsigned binary representation can not be used to represent negative numbers. With paper and pencil arithmetic, a number is made negative.
Negative Binary Numbers
Digital Arithmetic Wen-Hung Liao, Ph.D..
CSCI206 - Computer Organization & Programming
Computer Architecture & Operations I
Lecture 2 Topics Binary Arithmetic (Unsigned binary operands)
Negative Binary Numbers
Integer Representations and Arithmetic
Digital Systems Section 8 Multiplexers. Digital Systems Section 8 Multiplexers.
Exercise: Add these two single precision IEEE 754 numbers: … …0 Left number: 1.101x24 Right number: 1.011x 22= x24.
Computer Organization and ASSEMBLY LANGUAGE
Lecture 2 Topics Binary Arithmetic (Unsigned binary operands)
MIPS ALU.
Number Representation
King Fahd University of Petroleum and Minerals
MIPS ALU.
Data Representation in Computer Systems
Arithmetic Circuits (Part I) Randy H
Digital Systems Section 12 Binary Adders. Digital Systems Section 12 Binary Adders.
By: A. H. Abdul Hafez CAO, by Dr. A.H. Abdul Hafez, CE Dept. HKU
Overview Part 1 – Design Procedure Part 2 – Combinational Logic
Instructor: Alexander Stoytchev
Decimal and binary representation systems
Instructor: Alexander Stoytchev
ECE 352 Digital System Fundamentals
Binary to Decimal Conversion
ECE 171 Digital Circuits Chapter 2 Binary Arithmetic
ECE 331 – Digital System Design
CSC 220: Computer Organization Signed Number Representation
Integer arithmetic Depends what you mean by "integer"
COMS 361 Computer Organization
Two’s Complement & Binary Arithmetic
Today Binary addition Representing negative numbers 2.
Presentation transcript:

CSCI206 - Computer Organization & Programming Integer Addition and Subtraction zyBook: 10.1, 10.2

Review Positional Number Systems n-th digit Base

Binary to Decimal (b=2) 110011 543210 Digit count (n), or position

Decimal to Binary (b=2) (left to right) 42 = ?? First power of two <= N is the first 1, e.g., 2^5 which is 32 Subtract the value from the original, e.g., 42 - 32 == 10 Repeat for remaining digits insert zero if greater than remaining value else insert 1 and subtract value

Decimal to Binary (b=2) (left to right) insert 0’s in where the value is too small, e.g., 42-32 == 10, no 2^4 == 16 b/c 16 > 10 42 = 101010 5 4 3 2 1 0 first power of 2 <= 42 subtract, have 10 remaining next power of 2 <= 10, subtract 2 remain 2 remains, 2^1 is the last 1

Decimal to Binary (b=2) (right to left) Let N be the base 10 number while N > 0 If N is odd (N%2==1) add a 1 else add a 0 N = N / 2 (integer divide)

Decimal to Binary (b=2) (right to left) 42 = even 0, 42/2 = 21R0 21 = odd 1, 21/2 = 10R1 10 = even 0, 10/2 = 5R0 5 = odd 1, 5/2 = 2R1 2 = even 0, 2/2 = 1R0 1 = odd 1, 1/2 = 0R1

Decimal to Binary (b=2) (right to left) 42 = even 0, 42/2 = 21R0 21 = odd 1, 21/2 = 10R1 10 = even 0, 10/2 = 5R0 5 = odd 1, 5/2 = 2R1 2 = even 0, 2/2 = 1R0 1 = odd 1, 1/2 = 0R1 Generate result right to left: 101010

Binary addition (zyBook 10.2) same as elementary base-10 arithmetic 1 529 + 742 1271 Sum each place value from right to left and add carry bits if result requires an additional digit.

Binary Addition 101101 + 1110 1 A B Sum Carry 1

Binary Addition 101101 + 1110 11 A B Sum Carry 1

Binary Addition 1 101101 + 1110 011 A B Sum Carry 1

Binary Addition 1 101101 + 1110 011 A B Sum Carry 1

Binary Addition 1 101101 + 1110 011 A B Sum Carry 1

Binary Addition 1 1 101101 + 1110 1011 A B Sum Carry 1

Binary Addition 1 1 101101 + 1110 11011 A B Sum Carry 1

Binary Addition 1 1 101101 + 1110 111011 A B Sum Carry 1

Binary Addition 101101 = 45 + 1110 = 14 111011 = 59 A B Sum Carry 1

Ripple Carry Adder Add bits sequentially Carry out goes into next carry in ALU Symbol

Ripple Carry Adder 1001 + 0101 1110 1 0 0 1 0 0 1 1 0 0 0 1 0 1 1 1 0 Simple to understand, but slow because the result has to be computed 1 bit at a time Faster, more complex, circuits exist!

Subtraction 2’s complement negation is done with bitwise inverse plus one: Easily implemented by computing the bitwise inverse and setting carry in to be 1 on bit 0, i.e., Bi = not(yi)

Multiplexer (Mux) By Lenehey at en.wikipedia Later version(s) were uploaded by Fresheneesz at en.wikipedia. (Transferred from en.wikipedia) [Public domain], from Wikimedia Commons

Adder/subtractor

Overflow Only possible when signs are the same of both operands. Differing signs always produce a smaller absolute value. Same signs produce a larger absolute value. Overflow if positive + positive = negative or negative + negative = positive. carry out of MSB (most significant bit) is not a valid test for overflow!

Absolute Value if (x > 0) x else -x

Absolute Value if (x > 0) x else -x

Absolute Value 1

Absolute Value Overflow? if result is negative only a problem with the C standard library implementation NAME abs, labs, llabs, imaxabs - compute the absolute value of an integer SYNOPSIS #include <stdlib.h> int abs(int j); Result of abs is a signed integer!

Consider the representations … Assuming an 8-bit integer INT_MIN : 1000 0000 // -128 INT_MAX: 0111 1111 // +127 If unsigned, 1000 0000 == 128 If signed, 2’s comp: 0111 1111 + 1 = 1000 0000 because it is signed, it is now -128

Absolute Value Overflow? the invert plus 1 will overflow if the inverted value is all 1’s 1000000...0 is the most negative 2’s complement value (INT_MIN) Detect if the number is negative and its absolute value is still negative! (INT_MIN!)