I've been working on this for hours! the code makes perfect sense, but wont' work!!! aaah! about to pull my hair out.
the code is suppose to do get the sum of this
1/1 + 1/2 + ..... + 1/n
I blocked all the codes and just print out the v0 value in float form, but it's the same problem so I'm assuming its coming from the conversion. But I followed the codes closely, shouldn't be any errors.
.text
.globl __start
__start:
la $a0, prompt #print the directions to screen
li $v0,4
# Register Use Chart
# $f0 --- x
# $f2 --- sum of terms
la $a0,prompt # prompt user for v0
li $v0,4 # print string
syscall
li $v0,5 # read single
syscall # input stored to v0
li $t0,1 #assign 1 to t0
l.s $f2,1 #assign 1 to f2
l.s $f10,0 #assign 0 to f10
do:
#NOTE
#f2 is the number 1
#f4 is the float value of the input integer
#f6 is the value after the division operation
#f10 is the sum of all the added values
mtc1 $v0, $f4 #
cvt.s.w $f4, $f4 #convert from int to float
div.s $f6,$f2,$f4 #divide 1/n and store in f6
add.s $f10, $f10, $f6 #add f6 to the sum(initial 0)
sub $v0,$v0,$t0 #n-1
beq $v0,0,next #if n==0 go to next
bne $v0,0,do #if n!=0 go to do
next:
#print the result
mov.s $f12,$f10 # move sum to f12 register
li $v0,2 # print single
syscall
la $a0,newl # new line
li $v0,4 # print string
syscall
li $v0,10 # code 10 == exit
syscall # Return
## Data Segment
.data
zero: .float 0.0
prompt: .asciiz "Enter an integer: "
blank: .asciiz " "
newl: .asciiz "\n"