SlideShare a Scribd company logo
1 of 7
Download to read offline
I need help getting my code to work (code is at the bottom)
1.3. Overview
For this assignment you will be writing a program the asks the user to enter a decimal number
and stores it in IEEE 754 single-precision floating point representation. You will then parse the
IEEE 754 representation to extract the different pieces (sign, exponent, and significand)
You do not have to convert the input to IEEE 754 representation manually. Just use the syscall to
read a float. This will automatically store the value in IEEE 754 format for you. You can then
copy the value to a normal 32-bit register to perform the different bit manipulations to extract
each piece.
After the initial reading in of the floating point value and moving the value to a standard register
you should not use the floating point registers again. Do not use any of the floating point
operations to find the sign, or anything else.
All of the parsing and calculations should be done using various bit manipulations operations
(i.e. bitshifts, maskings, etc). Remember beyond the initial reading of the floating point value
and moving it to a standard register your program should not touch the floating point registers
again.
Your program does not need to handle any of the special cases of floating point numbers like
NaN, infinity, -infinity, 0 or -0.
1.4. Task 1: Main Procedure
Your first task is to collect is to create a loop for your program. Ask user to enter "Do you want
to do it again?" in a Dialog box. Hint: Use syscall 50. If the user answers YES repeat the process.
NO or Cancel, exit the program.
1.5. Task 2: Take User Input Procedure
void read_float()
Next, take user input and store it in memory. Prompt the user to enter a floating point value as a
decimal number. Then, store the input value in a single precision floating point register. In a
DialogBox (syscall 52), Display a string with info about the program ex: "Welcome to the " and
capture a user input. The input should be a floating point number.
You MUST store input into memory space (ieee). To do this, first move your captured input
from the f0 floating point register to a regular temporary register using the following call:
Now, you should be able to store the value into the ieee variable in memory.
The procedure should have the following signature:
1.6. Task 3: Print the sign
void print_sign(ieee)
Your next task is to create a procedure called print_sign that will extract and interpret the sign bit
of the IEEE 754 single precision floating point number. The floating point number is the value
you collected from Task 2.
Your function will take the value as a 32-bit number in a non-floating point register (i.e. $a0).
Remember, this value is stored in your ieee memory space. You should use bit manipulations
(i.e. shifting, masking, etc) to determine the value of the sign bit. If the sign bit is a 1 your
function should print the '-' character. If it is a 0 your function should print the '+' character.
The procedure should have the following signature:
Remember, the sign bit in an IEEE 754 floating point number is the most significant bit.
1.7. Task 4: Print the exponent
void parse_exp(ieee)
Your next task is to create a procedure called parse_exp that will extract and interpret the
exponent bits of the IEEE 754 single precision floating point number. Your function will take the
value as a 32-bit number in a non-floating point register (i.e. $a0). Next it will need to isolate the
bits representing the exponent and interpret those bits as an unsigned integer. Finally, you will
need to subtract the bias to recover the true exponent value as a signed integer. This is the value
that should be returned.
The procedure should have the following signature:
Remember the exponent is the 8 bits immediately following the sign bit.
1.8. Task 5: Print the significand
void print_significand(ieee)
Your next task is to create a procedure called print_significand that will extract the mantissa of
the IEEE 754 single precision floating point number. Your function will take the value as a 32-
bit number in a non-floating point register (i.e. $a0). Next it will need to isolate the bits
representing the mantissa.
The procedure should have the following signature:
Remember the mantissa is the low order 23 bits and you will need to add the implied 1.
1.9. Task 6: Print value store from Task 2
Finally, print the output you captured in Task 2 in IEEE 32 bit form
Here is what i have so far please help
# Author: Your name
# Date: The date
# Description: Program description
.macro print_str (%string)
la $a0, %string
li $v0, 4
syscall
.end_macro
.globl read_float, print_sign, parse_exp, print_exp, parse_mantissa, print_significand, main,
ieee_to_hex
# Data for the program goes here
.data
ieee: .word 0
again: .asciiz "Do you want to do it again?"
prompt: .asciiz "Enter an IEEE 754 floating point number in decimal form: "
res_sign: .asciiz "nThe sign is: "
new_line: .asciiz "n"
expoBias: .asciiz "nExpo with bias: "
expoNoBias: .asciiz "nExpo without bias: "
manti: .asciiz "nMantissa: "
sieee: .asciiz "nIEEE-754 Single Prec: "
.text
main:
# Task 2: Call read_float()
jal read_float
while:
# Task 3: Call print_sign(ieee)
jal print_sign
# Task 4: Call print_exp(ieee)
jal print_exp
# Task 5: Call print_significand(ieee)
jal parse_mantissa
jal print_significand
# Task 6: Print IEEE number in hex
li $v0, 34
lw $a0, ieee
syscall
li $v0, 4
la $a0, sieee
syscall
li $v0, 34
lw $a0, ieee
syscall
li $v0, 16
syscall
# Task 1: Try again pop-up
li $v0, 52
la $a0, again
syscall
li $v0, 5
syscall
mfc1 $f0, $f0
mfc1 $t0, $f0
sw $t0, ieee
li $v0, 34
lw $a0, ieee
syscall
li $v0, 4
la $a0, new_line
syscall
li $v0, 16
syscall
beq $v0, 1, exit_main
beq $v0, 2, while
exit_main:
li $v0, 10
syscall
# Task 2: Take User Input Procedure
################################################################
# Procedure void read_float()
# Functional Description: Reads input from user using a pop up
# gui. It stores the capture value in ieee memory space
# Argument parameters: None
# Return Value: None
################################################################
# Register Usage:
# $f0: Input float value
# $t0: Temp storage for input value
# $a0: Prompt string address
read_float:
li $v0, 52
la $a0, prompt
syscall
li $v0, 5
syscall
mfc1 $f0, $f0
mfc1 $t0, $f0
sw $t0, ieee
jr $ra
# Task
# Task 3: Print the sign
################################################################
# Procedure void print_sign(ieee)
print_sign:
lw $t0, ieee
srl $t0, $t0, 31
beqz $t0, print_sign_positive
print_str res_sign
li $v0, 1
li $a0, '-'
syscall
j print_sign_end
print_sign_positive:
print_str res_sign
li $v0, 1
li $a0, '+'
syscall
print_sign_end:
jr $ra
# Task 4: Print the exponent
################################################################
# Procedure void print_exp(ieee)
print_exp:
print_str(expoBias)
lw $t1, ieee
andi $t0, $t1, 0x7f800000 # mask out the sign bit and mantissa
srl $t0, $t0, 23 # shift the exponent to the rightmost bit
addi $t0, $t0, -127 # subtract the exponent bias
li $v0, 34 # syscall to print a 32-bit hex number
move $a0, $t0
syscall
print_str(expoNoBias)
lw $t1, ieee
andi $t0, $t1, 0x7f800000 # mask out the sign bit and mantissa
srl $t0, $t0, 23 # shift the exponent to the rightmost bit
li $v0, 34 # syscall to print a 32-bit hex number
move $a0, $t0
syscall
print_str(new_line)
jr $ra
# Task 5: Print the significand
################################################################
# Procedure void print_significand(ieee)
parse_mantissa:
lw $t0, ieee
li $t1, 0x007fffff
and $t0, $t0, $t1
sll $t0, $t0, 1
or $t0, $t0, 0x80000000
mtc1 $t0, $f0
jr $ra
print_significand:
la $a0, manti
print_str($a0)
li $v0, 2
syscall
li $v0, 4
la $a0, new_line
syscall
jr $ra
# Task 6: print value store from task 2
#print output you captured in task 2 in IEEE 32 bit form
print_str sieee
li $v0, 34
lw $a0, ieee
syscall
li $v0, 16
syscall
exit_main:
li $v0, 10 # 10 is the exit program syscall
syscall # execute call In the tool below, "significand" is another name for the mantissa.
Input Waldo Weber CS2810 Spring2018 Welcome to the IEEE Parser Enter a decimal number:
OK Cancel
Exponent 00000000
Significand
1.9.1. Sample Output Negative sign: 0x00000001 Expo with bias: 0x00000081 Expo without
bias: 0x00000002 Mantissa: Ox00180000 IEEE-754 Single Prec: 0xc0980000
1.9.1.1. If your answer is YES Continue running the program Negative sign: 0x00000001 Expo
with bias: 0x00000081 Expo without bias: 0x00000002 Mantissa: Ox00180000 IEEE-754 Single
Prec: Oxc0980000 Expo without bias: 000000002 Mantissa: 0x00180000 IEEE-754 Single Prec:
Oxc0980000 Positive sign: 000000000 Expo with bias: 0x00000086 Expo without bias:
0x00000007 Mantissa: Ox00484000 IEEE-754 Single Prec: 0x43484000 1.9.1.2. If your answer
is NO Exit the program IEEE-754 Single Prec: 0x43484000 -- program is finished running .-

