Download presentation
Presentation is loading. Please wait.
Published byAlexandra Rich Modified over 9 years ago
1
+ CS 325: CS Hardware and Software Organization and Architecture Integers and Arithmetic Part 4
2
+ Outline Binary Multiplication Booth’s Algorithm Number Representations
3
+ 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. 10110110 arithmetic shift right 11011011 x86 assembly instruction: SAR ABA NXOR B 001 010 100 111
4
+ 2’s Complement Binary Multiplication – Booth’s Algorithm Example: 5 x -3 First, convert to 2s comp bin: 5 = 0101 -3 = 1101 If we add 0 to the right of both values, there are 4 0-1 or 1-0 switches in 0101, and 3 in 1101. 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.
5
+ 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-1 0000 11010
6
+ 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-1 0000 11010 +1011 1011 1101100011101
7
+ 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-1 1101100011101 +0101 0010 0001010001110
8
+ 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-1 0001010001110 +1011 1100 1110001010111
9
+ 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-1 1110001010111 1111000111011
10
+ 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: 11110001 00001111 -15 10 This gives the correct result of 3 x -5 UVXX-1 1111000111011 11110001
11
+ 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 = 0111 -Y = 1001, for easy bin subtract
12
+ 2’s Complement Binary Multiplication – Booth’s Algorithm UVXX-1 0: 0000 0000 1100 0 1: 0000 0000 0110 0 2: 0000 0000 0011 0 +1001 1001 3: 1100 1000 1001 1 4: 1110 0100 1100 1 Result of 7 x -4: UV 11100100 00011100 -28 10
13
+ 2’s Complement Binary Multiplication – Booth’s Algorithm Try: -9 x 7
14
+ 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
15
+ 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
16
+ 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
17
+ Byte Order Illustration Note: Difference is especially important when transferring data between computers for which the byte ordering differs.
18
+ 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 -4 10 to 32-bit: 1111 1111 1111 1100 1111 1111 1111 1111 1111 1111 1111 1100
19
+ 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.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.