0% found this document useful (0 votes)
31 views

Lecture Slides Week4

Uploaded by

Anas
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views

Lecture Slides Week4

Uploaded by

Anas
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 42

Computer Organization and Assembly

Language
(CS2523)

Week 4

Department of Computer Science


Capital University of Science and Technology (CUST)
Outline Week 4
• Floating Point Representation

2
Binary Representation of
Floating Point Numbers
IEEE Standard 754 Floating Point
Numbers
• The IEEE Standard for Floating-Point Arithmetic (IEEE 754) is a
technical standard for floating-point computation which was
established in 1985 by the Institute of Electrical and Electronics
Engineers (IEEE).
• IEEE Standard 754 floating point is the most common representation
today for real numbers on computers, including Intel-based PC’s,
Macs, and most Unix platforms.

4
IEEE 754 Components

IEEE 754 has 3 basic components:


1.The Sign of Mantissa
This is as simple as the name. 0 represents a positive number while 1
represents a negative number.
2.The Biased exponent
The exponent field needs to represent both positive and negative
exponents. A bias is added to the actual exponent in order to get the
stored exponent.
3.The Normalized Mantissa
The mantissa is part of a number in scientific notation or a floating-
point number, consisting of its significant digits. Here we have only 2
digits, i.e. O and 1. So a normalized mantissa has one 1 to the left of
the decimal.

5
6
Convert Float to Floating Point Representation – 32 Bit

 Float a = 5.2
 Binary of 5 = 101
 Binary of Fractional part i.e. “.2” would be:
.2*2 0
.4 0
.8 1
.6 1
.2

 .2*2=0.4 .4*2=0.8 .8*2=1.6 0.6*2=1.2


.2=.2
 5.2=101.00110011
7
Convert Float to Floating Point Representation – 32 Bit

 5.2=101.00110011 No Need to Store the leading 1

 1.0100110011… E+2
 Bias 127; so, 127+2 = 129 = 10000001

0 1 0 0 0 0 0 0 1 0 1 0 0 1 1 0 0 1 1 0 0 1 1 …

1 Bit 8 Bits 23 Bits


Sign Exponent Mantissa

0:Positive

8
Convert Float to Floating Point Representation – 32 Bit

 Float a = 5.2

 In Binary
01000000101001100110011001100110
 In Hexadecimal
40A66666

9
Example: Biased Notation

10
Convert Float to Floating Point Representation – 32 Bit

11
Convert Float to Floating Point Representation – 32 Bit

12
Convert Float to Floating Point Representation – 32 Bit

13
Convert Float to Floating Point Representation – 8 Bit

 Float a = 11.8
 Binary of 11 = 1011
 Binary of Fractional part i.e. “.8” would be:
.8*2 1
.6 1
.2 0
.4 0
.8

 .8*2=1.6; .6*2=1.2; .2*2=0.4; 0.4*2=0.8; .8=.8


 11.8=1011.110011001100...
14
Convert Float to Floating Point Representation – 8 Bit
 (11.8)10=(1011.110011001100...)2 (Move the fractional point
or dot just before the first one)
 (1.011110011001100...)2 *23
 (1.0111)2 *23 (4 bit mantissa) = (1.0111)2 *2(11)2
 (1.0111)2 *2(011)2= (3 bit exponent)
 Bias 3; so, 3+3 = 6 = 110

0 1 1 0 0 1 1 1
+(1.0111)2*2(110)2
1 Bit 3 Bits 4 Bits
Sign Exponent Mantissa
is
Positive#

15
Convert Float to Floating Point Representation – 8 Bit

 Float a = 3.15
 Binary of 3 = 11
 Binary of Fractional part i.e. “.15” is =
 0.00100110011
.15*2 0
.3 0
.6 1
.2 0
.4 0
.8 1
.6 1
.2 0
.4 0
.8 1
.6 1
.2

16
Convert Float to Floating Point Representation – 8 Bit
 (3.15)10=(11.00100110011...)2 (Move the fractional point or
dot just before the first one)
 (1.100100110011...)2 *21
 (1.1001)2 *21 (4 bit mantissa) = (1.1001)2 *2(1)2
 (1.1001)2 *2(001)2= (3 bit exponent)
 Bias 3; so, 3+1 = 4 = 100

0 1 0 0 1 0 0 1
+(1.1001)2*2(100)2
1 Bit 3 Bits 4 Bits
Sign Exponent Mantissa
is
Positive#

17
Convert Float to Floating Point Representation – 8 Bit

18
Convert Float to Floating Point Representation – 8 Bit

19
Convert Float to Floating Point Representation – 8 Bit

20
Convert Float to Floating Point Representation – 8 Bit

21
Convert Float to Floating Point Representation – 8 Bit

22
Convert Float to Floating Point Representation – 8 Bit

 Float a = -0.05
 Binary of 0 = 0
 Binary of Fractional part i.e. “.05” is =
 0000110011
.05*2 0
.1 0
.2 0
.4 0
.8 1
.6 1
.2 0
.4 0
.8 1
.6 1
.2

23
Convert Float to Floating Point Representation – 8 Bit
 (0.05)10=(0.0000110011...)2 (Move the fractional point or dot
just after the first one)
 (00001.10011...)2 *2-5
 (1.1001)2 *2-5 (4 bit mantissa)
 Bias 3; so, -5+3 = -2 = 010
1 Bit
Sign of Exponent

1 0 1 0 1 0 0 1
-(1.1001)2*2(-010)2
1 Bit 3 Bits 4 Bits
Sign Exponent Mantissa
is
Negative#
24
Convert Float to Floating Point Representation – 8 Bit

 Float a = 20.38
 Binary of 20 = 10100
 Binary of Fractional part i.e. “.38” is =
 01100001010…