More Related Content

Similar to I need help getting my code to work (code is at the bottom)1.3.pdf

Lecture 2 coal sping12
Lecture 2 coal sping12Lecture 2 coal sping12
Lecture 2 coal sping12
Rabia Khalid
 

Similar to I need help getting my code to work (code is at the bottom)1.3.pdf (20)

GSP 215 RANK Introduction Education--gsp215rank.com
GSP 215 RANK Introduction Education--gsp215rank.comGSP 215 RANK Introduction Education--gsp215rank.com
GSP 215 RANK Introduction Education--gsp215rank.com
 
GSP 215 RANK Education Counseling--gsp215rank.com
 GSP 215 RANK Education Counseling--gsp215rank.com GSP 215 RANK Education Counseling--gsp215rank.com
GSP 215 RANK Education Counseling--gsp215rank.com
 
GSP 215 RANK Education Planning--gsp215rank.com
GSP 215 RANK Education Planning--gsp215rank.comGSP 215 RANK Education Planning--gsp215rank.com
GSP 215 RANK Education Planning--gsp215rank.com
 
Lecture 2 coal sping12
Lecture 2 coal sping12Lecture 2 coal sping12
Lecture 2 coal sping12
 
python lab programs.pdf
python lab programs.pdfpython lab programs.pdf
python lab programs.pdf
 
