0% found this document useful (0 votes)
11 views9 pages

CC2032 COAL Lab # 07

The document discusses floating point representation and arithmetic in MIPS. It explains IEEE 754 standard for single precision floating point numbers and shows representation format. It also demonstrates simple MIPS programs for floating point addition and subtraction, showing usage of floating point registers and instructions. The tasks analyze output of programs by calculating expected results and hexadecimal values in registers.

Uploaded by

Tanzeela Shakeel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views9 pages

CC2032 COAL Lab # 07

The document discusses floating point representation and arithmetic in MIPS. It explains IEEE 754 standard for single precision floating point numbers and shows representation format. It also demonstrates simple MIPS programs for floating point addition and subtraction, showing usage of floating point registers and instructions. The tasks analyze output of programs by calculating expected results and hexadecimal values in registers.

Uploaded by

Tanzeela Shakeel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

University of Management and Technology

Department of Artificial Intelligence


CC2032L Computer Organization and Assembly Language Lab
Spring 2024
Participant ID: Participant Name:

Date: Total Marks: Obtained Marks:

Lab # 07: Floating Arithmetic in MIPS


1. Learning Objectives
 Understand the basic principles of single-precision floating-point representation
according to the IEEE 754 standard.
 Explain the execution flow of a simple MIPS program that performs floating-point
addition
2. Floating Point Representation
Computer arithmetic supports floating point as it represents numbers in which the binary point is
not fixed, as it is for integers. Here are some examples:
3.14159265…ten (pi)
2.71828…ten (e)
0.000000001ten or 1.0ten × 10−9 (seconds in a nanosecond)
3,155,760,000 ten or 3.15576ten × 109 (seconds in a typical century)
The last number cannot be represented as an integer data type. Thus, its alternative is scientific
notation which has single decimal digit to the left of decimal point. A number in scientific
notation that has no leading 0s is called a normalized number. For example, 1.0 x 10 -9 is a
normalized scientific notation.
A floating point decimal number can also be represented as floating point binary such as
1.xxxxxxxxx two x 2yyyy
It can be noticed that every binary number always starts from 1, xxxxxxx represents the
significand and yyyy represents the exponent. The IEEE 754 floating point number representation
is commonly used in computer and given below:
where “s” is Sign Bit and s=0 for positive and s=1 for negative numbers. Exponent is 8-bit field
which is actually biased exponent, and its formula is given below
Biased Exponents = 127+yyyy
There are 23-bits to represents the magnitude of significand. This number is actually 24-bit,
however, as each binary number always starts from ‘1’ thus the initial ‘1’ has been omitted to
increase the accuracy of floating point number.
In general, floating-point numbers are of the form
(-1)S x F x 2E
This chosen size of exponent and fraction give MIPS computer arithmetic an extraordinary
range. Fractions almost as small as 2.0ten x 10-38 and numbers almost as large as 2.0ten x 10+38 can
be represented in a computer.
There could be overflow and underflow in floating point as well as in integer arithmetic.
Overflow occurs when the exponents is too large to be represented in the exponent field.
Underflow occurs when the negative exponent is beyond the range of exponent field.
One way to reduce chances of underflow or overflow is to o ffer another format that has a larger
exponent. In C this number is called double, and operations on\doubles are called double
precision floating-point arithmetic; single precision floating point is the name of the earlier
format. The representation of a double precision floating-point number takes two MIPS words,
where s is still the sign of the number, exponent is the value of the 11-bit exponent field, and
fraction is the 52-bit number in the fraction field. Double precision allows numbers almost as
small as 2.0ten x 10x-308 and almost as large as 2.0ten x 10+308

The encodings of IEEE 754 floating-point numbers are shown below. Other features of IEEE 754
are special symbols to represent unusual events. For example, instead of interrupting on a divide
by 0, software can set the result to a bit pattern representing -∞ or +∞; the largest exponent is
reserved for these special symbols. When the programmer prints the results, the program will
print an infinity symbol. IEEE 754 even has a symbol for the result of invalid operations, such as
0/0 or subtracting infinity from infinity. This symbol is NaN, for Not a Number. The purpose of
NaNs is to allow programmers to postpone some tests and decisions to a later time in the
program when they are convenient.
3. Floating-Point Instructions in MIPS
MIPS supports the IEEE 754 single precision and double precision formats with these
instructions:

