Programming Assignment 6
There are 2 parts to this assignment, both of which should be implemented in one single menubased program. Do not submit 2 .asm files.
Description:
You will write a program that presents the user with a menu. That menu will provide 3 choices as
defined below.
Main menu
----------------------------------------------
1. Display all primes between 2 and n (max of 10000)
2. Euclid’s Algorithm for GCD
3. Exit
Note: The user must always be prompted for input. All inputs must be error checked.
Part 1(20 points):
1. Write a procedure (GetInt) that accepts an unsigned integer from the user and verifies that the
number is a valid input. It must be in the range 2 to 10000 (inclusive).
2. Write a procedure (FindPrimes) that calculates all prime numbers between the 2 and the user
input integer n.
a. Use the Sieve of Eratosthenes to find all primes between 2 and n. There are many examples
of this online, and pseudocode provided below.
b. Display your results using the procedure PrintResults, outlined in step 3.
c. Do not simply hardcode an array of primes, no credit will be given if this is done. They must
be calculated.
3. Write a procedure (PrintResults) that displays: (1) how many primes are in the range of 2 to n and
(2) lists all primes in the following format. Do not use dumpmem. There should be 7 prime
numbers per line, with the possible exception of the last line. Ensure that your numbers line up
in columns as shown below. A string of 5 spaces will not work.
Example: User input n=25
4. Your program will run using a menu procedure (MainMenu), make sure to check for valid input.
5. After displaying the results of a procedure, pause and wait for a key press to continue.
6. Display the Main Menu each time the user elects to stop the current procedure. Meaning each
time a number is entered, primes are displayed, wait for a keypress to acknowledge this, and ask the
user if they would like to input another number or return to the main menu.
Pseudocode for the Sieve of Eratosthenes
Start with a boolean array is_prime of an appropriate size, all initialized to
true (1).
For each i from 2 to 5000, do
If is_prime[i] is true,
For each m from i2 to 5000, step i
set is_prime[m] to false (0)
Part 2(20 points):
Write a recursive implementation of Euclid’s Algorithm for finding the greatest common divisor
(GCD) of two integers. You can find pseudocode for this algorithm online(be sure to cite in your
program where you found pseudocode if any is used). The output shall be of the following format:
Specifications:
1. Do not use USES.
2. Error check after each input. All numbers should be unsigned in part 1, part 2 may use
signed numbers. No number greater than 10000 should be entered.
3. Do not use any . directives(.if, .while, .else, etc.).
4. You must use a recursive algorithm for part 2.
5. Remember your procedures should accomplish a basic task, so you may write more
procedures than just those outlined above.
6. Pass variables to procedures using the Stack. Variables are placed on the stack before
calling the procedure.
7. Remember that you can create local variables, but they are scoped to the procedure they
are defined in.
8. All labels must be unique. This includes data labels and code labels. Do not reuse labels.
9. Style is important. Write clean readable code with sufficient commenting.
10. Make sure your program compiles before submitting it.
请加QQ:99515681 邮箱:99515681@qq.com WX:codinghelp
- 网易硬刚腾讯 两大游戏玩家之间的口水仗不断
- 全球“最独特”的一台华为 nova 6 5G 版手机是什么样子的?
- 拼多多抖音淘宝京东,谁是真低价?
- 老杨第一次再度抓握住一瓶水,他由此产生了新的憧憬
- 丰田章男称未来依然需要内燃机 已经启动电动机新项目
- B站更新决策机构名单:共有 29 名掌权管理者,包括陈睿、徐逸、李旎、樊欣等人
- 苹果罕见大降价,华为的压力给到了?
- 三明列东又有房子要拆迁!住这里的人要发了!
- 放大招后,广州又忍不住了…
- 私募积极加仓,百亿股票私募仓位指数创出近八周新高
- 他,传闻中马云最想见的人
- 升级的脉脉,正在以招聘业务铺开商业化版图
- 如何经营一家好企业,需要具备什么要素特点
- 智慧驱动 共创未来| 东芝硬盘创新数据存储技术
- 创意驱动增长,Adobe护城河够深吗?