.38*2 0
.76 1
.52 1
.04 0
.08 0
.16 0
.32 0
.64 1
.28 0
.56 1
.12 0
.24

25
Convert Float to Floating Point Representation – 8 Bit
 (20.38)10=(10100. 01100001010...)2 (Move the fractional point
or dot just before the first one)
 (1.010001100001010...)2 *24
 (1.0100)2 *24 (4 bit mantissa)
 Bias 3; so, 3+4 = 7 = 111

0 1 1 1 0 1 0 0
+(1.0100)2*2(111)2
1 Bit 3 Bits 4 Bits
Sign Exponent Mantissa
is
Positive#

26
Convert Float to Floating Point Representation – 8 Bit

 Float a = -7.5
 Binary of 7 = 111
 Binary of Fractional part i.e. “.5” is =
 100000000…

.5*2 1

27
Convert Float to Floating Point Representation – 8 Bit
 (-7.5)10=(111. 10000...)2 (Move the fractional point or dot just
before the first one)
 (1.1110000...)2 *22
 (1.1110)2 *22 (4 bit mantissa)
 Bias 3; so, 3+2 = 5 = 101

1 1 0 1 1 1 1 0
-(1.1110)2*2(101)2
1 Bit 3 Bits 4 Bits
Sign Exponent Mantissa
is
Negative#

28
Binary Coded Decimal

29
BCD

• Encode each decimal digit separately and use as many bits as


necessary to represent the complete number exactly.
• To encode each of the digits from 0 through 9, four bits are necessary
• Since only four bits are needed to encode a BCD digit, two BCD digits
may be encoded in every byte. This is called packed BCD.
• 00000000 is 00 in BCD
• 10011001 is 99
• The advantage of BCD is that it yields absolutely correct results.
• Its disadvantage is that it uses a large amount of memory and results
in slow arithmetic operations.

30
General Concepts

31
Sign Bit (For signed Numbers)
Highest bit indicates the sign. 1 = negative, 0 = positive
sign bit

1 1 1 1 0 1 1 0
Negative

0 0 0 0 1 0 1 0 Positive

If highest digit of a hexadecimal is > 7, the value is negative


Examples: 8A and C5 are negative bytes
A21F and 9D03 are negative words
B1C42A00 is a negative double-word

32
Sign Extension

Step 1: Move the number into the lower-significant bits


Step 2: Fill all the remaining higher bits with the sign bit
• This will ensure that both magnitude and sign are correct
• Examples
• Sign-Extend 10110011 to 16 bits
10110011 = -77 11111111 10110011 = -77
• Sign-Extend 01100010 to 16 bits

01100010 = +98 00000000 01100010 = +98

• Infinite 0s can be added to the left of a positive number


• Infinite 1s can be added to the left of a negative number

33
Two's Complement of a Hexadecimal
• To form the two's complement of a hexadecimal
• Subtract each hexadecimal digit from 15
• Add 1
• Examples:
• 2's complement of 6A3D = 95C2 + 1 = 95C3
• 2's complement of 92F0 = 6D0F + 1 = 6D10
• 2's complement of FFFF = 0000 + 1 = 0001
• No need to convert hexadecimal to binary

34
Hexadecimal Subtraction
• When a borrow is required from the digit to the left, add 16
(decimal) to the current digit's value
16 + 5 = 21

-1 11
C675 C675
- A247 +
5DB9 (2's complement)
242E 242E (same result)
• Last Carry is ignored

35
Hexadecimal Subtraction Practice
Practice: The address of var1 is 00400B20. The address of the next variable after
var1 is 0040A06C. How many bytes are used by var1?

36
Hexadecimal Subtraction

37
Ranges of Signed Integers
The unsigned range is divided into two signed ranges for positive
and negative numbers

38
Character Storage
• Standard ASCII: 7-bit character codes (0 – 127)
• Extended ASCII: 8-bit character codes (0 – 255)
• Unicode: 16-bit character codes (0 – 65,535)
• Unicode standard represents a universal character set
• Defines codes for characters used in all major languages
• UTF-8: variable-length encoding used in HTML
• Encodes all Unicode characters
• Uses 1 byte for ASCII, but multiple bytes for other characters

39
Printable ASCII Codes

0 1 2 3 4 5 6 7 8 9 A B C D E F
2 space ! " # $ % & ' ( ) * + , - . /
3 0 1 2 3 4 5 6 7 8 9 : ; < = > ?
4 @ A B C D E F G H I J K L M N O
5 P Q R S T U V W X Y Z [ \ ] ^ _
6 ` a b c d e f g h i j k l m n o
7 p q r s t u v w x y z { | } ~ DEL

 Examples:
 ASCII code for space character = 20 (hex) = 32 (decimal)
 ASCII code for 'L' = 4C (hex) = 76 (decimal)
 ASCII code for 'a' = 61 (hex) = 97 (decimal)
Big-endian and Little-endian

• Big-endian is an order in which the "big end" (most significant value


in the sequence) is stored first, at the lowest storage address. Little-
endian is an order in which the "little end" (least significant value in
the sequence) is stored first.
• In a big-endian computer, the two bytes required for the hexadecimal
number 4F52 would be stored as 4F52 in storage.
• 4F is stored at storage address 1000,
• 52 will be at address 1001.
• In a little-endian system, it would be stored as 524F, with 52 at
address 1000 and 4F at 1001.

https://www.techtarget.com/searchnetworking/definition/big-endian-and-little-endian
https://uynguyen.github.io/2018/04/30/Big-Endian-vs-Little-Endian/
41
Example

• 1991994 (Decimal) = 001E653A (Hex)

42

You might also like