4. Floating Point Registers in MIPS


The MIPS designers decided to add separate floating-point registers—called $f0, $f1, $f2,
…—used either for single precision or double precision. Hence, they included separate loads and
stores for floating-point registers: lwc1 and swc1. The base registers for floating-point data
transfers which are used for addresses remain integer registers. The MIPS code to load two
single precision numbers from memory, add them, and then store the sum might look like this:
lwc1 $f4,c($sp) # Load 32-bit F.P. number into F4
lwc1 $f6,a($sp) # Load 32-bit F.P. number into F6
add.s $f2,$f4,$f6 # F2 = F4 + F6 single precision
swc1 $f2,b($sp) # Store 32-bit F.P. number from F2
A double precision register is really an even-odd pair of single precision registers, using the even
register number as its name. Thus, the pair of single precision registers $f2 and $f3 also form
the double precision register named $f2.

5. Binary Floating-Point Addition


Let’s Add 1.000 x 2-1 and -1.110 x 2-2. Assume that there is 4-bit precision. The binary floating
point addition is four step process which are given below:
Step 1. The significand of the number with the lesser exponent (1.11 x 2 -2) is shifted right until
its exponent matches the larger number - 1.110 x 2-2 = - 0.111x 2-1
Step 2. Add the significands:
1.000 x 2-1 + (-0.111 x 2-1) = 1.000 x 2-1+ 1.111 x 2-1 = 0.001 x 2-1
It can be observed that to add two signed number, 2’s complement of negative number
has been taken.
Step 3. Normalize the sum, checking for overflow or underflow:
0.001 x 2-1 = 0.001 x 2-2 = 0.001 x 2-3 = 0.001 x 2-4
Since 127 >= 4 >= -126, there is no overflow or underflow
The biased exponent = 127-4 = 123, which is between 1 and 254, the smallest and largest
unreserved biased exponents
Step 4. Round the sum:
0.001 x 2-4
The sum already fits exactly in 4 bits, so there is no change to the bits due to rounding.

6. Task # 1: Run the following MIPS32 program and observe the values in
floating registers.
.data
num1: .float 3.5 # First floating-point number
num2: .float 2.25 # Second floating-point number
result: .float 0 # Variable to store the result

.text
.globl main
main:
# Load the first floating-point number into f0
lwc1 $f0, num1

# Load the second floating-point number into f1


lwc1 $f1, num2

# Add the two floating-point numbers


add.s $f2, $f0, $f1

# Store the result back to memory


swc1 $f2, result

# Exit program
li $v0, 10
syscall
Observation and Analysis:
Q1. What is expected result after addition (using calculator)?
Q2. Calculate the single precision floating point representation of given operands: A = 3.5
and B = 2.25. Present the calculated result in hexadecimal format and match with the value
stored in data memory.

Operand A
Sign Exponent Fraction

Hexadecimal =
Operand B
Sign Exponent Fraction

Hexadecimal =

Q3. What is value of floating point addition result stored in $f2 floating point register?

Q4. Convert the result of $f2Hex into decimal and verify if the result match the calculated
value of operands.

Q5. What is there need of $at general purpose register?

Q6. After the program finished, at which data memory location the result of addition is
stored? How is that address computed?
7. Task # 1: Run the following MIPS32 program and observe the values in
floating registers.
.data
num1: .float 7.5 # First floating-point number
num2: .float 3.25 # Second floating-point number
result: .float 0 # Variable to store the result

.text
.globl main
main:
# Load the first floating-point number into f0
lwc1 $f0, num1

# Load the second floating-point number into f1


lwc1 $f1, num2

# Add the two floating-point numbers


sub.s $f2, $f0, $f1

# Store the result back to memory


swc1 $f2, result

# Exit program
li $v0, 10
syscall
Observation and Analysis:
Q1. What is expected result after subtraction (using calculator)?

Q2. Calculate the single precision floating point representation of given operands: A = 3.5
and B = 2.25. Present the calculated result in hexadecimal format and match with the value
stored in data memory.

Operand A
Sign Exponent Fraction

Hexadecimal =
Operand B
Sign Exponent Fraction

Hexadecimal =
Q3. What is value of floating point addition result stored in $f2 floating point register?

Q4. Convert the result of $f2Hex into decimal and verify if the result match the calculated
value of operands.

You might also like