GSP 215 RANK Education Your Life--gsp215rank.com
GSP 215 RANK Education Your Life--gsp215rank.comGSP 215 RANK Education Your Life--gsp215rank.com
GSP 215 RANK Education Your Life--gsp215rank.com
 
GSP 215 RANK Lessons in Excellence-- gsp215rank.com
GSP 215 RANK Lessons in Excellence-- gsp215rank.comGSP 215 RANK Lessons in Excellence-- gsp215rank.com
GSP 215 RANK Lessons in Excellence-- gsp215rank.com
 
GSP 215 RANK Inspiring Innovation--gsp215rank.com
GSP 215 RANK Inspiring Innovation--gsp215rank.com GSP 215 RANK Inspiring Innovation--gsp215rank.com
GSP 215 RANK Inspiring Innovation--gsp215rank.com
 
lecture 2.pptx
lecture 2.pptxlecture 2.pptx
lecture 2.pptx
 
Gsp 215 Effective Communication / snaptutorial.com
Gsp 215  Effective Communication / snaptutorial.comGsp 215  Effective Communication / snaptutorial.com
Gsp 215 Effective Communication / snaptutorial.com
 
GSP 215 RANK Education Counseling -- gsp215rank.com
GSP 215 RANK Education Counseling -- gsp215rank.comGSP 215 RANK Education Counseling -- gsp215rank.com
GSP 215 RANK Education Counseling -- gsp215rank.com
 
GSP 215 Inspiring Innovation/tutorialrank.com
GSP 215 Inspiring Innovation/tutorialrank.comGSP 215 Inspiring Innovation/tutorialrank.com
GSP 215 Inspiring Innovation/tutorialrank.com
 
GSP 215 Enhance teaching/tutorialrank.com
 GSP 215 Enhance teaching/tutorialrank.com GSP 215 Enhance teaching/tutorialrank.com
GSP 215 Enhance teaching/tutorialrank.com
 
Gsp 215 Exceptional Education / snaptutorial.com
Gsp 215  Exceptional Education / snaptutorial.comGsp 215  Exceptional Education / snaptutorial.com
Gsp 215 Exceptional Education / snaptutorial.com
 
Gsp 215 Enthusiastic Study / snaptutorial.com
Gsp 215 Enthusiastic Study / snaptutorial.comGsp 215 Enthusiastic Study / snaptutorial.com
Gsp 215 Enthusiastic Study / snaptutorial.com
 
