You are on page 1of 23

Computer Organization and

Assembly Language
Muhammad Usman

Federal Urdu University of Arts, Science & Technology, Islamabad


Integer Representation
• Whole numbers or fixed point numbers
• Computers use fixed number of bits to
represent an integer
• Commonly used bit lengths for integers
are 8-bit, 16-bit, 32-bit or 64-bit
• Two representation schemes for integers
– Unsigned integers
– Signed integers

FUUAST, Islamabad 2
Unsigned Integer
• Unsigned integers can represent zero and
positive integers
• But not negative integers
• For n=8, binary pattern is 0100 0001
• For n=16, binary pattern is 0001 0000
0000 1000
• n-bit unsigned integer can represent
integers from 0 to (2n)-1
FUUAST, Islamabad 3
Continue…
N Min Max

8 0 28-1 = 255

16 0 216-1 = 65,535

32 0 232-1 = 4,294,967,295

64 0 264-1 = 18,446,744,073,709,551,615

FUUAST, Islamabad 4
Signed Integers
• Signed integers can represent zero,
positive integers, as well as negative
integers
• Most significant bit (MSB) is called the sign
bit
• Positive and negative integers need to be
processed separately

FUUAST, Islamabad 5
Continue…
• Sign bit is used to represent the sign of the
integer with:
– 0 for positive integers and
– 1 for negative integers
• Remaining n-1 bits represents the magnitude
or absolute value
• For n=8, binary representation is 0 100 0001
– Sign bit is 0 ⇒ positive
– Magnitude 100 0001 ⇒ 6510
– Hence, the number is +6510
FUUAST, Islamabad 6
1’s Compliment
• 1’s compliment representation
– For n=8, binary representation 1 000 00012.
– Sign bit is 1 ⇒ negative
– Absolute value is the complement of 000
00012, i.e., 111 11102 = 12610
– Hence, the integer is -12610

FUUAST, Islamabad 7
Continue…

FUUAST, Islamabad 8
Continue…
• 1’s compliment representation
– For n=8, binary representation 0 000 00002
• Sign bit is 0 ⇒ positive
• Absolute value is 000 00002 = +010
• Hence, the integer is 010
– For n=8, binary representation 1 111 11112
• Sign bit is 1 ⇒ negative
• Absolute value is compliment of 111 11112 i.e. 000
00002 = 010
• Hence, the integer is -010

FUUAST, Islamabad 9
2’s Compliment
• 2’s complement representation
– Allows to represent signed negative values in
binary
– Convert -6510 to binary
– 6510  010000012
– Taking 1’s compliment
01000001  10111110
– Takin 2’s compliment (by adding 1 in above)
– (10111110 + 1)  10111111
FUUAST, Islamabad 10
Continue…
• 101111112 is -6510 in binary
• If we add 010000012 (+6510) to 101111112
(-6510) and ignore the carry bit,
• Sum is 0, which is what we obtain if we
add +65 + (-65) = 0
• Computers use 2's Complement
Representation for Signed Integers

FUUAST, Islamabad 11
2’s Compliment

FUUAST, Islamabad 12
Difference: 1’s & 2’s Compliment
• 1′ s complement has two representations
of 0
– 0000 0000, which is positive zero (+0)
– 1111 1111, which is negative zero (-0)
• In 2′ s complement, there is only one
representation for zero (0000 0000)
• That’s why 2′s complement is generally
used

FUUAST, Islamabad 13
Subtraction
• Subtraction is treated as Addition
– For n=8, 6510-510=6510+(-510)=6010
– 6510  0100 00012
– -510  1111 10112 (2’s c)
– (adding) 0011 11002  6010
• Perform 8010-7010

FUUAST, Islamabad 14
Binary Addition Overflow
4-bit values
(1) (2) (3) (4) (5)
0111 1000 1111 0100 1000
0110 0111 1010 0011 1001
1101 1111 1001 0111 0001
• In cases (3) and (5) there is carry in place
of 5th bit
• Hence the result is causing overflow

FUUAST, Islamabad 15
Continue…
• Whenever, actual result increase the range
of value, overflow occurs
• Overflow is the higher value then the
range of values

FUUAST, Islamabad 16
Floating Point Number
• Programming language support numbers
with fractions called floating point
numbers
• Examples: 3.1415, 1.0x10-9, 8.64x1013
• Single precision floating point number
(32-bit)
• Double precision floating point number
(64-bit)

FUUAST, Islamabad 17
Continue…
• No fixed number of digits before and after
the decimal point
• If number of digits before and after the
decimal point are set, fixed point
representation
• Floating point number have:
– Mantissa (M)
– Exponent (E’) [E+bias]
– Sign (S)

FUUAST, Islamabad 18
Continue…
• Single Precision (32-bit)
– 1 bit: sign
– 8 bits: exponent [bias is 127]
– 23 bits: fractions/mantissa
• Double Precision (64-bit)
– 1 bit: sign
– 11 bits: exponent [bias is 1023]
– 52 bits: fractions/mantissa

FUUAST, Islamabad 19
Continue…
• 1014.2510  1111110110.1102
• We can write 1.1111101101102 x29
• Now
–S=0
– E = 9 and E’ = 9+127 = 136  100010002
– M = 111110110110

0 1 0 0 0 1 0 0 0 1 1 1 1 1 0 1 1 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0

FUUAST, Islamabad 20
FP decimal to binary
• Convert -0.8125 to binary single and
double precision
– 0.8125  (0.1101)2
– 1.1012 x 2-1 (Normalized Form)
– S = 1 (negative number)
– E’ = -1+127 = 126  011111102 {single}
– E’ = -1+1023 = 1022  011111111102
{double}
– M = 1012

FUUAST, Islamabad 21
Continue…

1 0 1 1 1 1 1 1 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

Single Precision (32-bit)

1 0 1 1 1 1 1 1 1 1 1 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

Double Precision (64-bit)

FUUAST, Islamabad 22
Decimal value: single precision float
1 0 1 1 1 1 1 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

• S = 1 (negative number)
• E = 011111002 = 124, E-bias = -3
• M = 1.0100….02
• So, -(1.0100…0)2 x 2-3 = -(0.0010100…0)2
• -0.1562510

FUUAST, Islamabad 23

You might also like