Tutorial 09

Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

Tutorial #9

CSE 321b: Computer Organization (II)


Third Year, Computer and Systems Engineering

Question:
9.1 Briefly explain the following representations: sign magnitude, twos
complement, biased.
Sign–Magnitude Representation: In an N-bit word, the left-most bit is the sign (0
= positive, 1 = negative) and the remaining N – 1 bits comprise the magnitude of
the number. Twos Complement Representation: A positive integer is represented
as in sign magnitude. A negative number is represented by taking the Boolean
complement of each bit of the corresponding positive number, then adding 1 to
the resulting bit pattern viewed as an unsigned integer. Biased representation: A
fixed value, called the bias, is added to the integer.

9.3 What is the sign-extension rule for twos complement numbers?


Add additional bit positions to the left and fill in with the value of the original sign
bit.

9.4 How can you form the negation of an integer in twos complement
representation?
Take the Boolean complement of each bit of the positive number, then adding 1
to the resulting bit pattern viewed as an unsigned integer.
Problems:
9.1 Represent the following decimal numbers in both binary sign/magnitude and
twos complement using 16 bits: +512; -29.
Sign Magnitude: 512 = 0000 0010 0000 0000
–29 = 1000 0000 0001 1101
Two’s Complement: 512 = 0000 0010 0000 0000
–29 = 1111 1111 1110 0011

9.2 Represent the following twos complement values in decimal:


1101011; 0101101.
1101011:
Because this starts with a leftmost 1, it is a negative number. The magnitude of
the negative number is determined by flipping the bits and adding 1: 0010100 + 1
= 0010101
This is 21, so the original value was –21.
0101101:
Because this starts with a leftmost 0, it is a positive number and we just compute
the magnitude as an unsigned binary number, which is 45.

9.10 Assume numbers are represented in 8-bit twos complement representation.


Show the calculation of the following:
a. 6 + 13 b. - 6 + 13 c. 6 - 13 d. - 6 - 13

a. + 6 00000110 b. – 6 11111010 c. + 6 00000110 d. – 6 11111010


+13 00001101 +13 00001101 –13 11110011 –13 11110011
+19 00010011 + 7 00000111 – 7 11111001 –19 11101101

9.11 Find the following differences using twos complement arithmetic:


a. 111000 b. 11001100 c. 111100001111 d. 11000011
- 110011 - 101110 - 110011110011 - 11101000

a. 111000 b. 11001100 c. 111100001111 d. 11000011


+ 001101 + 00010010 + 001100001101 + 00011000
1 000101 11011110 1 001000011100 11011000
9.12 Is the following a valid alternative definition of overflow in twos
complement arithmetic?
If the exclusive-OR of the carry bits into and out of the leftmost column is 1, then
there is an overflow condition. Otherwise, there is not.
The overflow rule was stated as follows: If two numbers are added, and they are
both positive or both negative, then overflow occurs if and only if the result has
the opposite sign. There are four cases:
•Both numbers positive (sign bit = 0) and no carry into the leftmost bit position:
There is no carry out of the leftmost bit position, so the XOR is 0. The result has a
sign bit = 0, so there is no overflow.
•Both numbers positive and a carry into the leftmost bit position: There is no
carry out of the leftmost position, so the XOR is 1. The result has a sign bit = 1, so
there is overflow.
•Both numbers negative and no carry into the leftmost position: There is a carry
out of the leftmost position, so the XOR is 1. The result has a sign bit of 0, so there
is overflow.
•Both numbers negative and a carry into the leftmost position. There is a carry
out of the leftmost position, so the XOR is 0. The result has a sign bit of 1, so there
is no overflow.
Therefore, the XOR result always agrees with the presence or absence of
overflow.

9.15 Use the Booth algorithm to multiply 19 (multiplicand) by 23 (multiplier),


where each number is represented using 6 bits.
Using M=010011 (23) and Q = 010111 (19) we should get 437 as the result.
A Q Q–1 M
000000 010111 0 010011 Initial
101101 010111 0 010011 A A – M
110110 101011 1 010011 Shift
111011 010101 1 010011 Shift
111101 101010 1 010011 Shift
010000 101010 1 010011 A A + M
001000 010101 0 010011 Shift
110101 010101 0 010011 A A – M
111010 101010 1 010011 Shift
001101 101010 1 010011 A A + M
000110 110101 1 010011 Shift

Answer = 0001 1011 0101 (which is 437)


9.14 Given x= 0101 and y= 1010 in twos complement notation (i.e. x = 5, y = -6),
compute the product P = x X y with Booth’s algorithm.

A Q Q–1 M
0000 1010 0 010 1 Initial
0000 0101 0 010 1 Shift
1011 0101 0 010 1 A←A–M
1101 1010 1 010 1 Shift
0010 1010 1 010 1 A←A+M
0001 0101 0 010 1 Shift
1100 0101 0 010 1 A←A–M
1110 0010 1 010 1 Shift
Result = 11100010 which equal -30

External problem: Divide -7 by 3 in binary notation, using 4-bit words.


Use Restoring Division

Divisor = +3 = (0011)2 is placed in M register.


Dividend = –7 = convert to unsigned  7 = (0111)2 is placed in Q register
A Q M
0000 0111 0011 Initial
0000 1110 LL Shift
1101 sub
1101
0000 1110 Restore
0001 1100 LL Shift
1101 sub
1110
0001 1100 Restore
0011 1000 LL Shift
1101 sub
0000
0000 1001 Q0  1
0001 0010 LL Shift
1101 sub
1110
0001 0010 Restore

Remainder = twos complement of (0001)2 =( 1111)2 = -1


Quotient = twos complement of (0010)2 = (1110)2 = –2

You might also like