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
- HGC环电强化国际业务领导架构 谭君骥及Ravindran Mahalingam分别担任专精职务
- 海伯森六维力传感器:助力人形机器人产业发展的创新力量
- 达闼董事长黄晓庆:以技术破局致胜从未止步
- 从辅助到核心,企业如何基于AI Agent升级品牌数字营销
- 国产2.5亿超高分辨率图像传感器发布,主要面向机器视觉领域
- 西部数据推出多款超高速、大容量存储解决方案
- 中关村e谷承办“科创耀未来 奋进谱新篇”企业家创新论坛圆满落幕
- 航科卫星“汕头数字一号”卫星发射成功!
- Gartner 最新魔力象限出炉!ManageEngine卓豪成功入围
- 科技重塑物流,英特尔&集和诚加速智慧物流发展!
- 数智赋能 向“新而行” 坦克与装甲车辆学术与发展论坛召开
- 赛诺威盛:大孔径专科化CT领航者
- 网易硬刚腾讯 两大游戏玩家之间的口水仗不断
- 全球“最独特”的一台华为 nova 6 5G 版手机是什么样子的?
- 拼多多抖音淘宝京东,谁是真低价?