1

I am currently working on a program that calculates the prime numbers up to 200 using recursion in MIPS assembly using PCSPIM. So far, I have populated an array of numbers from 1-200 and a binary vector list that consists of all 1's successfully. The concept that I am struggling with is how to use a stack frame to help with the process.

Here is what I have for the stack frame:

 subu  $sp,$sp,32       # Set up the stack frame
 sw    $ra, 28($sp)     # save $ra register to the stack
 sw    $fp, 24($sp)     # save $fp register to the stack
 addu  $fp, $sp, 28     # set $fp register to the end of the stack

I just don't understand how this is going to help me find prime numbers. Any insight would be greatly appreciated!

dhint4
  • 1,132
  • 2
  • 11
  • 25
  • Before the code, are you clear with the algorithm? – starrify Oct 10 '14 at 05:38
  • _"I just don't understand how this is going to help me find prime numbers."_ It helps you perform recursive calls, since you need to save and restore `$ra` (and possibly other registers) somehow, and you say that your algorithm is recursive. – Michael Oct 10 '14 at 05:40
  • starrify, I am completely clear with the algorithm. If I had to do it in a high level language, I could definitely do it. I just don't understand how to do it in MIPS. – dhint4 Oct 10 '14 at 06:36
  • @dhint4 Fine. Then Michael's comment is also what I wanna say. Also ask Google for how to implement recursion in low level languages like MIPS assembly. – starrify Oct 10 '14 at 06:47

1 Answers1

0

If you're familiar with the sieve of Eratosthenes, you don't need recursion to find prime numbers. This method is much simpler and more memory-efficient than using recursion, and you don't need to use the stack.

I can't help you with "how this is going to help me find prime numbers", because you never specified what algorithm you're using.

qwr
  • 9,525
  • 5
  • 58
  • 102