+ CS 325: CS Hardware and Software Organization and Architecture Integers and Arithmetic Part 4.

Slides:



Advertisements
Similar presentations
Intro to CS – Honors I Representing Numbers GEORGIOS PORTOKALIDIS
Advertisements

Arithmetic in Computers Chapter 4 Arithmetic in Computers2 Outline Data representation integers Unsigned integers Signed integers Floating-points.
Representing Numbers: Integers
Princess Sumaya Univ. Computer Engineering Dept. Chapter 3: IT Students.
CS 61C L02 Number Representation (1) Garcia, Spring 2004 © UCB Lecturer PSOE Dan Garcia inst.eecs.berkeley.edu/~cs61c CS61C.
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
Data Representation Computer Organization &
Data Representation COE 205
Assembly Language and Computer Architecture Using C++ and Java
Fixed-Point Arithmetics: Part I
Introduction to Programming with Java, for Beginners
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
Assembly Language for Intel-Based Computers, 4th Edition
COMP3221: Microprocessors and Embedded Systems--Lecture 4 1 COMP3221: Microprocessors and Embedded Systems Lecture 4: Number Systems (II)
Computer ArchitectureFall 2008 © August 25, CS 447 – Computer Architecture Lecture 3 Computer Arithmetic (1)
COMP3221 lec07-numbers-III.1 Saeid Nooshabadi COMP 3221 Microprocessors and Embedded Systems Lecture 7: Number Systems - III
Mathematics with Binary. Question  Below is a binary string  Which is the least significant bit (LSB)?  Which is the most significant bit (MSB)? 0.
Computer ArchitectureFall 2007 © August 29, 2007 Karem Sakallah CS 447 – Computer Architecture.
+ CS 325: CS Hardware and Software Organization and Architecture Integers and Arithmetic.
+ CS 325: CS Hardware and Software Organization and Architecture Exam 1: Study Guide.
Arithmetic for Computers
CENG 311 Machine Representation/Numbers
Data Representation – Binary Numbers
Computers Organization & Assembly Language
Computer Arithmetic Nizamettin AYDIN
Computer Arithmetic. Instruction Formats Layout of bits in an instruction Includes opcode Includes (implicit or explicit) operand(s) Usually more than.
CMPE 325 Computer Architecture II Cem Ergün Eastern Mediterranean University Integer Representation and the ALU.
CSU0014 Assembly Languages Homepage: Textbook: Kip R. Irvine, Assembly Language for Intel-Based Computers,
Computing Systems Basic arithmetic for computers.
Lec 3: Data Representation Computer Organization & Assembly Language Programming.
Lecture Objectives: 1)Define the terms least significant bit and most significant bit. 2)Explain how unsigned integer numbers are represented in memory.
+ CS 325: CS Hardware and Software Organization and Architecture Integers and Arithmetic Part 2.
CPU Internal memory I/O interface circuit System bus
Chapter 19 Number Systems. Irvine, Kip R. Assembly Language for Intel-Based Computers, Translating Languages English: Display the sum of A times.
Integer and Fixed Point P & H: Chapter 3
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=
Chapter 10 Instruction Sets: Characteristics and Functions Felipe Navarro Luis Gomez Collin Brown.
C OMPUTER A RITHMETIC. I NTRODUCTION A processor has an separate unit that is known as ALU that executes arithmetic operations. Negative numbers may be.
Chapter 8 Computer Arithmetic. 8.1 Unsigned Notation Non-negative notation  It treats every number as either zero or a positive value  Range: 0 to 2.
EE204 L03-ALUHina Anwar Khan EE204 Computer Architecture Lecture 03- ALU.
COMPUTER ARCHITECTURE & OPERATIONS I Instructor: Yaohang Li.
Chapter 9 Computer Arithmetic
William Stallings Computer Organization and Architecture 8th Edition
Addition and Subtraction
Lec 3: Data Representation
Array multiplier TU/e Processor Design 5Z032.
Data Representation Binary Numbers Binary Addition
Integer Real Numbers Character Boolean Memory Address CPU Data Types
Data Representation in Computer Systems
Computer Architecture & Operations I
William Stallings Computer Organization and Architecture 7th Edition
IT 0213: INTRODUCTION TO COMPUTER ARCHITECTURE
COMP3221: Microprocessors and Embedded Systems
ECEG-3202 Computer Architecture and Organization
ECEG-3202 Computer Architecture and Organization
ECEG-3202 Computer Architecture and Organization
Decimal and binary representation systems
Chapter 8 Computer Arithmetic
Part I Data Representation and 8086 Microprocessors
Presentation transcript:

+ CS 325: CS Hardware and Software Organization and Architecture Integers and Arithmetic Part 4

+ Outline Binary Multiplication Booth’s Algorithm Number Representations