GSP 215 Technology levels--snaptutorial.com
GSP 215 Technology levels--snaptutorial.comGSP 215 Technology levels--snaptutorial.com
GSP 215 Technology levels--snaptutorial.com
 
Gsp 215 Massive Success / snaptutorial.com
Gsp 215  Massive Success / snaptutorial.comGsp 215  Massive Success / snaptutorial.com
Gsp 215 Massive Success / snaptutorial.com
 
GSP 215 Effective Communication - tutorialrank.com
GSP 215  Effective Communication - tutorialrank.comGSP 215  Effective Communication - tutorialrank.com
GSP 215 Effective Communication - tutorialrank.com
 
GSP 215 RANK Become Exceptional--gsp215rank.com
GSP 215 RANK Become Exceptional--gsp215rank.comGSP 215 RANK Become Exceptional--gsp215rank.com
GSP 215 RANK Become Exceptional--gsp215rank.com
 
GSP 215 RANK Achievement Education--gsp215rank.com
GSP 215 RANK Achievement Education--gsp215rank.comGSP 215 RANK Achievement Education--gsp215rank.com
GSP 215 RANK Achievement Education--gsp215rank.com
 

More from pratyushraj61

I need an explanation on what the function of the number 1.428 in .pdf
I need an explanation on what the function of the number 1.428 in .pdfI need an explanation on what the function of the number 1.428 in .pdf
I need an explanation on what the function of the number 1.428 in .pdf
pratyushraj61
 
Here is my code for a linefile editor import java.io.BufferedRea.pdf
Here is my code for a linefile editor import java.io.BufferedRea.pdfHere is my code for a linefile editor import java.io.BufferedRea.pdf
Here is my code for a linefile editor import java.io.BufferedRea.pdf
pratyushraj61
 
I am wondering if i can implement these use cases to make a google f.pdf
I am wondering if i can implement these use cases to make a google f.pdfI am wondering if i can implement these use cases to make a google f.pdf
I am wondering if i can implement these use cases to make a google f.pdf
pratyushraj61
 

More from pratyushraj61 (20)

helphelp Regarding the numerou.pdf
helphelp Regarding the numerou.pdfhelphelp Regarding the numerou.pdf
helphelp Regarding the numerou.pdf
 
Hello. Im having trouble trying to set the condition where once the .pdf
Hello. Im having trouble trying to set the condition where once the .pdfHello. Im having trouble trying to set the condition where once the .pdf
Hello. Im having trouble trying to set the condition where once the .pdf
 
Henrich is a single taxpayer. In 2022, his taxable income is $478,0.pdf
Henrich is a single taxpayer.  In 2022, his taxable income is $478,0.pdfHenrich is a single taxpayer.  In 2022, his taxable income is $478,0.pdf
Henrich is a single taxpayer. In 2022, his taxable income is $478,0.pdf
 
Hi could you focus on the isohyetal method and thiessen polygon me.pdf
Hi could you focus on the isohyetal method and thiessen polygon me.pdfHi could you focus on the isohyetal method and thiessen polygon me.pdf
Hi could you focus on the isohyetal method and thiessen polygon me.pdf
 
