Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
Solved

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

Posted on 2008-11-16
Medium Priority
1,921 Views
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.
0
Question by:thirst4truth
• 3

LVL 13

Expert Comment

ID: 22971075
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
0

Author Comment

ID: 22971545
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
0

Accepted Solution

thirst4truth earned 0 total points
ID: 22971955
I got the program working. thx
0

Author Comment

ID: 22971962
I got it working by myself
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
###### Suggested Courses
Course of the Month14 days, 9 hours left to enroll