# "sum of squares" program in assebly language programming?

The objective is to write a MIPS Assembly language program, that prompts a user to enter a positive integer n, and computes and print the sum 1sqaure + 2square + ....+ nsquare. (should not use formula).

Can somebody help me with a sample working code.
###### Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Commented:
We can't really give full code, as this is an assignment.

Maybe I can give some pointers.

1. You should use a counter... say CX, initialize this to your integer n.

2. You should use a a conditional jump (jz or jnz) together with a loop to ensure that you are able to loop n number of times.

3. n ^ 2 is simply a number multiplied by itself. So you can use the MUL operation.

4. You should use a temporary address (or register) to store your results as you loop.

Maybe you can post some code, and then we can take it from here:

Hope that helps
- Kelvin
Author Commented:
Hi Kelvin King

I made the previous program working,  Thank you.
However, Now i am writing a program for harmonic series..
following is my code. I am getting syntax error for div instruction in the code

# ***** This program caluculates the Hormonic Series ****

# \$t0 - n , No. of loops
# \$t1 - temporary reg, hold 1/nth value
# \$t2 - sum of the series
# \$t3 - counter

main:
li \$v0, 5
syscall
move \$t0, \$v0

li \$t2, 0
li \$t3, 0
loop:
beq \$t3, \$t0, endloop
div \$t1, 1, \$t3
b loop

endloop:
## Print out \$t2.
move \$a0, \$t2
li \$v0, 1
syscall

li \$v0, 10
syscall
Author Commented:
I got the program working. thx

Experts Exchange Solution brought to you by