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
-
Zymeworks Announces FDA Clearance of Investigational New Drug Application for ZW171, a novel 2+1 T-cVANCOUVER, British Columbia, June 17, 2024 (GLOBE NEWSWIRE) -- Zymeworks Inc. (Nasdaq: ZYME), a clinical-stage biotechnology company developing a di2024-06-17
-
Indonesia Stock Exchange Partners with Nasdaq to Upgrade Market InfrastructureTechnology partnership will further enhance overall resilience and integrity of the exchange, while supporting the rapid deployment of new products2024-06-17
-
Adalvo 的 Liraglutide 預充式注射筆成為歐盟首款獲得批准的仿製藥馬爾他聖瓜安, June 17, 2024 (GLOBE NEWSWIRE) -- Adalvo 宣布 Liraglutide 預充式注射筆成功取得 DCP 批准,成為歐盟首款獲得批准的仿製藥。 根據 IQVIA 的報2024-06-17
-
促进生育,助力三胎——“三胎免费生”联合公益行动正式启动为积极响应国家号召实施三胎生育政策,扩大妇幼服务健康供给,在云南省优生优育妇幼保健协会指导下,昆明广播电视台联合昆明安琪儿妇产医院,于6月13日在昆明广播2024-06-17
-
学党史传承红色精神 守党纪筑牢自律防线——平安养老险湖南分公司党支部开展主题党日活动七一前夕,平安养老险湖南分公司党支部全体成员走进“千年学府、百年师范”——湖南第一师范,开展了一次学史明理、学史增信、学史崇德、学史力行的主题党日活动。重2024-06-17