All pastes #921495 Raw Edit

Untitled

public text v1 · immutable
#921495 ·published 2008-02-28 02:08 UTC
rendered paste body
# GRADER:
# The algorithm posted is correct.
# Please look into the comments I put in the source code, commented by # GRADER:
# The computation is not correct -30
# Score: 70 / 100

# Name:		Darren Gruber
# email:	dgruber@gwu.edu
# CSCI 136 Assignment 3 IEEE-754 Addition

.text
.globl main
main:
	
	li		$v0, 4				# Syscall code for printing strings
	la		$a0, prompt1	# Prompt for first decimal input
	syscall
	li		$v0, 6				# Syscall code for inputting floating point
	syscall	
	mov.s	$f1, $f0			# Sets the first parameter

ask:
	li		$v0, 4				# Syscall code for printing strings
	la		$a0, prompt1	# Prompt for second operand
	syscall
	li		$v0, 6				# Syscall code for inputting floating point
	syscall	
	mfc1 	$t1, $f0			# Store second operand so we can check if its 0
	mov.s	$f2, $f0			# Sets the second parameter
	jal 	getsum
	beqz	$t1, done			# User enter's zero, no more input needed
	j			ask						# If user's input doesn't equal 0, ask again
	
getsum:
	sub 	$sp, $sp,12		# Allocate space on the stack
	swc1 	$f1, 0($sp)		# Save parameter 1
	swc1 	$f2, 4($sp)		# Save parameter 2
	sw 		$ra, 8($sp)		# Save return address

	addi	$s6, $0, 1		# Prepare to add the leading 1 to mantissa
	sll		$s6, $s6, 23	# Span to the size of mantissa

	mfc1	$t0, $f1			# Moves floating point to regular register
	beqz	$t0, retB			# Operand 1 is 0, return B as answer
	srl		$s0, $t0, 31	# Stores sign bit of the input \ $s0 = signA
	sll		$s1, $t0, 1		# Gets rid of the sign bit
	srl		$s1, $s1, 24	# Isolates the exponent \ $s1 = expA
	sll		$s2, $t0, 9		# Isolates the mantissa 
	srl		$s2, $s2, 9		# Isolates the mantissa \ $s2 = mantA
	or		$s2, $s2, $s6	# Adds the leading 1 to the mantissa
	
	mfc1 	$t1, $f2			# Moves floating point to regular register
	beqz	$t1, retA			# Operand 2 is 0, return A as answer
	srl		$s3, $t1, 31	# Stores sign bit of the input \ $s3 = signB
	sll		$s4, $t1, 1		# Gets rid of the sign bit
	srl		$s4, $s4, 24	# Isolates the exponent \ $s4 = expB
	sll		$s5, $t1, 9		# Isolates the mantissa
	srl		$s5, $s5, 9		# Isolates the mantissa \ $s5 = mantB
	or		$s5, $s5, $s6	# Adds the leading 1 to the mantissa
	
	blt		$s1, $s4, L1	# if(expA < expB)
	add		$t1, $s1, $0	# else (expAns = expA)
# GRADER:  In the following line, you shoulde put $s4 instead of $s3.	
#	sub		$t5, $s1, $s3	# Calculate the difference between expA & expB
	sub		$t5, $s1, $s4	# Calculate the difference between expA & expB

	srl		$s5, $s5, $t5	# Shift manB to right by exp difference
	j			L1						# Now we check the signs
	
L1:										# if(expA < expB), check signs
	xor		$t5, $s0, $s3	# Checks to see if signs are the same
	beqz	$t5, L2				# Branch to loop if signs are the same
	sub		$t2, $s2, $s5	#	Signs diff. (manAns = manA + manB?+ 1)
	j			L3						# Check if manAns[24] = 1
	
L2:
	add		$t2, $s2, $s5	# manAns = manA + manB
	add		$t0, $s0, $0	# signAns = signA
	j			L3						# Check if manAns[24] = 1

L3:
	srl		$t6, $t2, 24	# Shift so we can check manAns[24]
	addi	$t7, $0, 1		# $t7 = 1
	beq		$t6, $t7, L4	#	manAns[24] = 1
	add		$t0, $s0, $0	# signAns = signA
	j			FP						# Time to reassemble the answer in FP

L4:										# manAns[24] = 1
# GRADER: what the following line do? I do not think the following line is useful.
#	neg		$t2, $t2			# manAns = manAns?
	
# GRADER: you should do the normalization. The follwing is not normaliztion.
	add		$t0, $s3, $0	# signAns = signB
	j			FP						# Time to reassemble the answer in FP

FP:
	sll		$t0, $t0, 31	# Extend the signAns to fit rest of answer
	sll		$t1, $t1, 23	# Extend the expAns to fir the rest of the answer
	sll		$t2, $t2, 9		# Remove the leading 1 from manAns
	srl		$t2, $t2, 9		# Remove the leading 1 from manAns
	or		$t0, $t0, $t1	# Add expAns to expSign
	or		$t0, $t0, $t2	# Add manAns to the rest of the answer
	mtc1	$t0, $f3			# Moves the answer to the floating point register
	j			EN						# We're done calculating the sum

EN:
	li 		$v0, 4				# Syscall for printing strings
	la 		$a0, ans			# Print the string announcing the result
	syscall
	mov.s	$f12, $f3			# Prepare to print out the FP answer
	li 		$v0, 2				# Syscall for printing FP
	syscall
	lwc1 	$f1, 0($sp)		# Restore parameter 1
	lwc1 	$f2, 4($sp)		# Restore parameter 2
	lw 		$ra, 8($sp)		# Restore return-address
	add 	$sp, $sp, 12	# De-allocate stack space
	jr 		$ra						# Return from function call
retA:
	mov.s	$f1, $f0			# Move A from parameter to answer
	j			EN						# Print result
retB:
	mov.s	$f2, $f0			# Move B from parameter to answer
	j			EN						# Print result
done:  								# We're finished- so syscall to exit
  li 		$v0,10
  syscall							# Exit

.data
prompt1:	.asciiz "Please enter a decimal number to be added: "
ans: 			.asciiz "The answer is: "