Question

Abstract Your goal for this project is to implement software emulation of floating point addition for 32-bit (single-precision) floating point numbers in MIPs.

Input/Output Your program will prompt the user for two floating point numbers. It will then compute and display the sum. Here’s example I/O from four runs (you only need to prompt once per execution run):

Enter a floating-point value: 1 Enter a floating-point value: 1 2.000000000000000000

Enter a floating-point value: 2.2 Enter a floating-point value: 1.4 3.599999904632568400

Issues to Resolve Here’s a few issues:  How will you deal with negative values?  How will your normalizing algorithm work?  What’s the easiest way to access bit fields within a word?

*You may not use any floating-point instructions for this project!!*

I have done the same in integers but need some help in floating point without using them! .data st1: .asciiz "\nIn binary:\n" st2: .asciiz "\nEnter 1st Integer:" st3: .asciiz "\nEnter 2nd Integer:" st4: .asciiz "\nYour answer is: " st5: .asciiz "\n--------------------------------\n" st6: .asciiz "\n"

.text

main: 

Prompt user to input first integer

la $a0,st2 # Put the address of the string in $a0   
li $v0, 4
syscall
li $v0, 5  # Code for input integer
syscall
move $s1, $v0 #storing first integer in s1

Prompt user to input first integer

la $a0,st3 # Put the address of the string in $a0
 li $v0, 4
syscall
li $v0, 5  # Code for input integer
syscall
move $s2, $v0 #storing second integer in s2

Adding integers

add $s0,$s2,$s1 #add and store in t3

Display result

la $a0,st4 #text to display 
li $v0,4
syscall  
li $v0,1     #for printing int
 move $a0,$s0 # move s0 to a0 to print s0
syscall
la $a0,st1
li $v0,4
syscall

Move in temporary registers

move $t3,$s0   
move $t2,$s2
move $t1,$s1

Counter for first number to be printed in binary

li $s5,32       # set up counter
loop1: 
    rol  $t1,$t1,1   #roll the bit left by on bit high to low
    and  $t0,$t1,1   #mask off low bit
    add  $t0,$t0,48  #combine t0 with 48 to form 1 or 0
    move $a0,$t0     #output ascii character
    li   $v0,11
    syscall
    li $t5,1
    sub $s5,$s5,$t5  #decrement counter
    bne $s5,$zero,loop1 #keep loop if not zero

Print a line

la $a0,st6  
li $v0,4
syscall  

Counter for second number in binary

li $s5,32     
loop2: 
    rol  $t2,$t2,1   #roll the bit left by on bit high to low
    and  $t0,$t2,1   #mask off low bit
    add  $t0,$t0,48  #combine t0 with 48 to form 1 or 0
    move $a0,$t0     #output ascii character
    li   $v0,11
    syscall
    li $t5,1
    sub $s5,$s5,$t5  #decrement counter
    bne $s5,$zero,loop2 #keep loop if not zero

Print a dotted line

la $a0,st5 #line 
li $v0,4
syscall  

Counter for Result in binary

li $s5,32       
loop: 
    rol  $t3,$t3,1   #roll the bit left by on bit high to low
    and  $t0,$t3,1   #mask off low bit
    add  $t0,$t0,48  #combine t0 with 48 to form 1 or 0
    move $a0,$t0     #output ascii character
    li   $v0,11
    syscall
    li $t5,1
    sub $s5,$s5,$t5  #decrement counter
    bne $s5,$zero,loop #keep loop if not zero

Close the Program

li $v0,10 #close the program
syscall

.end main

Was it helpful?

Solution

1- Use IEEE 754 to represent your floating point numbers 2- Add up the exponents, then add up the significands, check if you need to increase the exponent 3- Deal with negative signs (2's complement, single bit the first one represents sign)

This is a pretty easy problem and I agree with the comments above, I just thought you could use some good hints Good luck!

OTHER TIPS

.data
st1: .asciiz "\nIn binary:\n"
st2: .asciiz "\nEnter 1st Integer:"
st3: .asciiz "\nEnter 2nd Integer:"
st4: .asciiz "\nYour answer is: "
st5: .asciiz "\n--------------------------------\n"
st6: .asciiz "\n"

.text

main: 

Prompt user to input first integer

la $a0,st2 # Put the address of the string in $a0   
li $v0, 4
syscall
li $v0, 5  # Code for input integer
syscall
move $s1, $v0 #storing first integer in s1

Prompt user to input first integer

la $a0,st3 # Put the address of the string in $a0
 li $v0, 4
syscall
li $v0, 5  # Code for input integer
syscall
move $s2, $v0 #storing second integer in s2

Adding integers

add $s0,$s2,$s1 #add and store in t3

Display result

la $a0,st4 #text to display 
li $v0,4
syscall  
li $v0,1     #for printing int
 move $a0,$s0 # move s0 to a0 to print s0
syscall
la $a0,st1
li $v0,4
syscall

Move in temporary registers

move $t3,$s0   
move $t2,$s2
move $t1,$s1

Counter for first number to be printed in binary

li $s5,32       # set up counter
loop1: 
    rol  $t1,$t1,1   #roll the bit left by on bit high to low
    and  $t0,$t1,1   #mask off low bit
    add  $t0,$t0,48  #combine t0 with 48 to form 1 or 0
    move $a0,$t0     #output ascii character
    li   $v0,11
    syscall
    li $t5,1
    sub $s5,$s5,$t5  #decrement counter
    bne $s5,$zero,loop1 #keep loop if not zero

Print a line

la $a0,st6  
li $v0,4
syscall  

Counter for second number in binary

li $s5,32     
loop2: 
    rol  $t2,$t2,1   #roll the bit left by on bit high to low
    and  $t0,$t2,1   #mask off low bit
    add  $t0,$t0,48  #combine t0 with 48 to form 1 or 0
    move $a0,$t0     #output ascii character
    li   $v0,11
    syscall
    li $t5,1
    sub $s5,$s5,$t5  #decrement counter
    bne $s5,$zero,loop2 #keep loop if not zero

Print a dotted line

la $a0,st5 #line 
li $v0,4
syscall  

Counter for Result in binary

li $s5,32       
loop: 
    rol  $t3,$t3,1   #roll the bit left by on bit high to low
    and  $t0,$t3,1   #mask off low bit
    add  $t0,$t0,48  #combine t0 with 48 to form 1 or 0
    move $a0,$t0     #output ascii character
    li   $v0,11
    syscall
    li $t5,1
    sub $s5,$s5,$t5  #decrement counter
    bne $s5,$zero,loop #keep loop if not zero

Close the Program

li $v0,10 #close the program
syscall

.end main

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top