helpppppp((( The difference between an embedded object and a linked.pdf
helpppppp((( The difference between an embedded object and a linked.pdfhelpppppp((( The difference between an embedded object and a linked.pdf
helpppppp((( The difference between an embedded object and a linked.pdf
 
help on this thanks. Phalaropes are shore birds with brightly col.pdf
help on this thanks.  Phalaropes are shore birds with brightly col.pdfhelp on this thanks.  Phalaropes are shore birds with brightly col.pdf
help on this thanks. Phalaropes are shore birds with brightly col.pdf
 
I have an independent food delivery platform having a lot of differe.pdf
I have an independent food delivery platform having a lot of differe.pdfI have an independent food delivery platform having a lot of differe.pdf
I have an independent food delivery platform having a lot of differe.pdf
 
i need programingi need programing ai. Create o Va opplication t.pdf
i need programingi need programing ai. Create o Va opplication t.pdfi need programingi need programing ai. Create o Va opplication t.pdf
i need programingi need programing ai. Create o Va opplication t.pdf
 
I need help with making a program that can be part of a google forms.pdf
I need help with making a program that can be part of a google forms.pdfI need help with making a program that can be part of a google forms.pdf
I need help with making a program that can be part of a google forms.pdf
 
I need help fixing my assembly program please, I keep getting a segm.pdf
I need help fixing my assembly program please, I keep getting a segm.pdfI need help fixing my assembly program please, I keep getting a segm.pdf
I need help fixing my assembly program please, I keep getting a segm.pdf
 
Hewitt Packaging Companynin �denmemi 14 kupon faiz oranyla 1.000 A.pdf
Hewitt Packaging Companynin �denmemi 14 kupon faiz oranyla 1.000 A.pdfHewitt Packaging Companynin �denmemi 14 kupon faiz oranyla 1.000 A.pdf
Hewitt Packaging Companynin �denmemi 14 kupon faiz oranyla 1.000 A.pdf
 
I need an explanation on what the function of the number 1.428 in .pdf
I need an explanation on what the function of the number 1.428 in .pdfI need an explanation on what the function of the number 1.428 in .pdf
I need an explanation on what the function of the number 1.428 in .pdf
 
I need help being able to enable different voting types such as publ.pdf
I need help being able to enable different voting types such as publ.pdfI need help being able to enable different voting types such as publ.pdf
I need help being able to enable different voting types such as publ.pdf
 
I have this Koch Python code but isnt working. Can some please revi.pdf
I have this Koch Python code but isnt working. Can some please revi.pdfI have this Koch Python code but isnt working. Can some please revi.pdf
I have this Koch Python code but isnt working. Can some please revi.pdf
 
How do zoned reserves manage relations with local people1. Zone.pdf
How do zoned reserves manage relations with local people1. Zone.pdfHow do zoned reserves manage relations with local people1. Zone.pdf
How do zoned reserves manage relations with local people1. Zone.pdf
 
I have included the person.h file code. 1-4 In a file called functio.pdf
I have included the person.h file code. 1-4 In a file called functio.pdfI have included the person.h file code. 1-4 In a file called functio.pdf
I have included the person.h file code. 1-4 In a file called functio.pdf
 
Here is my code for a linefile editor import java.io.BufferedRea.pdf
Here is my code for a linefile editor import java.io.BufferedRea.pdfHere is my code for a linefile editor import java.io.BufferedRea.pdf
Here is my code for a linefile editor import java.io.BufferedRea.pdf
 
I have a question regarding extreme value analysis.I fitted a gene.pdf
I have a question regarding extreme value analysis.I fitted a gene.pdfI have a question regarding extreme value analysis.I fitted a gene.pdf
I have a question regarding extreme value analysis.I fitted a gene.pdf
 
I concur, technology is so engrained in our day-to-day activities (w.pdf
I concur, technology is so engrained in our day-to-day activities (w.pdfI concur, technology is so engrained in our day-to-day activities (w.pdf
I concur, technology is so engrained in our day-to-day activities (w.pdf
 
I am wondering if i can implement these use cases to make a google f.pdf
I am wondering if i can implement these use cases to make a google f.pdfI am wondering if i can implement these use cases to make a google f.pdf
I am wondering if i can implement these use cases to make a google f.pdf
 

Recently uploaded

Recently uploaded (20)

FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
How to Manage Call for Tendor in Odoo 17
How to Manage Call for Tendor in Odoo 17How to Manage Call for Tendor in Odoo 17
How to Manage Call for Tendor in Odoo 17
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Philosophy of china and it's charactistics
Philosophy of china and it's charactisticsPhilosophy of china and it's charactistics
Philosophy of china and it's charactistics
 
Tatlong Kwento ni Lola basyang-1.pdf arts
Tatlong Kwento ni Lola basyang-1.pdf artsTatlong Kwento ni Lola basyang-1.pdf arts
Tatlong Kwento ni Lola basyang-1.pdf arts
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
AIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.pptAIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.ppt
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 
How to Add a Tool Tip to a Field in Odoo 17
How to Add a Tool Tip to a Field in Odoo 17How to Add a Tool Tip to a Field in Odoo 17
How to Add a Tool Tip to a Field in Odoo 17
 
latest AZ-104 Exam Questions and Answers
latest AZ-104 Exam Questions and Answerslatest AZ-104 Exam Questions and Answers
latest AZ-104 Exam Questions and Answers
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 

I need help getting my code to work (code is at the bottom)1.3.pdf

  • 1. I need help getting my code to work (code is at the bottom) 1.3. Overview For this assignment you will be writing a program the asks the user to enter a decimal number and stores it in IEEE 754 single-precision floating point representation. You will then parse the IEEE 754 representation to extract the different pieces (sign, exponent, and significand) You do not have to convert the input to IEEE 754 representation manually. Just use the syscall to read a float. This will automatically store the value in IEEE 754 format for you. You can then copy the value to a normal 32-bit register to perform the different bit manipulations to extract each piece. After the initial reading in of the floating point value and moving the value to a standard register you should not use the floating point registers again. Do not use any of the floating point operations to find the sign, or anything else. All of the parsing and calculations should be done using various bit manipulations operations (i.e. bitshifts, maskings, etc). Remember beyond the initial reading of the floating point value and moving it to a standard register your program should not touch the floating point registers again. Your program does not need to handle any of the special cases of floating point numbers like NaN, infinity, -infinity, 0 or -0. 1.4. Task 1: Main Procedure Your first task is to collect is to create a loop for your program. Ask user to enter "Do you want to do it again?" in a Dialog box. Hint: Use syscall 50. If the user answers YES repeat the process. NO or Cancel, exit the program. 1.5. Task 2: Take User Input Procedure void read_float() Next, take user input and store it in memory. Prompt the user to enter a floating point value as a decimal number. Then, store the input value in a single precision floating point register. In a DialogBox (syscall 52), Display a string with info about the program ex: "Welcome to the " and capture a user input. The input should be a floating point number. You MUST store input into memory space (ieee). To do this, first move your captured input from the f0 floating point register to a regular temporary register using the following call: Now, you should be able to store the value into the ieee variable in memory. The procedure should have the following signature: 1.6. Task 3: Print the sign
  • 2. void print_sign(ieee) Your next task is to create a procedure called print_sign that will extract and interpret the sign bit of the IEEE 754 single precision floating point number. The floating point number is the value you collected from Task 2. Your function will take the value as a 32-bit number in a non-floating point register (i.e. $a0). Remember, this value is stored in your ieee memory space. You should use bit manipulations (i.e. shifting, masking, etc) to determine the value of the sign bit. If the sign bit is a 1 your function should print the '-' character. If it is a 0 your function should print the '+' character. The procedure should have the following signature: Remember, the sign bit in an IEEE 754 floating point number is the most significant bit. 1.7. Task 4: Print the exponent void parse_exp(ieee) Your next task is to create a procedure called parse_exp that will extract and interpret the exponent bits of the IEEE 754 single precision floating point number. Your function will take the value as a 32-bit number in a non-floating point register (i.e. $a0). Next it will need to isolate the bits representing the exponent and interpret those bits as an unsigned integer. Finally, you will need to subtract the bias to recover the true exponent value as a signed integer. This is the value that should be returned. The procedure should have the following signature: Remember the exponent is the 8 bits immediately following the sign bit. 1.8. Task 5: Print the significand void print_significand(ieee) Your next task is to create a procedure called print_significand that will extract the mantissa of the IEEE 754 single precision floating point number. Your function will take the value as a 32- bit number in a non-floating point register (i.e. $a0). Next it will need to isolate the bits representing the mantissa. The procedure should have the following signature: Remember the mantissa is the low order 23 bits and you will need to add the implied 1. 1.9. Task 6: Print value store from Task 2 Finally, print the output you captured in Task 2 in IEEE 32 bit form Here is what i have so far please help # Author: Your name # Date: The date # Description: Program description .macro print_str (%string) la $a0, %string
  • 3. li $v0, 4 syscall .end_macro .globl read_float, print_sign, parse_exp, print_exp, parse_mantissa, print_significand, main, ieee_to_hex # Data for the program goes here .data ieee: .word 0 again: .asciiz "Do you want to do it again?" prompt: .asciiz "Enter an IEEE 754 floating point number in decimal form: " res_sign: .asciiz "nThe sign is: " new_line: .asciiz "n" expoBias: .asciiz "nExpo with bias: " expoNoBias: .asciiz "nExpo without bias: " manti: .asciiz "nMantissa: " sieee: .asciiz "nIEEE-754 Single Prec: " .text main: # Task 2: Call read_float() jal read_float while: # Task 3: Call print_sign(ieee) jal print_sign # Task 4: Call print_exp(ieee) jal print_exp # Task 5: Call print_significand(ieee) jal parse_mantissa jal print_significand # Task 6: Print IEEE number in hex li $v0, 34 lw $a0, ieee syscall li $v0, 4 la $a0, sieee syscall li $v0, 34
  • 4. lw $a0, ieee syscall li $v0, 16 syscall # Task 1: Try again pop-up li $v0, 52 la $a0, again syscall li $v0, 5 syscall mfc1 $f0, $f0 mfc1 $t0, $f0 sw $t0, ieee li $v0, 34 lw $a0, ieee syscall li $v0, 4 la $a0, new_line syscall li $v0, 16 syscall beq $v0, 1, exit_main beq $v0, 2, while exit_main: li $v0, 10 syscall # Task 2: Take User Input Procedure ################################################################ # Procedure void read_float() # Functional Description: Reads input from user using a pop up # gui. It stores the capture value in ieee memory space # Argument parameters: None # Return Value: None ################################################################ # Register Usage: # $f0: Input float value
  • 5. # $t0: Temp storage for input value # $a0: Prompt string address read_float: li $v0, 52 la $a0, prompt syscall li $v0, 5 syscall mfc1 $f0, $f0 mfc1 $t0, $f0 sw $t0, ieee jr $ra # Task # Task 3: Print the sign ################################################################ # Procedure void print_sign(ieee) print_sign: lw $t0, ieee srl $t0, $t0, 31 beqz $t0, print_sign_positive print_str res_sign li $v0, 1 li $a0, '-' syscall j print_sign_end print_sign_positive: print_str res_sign li $v0, 1 li $a0, '+' syscall print_sign_end: jr $ra # Task 4: Print the exponent ################################################################ # Procedure void print_exp(ieee)
  • 6. print_exp: print_str(expoBias) lw $t1, ieee andi $t0, $t1, 0x7f800000 # mask out the sign bit and mantissa srl $t0, $t0, 23 # shift the exponent to the rightmost bit addi $t0, $t0, -127 # subtract the exponent bias li $v0, 34 # syscall to print a 32-bit hex number move $a0, $t0 syscall print_str(expoNoBias) lw $t1, ieee andi $t0, $t1, 0x7f800000 # mask out the sign bit and mantissa srl $t0, $t0, 23 # shift the exponent to the rightmost bit li $v0, 34 # syscall to print a 32-bit hex number move $a0, $t0 syscall print_str(new_line) jr $ra # Task 5: Print the significand ################################################################ # Procedure void print_significand(ieee) parse_mantissa: lw $t0, ieee li $t1, 0x007fffff and $t0, $t0, $t1 sll $t0, $t0, 1 or $t0, $t0, 0x80000000 mtc1 $t0, $f0 jr $ra print_significand: la $a0, manti print_str($a0) li $v0, 2 syscall li $v0, 4
  • 7. la $a0, new_line syscall jr $ra # Task 6: print value store from task 2 #print output you captured in task 2 in IEEE 32 bit form print_str sieee li $v0, 34 lw $a0, ieee syscall li $v0, 16 syscall exit_main: li $v0, 10 # 10 is the exit program syscall syscall # execute call In the tool below, "significand" is another name for the mantissa. Input Waldo Weber CS2810 Spring2018 Welcome to the IEEE Parser Enter a decimal number: OK Cancel Exponent 00000000 Significand 1.9.1. Sample Output Negative sign: 0x00000001 Expo with bias: 0x00000081 Expo without bias: 0x00000002 Mantissa: Ox00180000 IEEE-754 Single Prec: 0xc0980000 1.9.1.1. If your answer is YES Continue running the program Negative sign: 0x00000001 Expo with bias: 0x00000081 Expo without bias: 0x00000002 Mantissa: Ox00180000 IEEE-754 Single Prec: Oxc0980000 Expo without bias: 000000002 Mantissa: 0x00180000 IEEE-754 Single Prec: Oxc0980000 Positive sign: 000000000 Expo with bias: 0x00000086 Expo without bias: 0x00000007 Mantissa: Ox00484000 IEEE-754 Single Prec: 0x43484000 1.9.1.2. If your answer is NO Exit the program IEEE-754 Single Prec: 0x43484000 -- program is finished running .-