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


"sum of squares" program in assebly language programming?

Posted on 2008-11-16
Medium Priority
Last Modified: 2012-05-05
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.
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

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

      li $v0, 5
      move $t0, $v0

        li $t2, 0
      li $t3, 0
      beq $t3, $t0, endloop
      add $t3, $t3, 1
      div $t1, 1, $t3
      add $t2, $t2, $t1
      b loop
      ## Print out $t2.
      move $a0, $t2
      li $v0, 1

      li $v0, 10

Accepted Solution

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

Author Comment

ID: 22971962
I got it working by myself

Featured Post

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

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…

577 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question