+ 2’s Complement Binary Multiplication – Booth’s Algorithm Multiplication by bit shifting and addition. Removes the need for multiply circuit Requires: A way to compute 2’s Complement Available as fast hardware instructions X86 assembly instruction: NEG A way to compare two values for equality How to do this quickly? Exclusive Not OR (NXOR) Gate Compare all sequential bits of bit string A and bit string B. Values are equal if the comparison process produces all 1s. A way to shift bit strings. Arithmetic bit shift, which preserves the sign bit when shifting to the right  arithmetic shift right  x86 assembly instruction: SAR ABA NXOR B

+ 2’s Complement Binary Multiplication – Booth’s Algorithm Example: 5 x -3 First, convert to 2s comp bin: 5 = = 1101 If we add 0 to the right of both values, there are or 1-0 switches in 0101, and 3 in Pick 1101 as X value, and 0101 as Y value Next, 2s Comp of Y: 1011 for bin subtraction. Next, set 2 registers, U and V, to 0. Make a table using U, V, and 2 additional registers X, and X- 1.

+ 2’s Complement Binary Multiplication – Booth’s Algorithm Register X is set to the predetermined value of x, and X-1 is set to 0 Rules: Look at the LSB of X and the number in the X-1 register. If the LSB of X is 1, and X-1 is 0, we subtract Y from U. If LSB of X is 0, and X-1 is 1, then we add Y to U. If both LSB of X and X-1 are equal, do nothing and skip to shifting stage. UVXX

+ 2’s Complement Binary Multiplication – Booth’s Algorithm In our case, the LSB of X is one, and X-1 is zero, so we subtract Y from U. Next, we do an arithmetic right shift on U and V 1011  1101, 0000  1000 Copy the LSB of X into X-1 And then perform a circular right shift on X 1101  1110 Repeat the process three more times. UVXX

+ 2’s Complement Binary Multiplication – Booth’s Algorithm The LSB of X is zero, and X-1 is one, so we add Y to U. Next, we do an arithmetic right shift on U and V 0010  0001, 1000  0100 Copy the LSB of X into X-1 And then perform a circular right shift on X 1110  0111 Repeat the process two more times. UVXX

+ 2’s Complement Binary Multiplication – Booth’s Algorithm The LSB of X is one, and X-1 is zero, so we subtract Y from U. Next, we do an arithmetic right shift on U and V 1100  1110, 0100  0010 Copy the LSB of X into X-1 And then perform a circular right shift on X 0111  1011 Repeat the process one more time. UVXX

+ 2’s Complement Binary Multiplication – Booth’s Algorithm The LSB of X is one, and X-1 is one, begin shifts. Next, we do an arithmetic right shift on U and V 1110  1111, 0010  0001 Copy the LSB of X into X-1 And then perform a circular right shift on X 1011  1101 UVXX

+ 2’s Complement Binary Multiplication – Booth’s Algorithm The result is stored in U followed by V. This result is stored in 2’s complement notation. Convert to decimal:   This gives the correct result of 3 x -5 UVXX

+ 2’s Complement Binary Multiplication – Booth’s Algorithm Another Example: 7 x -4 First, convert to 2s comp bin: 7  0111, add zero to right gives 01110, 2 switches -4  1100, add zero to right gives 11000, 1 switch X = 1100 Y = Y = 1001, for easy bin subtract

+ 2’s Complement Binary Multiplication – Booth’s Algorithm UVXX-1 0: : : : : Result of 7 x -4: UV  

+ 2’s Complement Binary Multiplication – Booth’s Algorithm Try: -9 x 7

+ Numbers are stored at addresses Memory is a place to store bits A word is a fixed number of bits Ex: 32 bits, or 4 bytes An address is also a fixed number of bits Represented as unsigned numbers

+ Numbering Bits and Bytes Need to choose order for: Storage in physical memory system Transmission over serial/parallel medium (data network) Bit order Handled by hardware Usually hidden from programmer Byte order Affects multi-byte data items such as integers Visible and important to programmers

+ Possible Byte Orders Least significant byte of integer in lowest memory location Little endian Most Significant byte of integer in lowest memory location. Big endian

+ Byte Order Illustration Note: Difference is especially important when transferring data between computers for which the byte ordering differs.

+ Sign Extension Convert 2’s comp number using N bits to more than N bits (int to long int): Replicate the MSB (sign bit) of the smaller number to fill new bits. 2’s comp positive number has infinite 0s 2’s comp negative number has infinite 1s Ex: 16bit to 32-bit:

+ Conclusion We represent “things” in computers as particular bit patterns: N bits  2 N Decimal for human calculations, binary for computers, hex for convenient way to write binary 2’s comp universal in computing: so make sure to learn! Number are infinite, computers are not, so errors can occur (overflow, underflow) Know the powers of 2.