素数列表程序

时间:2012-06-27 19:47:16

标签: loops assembly hardware primes

首先,我想证明这不是作业http://computer.atlas4e.com/

我真的需要通过解释来理解这一点,因为我试图通过自己理解计算机的基本知识,感谢您的帮助

`Prime Number List Program 
Write a main program that generates a list of prime numbers. The program should use the PrimeTest subroutine to test whether each of the numbers 2, 3, 4, 5, 6…, 255 & 256 is a prime. Each number that is found to be a prime should be added to a list in memory. The list of primes should be stored in consecutive memory locations.  Use a location named StartPrimeList to point to the start address of the prime number list. Use a pointer called PrimeListPtr to point to the (current) end of the list, PrimeListPtr will be incremented every time a prime number is appended to the list.
Use a location named PrN to store the number that you are checking. Start by storing a 2 in PrN. In a loop, you should call PrimeTest to determine whether PrN is a prime. If PrN is a prime, then append it to the list. Then add 1 to PrN and jump back to the start of the loop to test the next value of PrN.`
The output of the program should appear starting at location StartPrimeList as follows:-
Address Contents
 [StartPrimeList]   2
[StartPrimeList+1]  3
[StartPrimeList+2]  5
[StartPrimeList+3]  7
    …
    …
[StartPrimeList+?]  Largest Prime <= 256

(251 - 54th prime number starting from 2 <=256)
(257 - 55th prime number >256)

`

Mark Allocations for Program 2

•   A program header in the program listing explaining how the program works.   
•   Sensible/Relevant program comments on sections of assembler language.       
•   Relevant labelling of loops and data items.                         [4]
•   Program runs successfully on xComputer and produces correct output for given input. 
`                 

1 个答案:

答案 0 :(得分:0)

“编写一个生成素数列表的主程序。”这是你的基本问题。稍后会提供更多详细信息以帮助您回答。

“程序应使用PrimeTest子程序来测试数字2,3,4,5,6 ......,255和256中的每一个是否为素数。”你能做到这一部分吗?如果没有,那么写下你能做的最好的代码,然后再问一个特定的问题。

“应将每个被发现为素数的数字添加到内存中的列表中。”你能做到这一部分吗?如果没有,那么写下你能做的最好的代码,然后再问一个特定的问题。

“素数列表应存储在连续的存储位置。”你能做到这一部分吗?如果没有,那么写下你能做的最好的代码,然后再问一个特定的问题。

“使用名为StartPrimeList的位置指向素数列表的起始地址。”你现在应该得到这个消息。使用问题本身提供的出色建议来帮助您。写下你的代码。如果它工作,那很好。如果它没有,那么在这里发布,解释它应该做什么以及你认为问题可能是什么。告诉我们您尝试了什么,以及什么没有解决问题。这将有助于我们重复你的工作。

我们不会为您编写程序。你必须写它;我们将帮助您编写它。