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"

Integer versus the Floating-Point processor. You're adding Floating-Point result of the reciprocal addition onto the integer register!

N
fTally = 0.0
fOne = 1.0

while N
   fN = N
    f = 1.0 / fN
    fTally = fTally + f
    N--
end while

Only one thing, please homeryansta, put the code in code tags with the highlighting: [ code=asm ] [ /code ] and please put better titles in your posts, because with good tittles the forums will be more organized and your chances to have a answer will grow, because of someone had the same problem, now can help you.

Thanks!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.