简体   繁体   中英

Calculating Prime Numbers in MIPS Assembly

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!

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM