Question: This assignment is designed to test your understanding of basic MASM assembly language programming. Please submit your . asm files on CANVAS. Objectives: Designing and

This assignment is designed to test your understanding of basic MASM assembly language programming.
Please submit your .asm files on CANVAS.
Objectives:
Designing and implementing procedures
Designing and implementing loops
Writing nested loops
Understanding data validation
Problem Definition:
Write a program to calculate composite numbers. First, the user is instructed to enter the number of
composites to be displayed, and is prompted to enter an integer in the range [1..400]. The user
enters a number, n, and the program verifies that 1n400. If n is out of range, the user is re-
prompted until s/he enters a value in the specified range. The program then calculates and displays
all of the composite numbers up to and including the nth composite. The results should be displayed
10 composites per line with at least 3 spaces between the numbers.
Requirements:
The programmer's name must appear in the output.
The counting loop (1 to n) must be implemented using the MASM loop instruction.
The main procedure must consist (mostly) of procedure calls. It should be a readable "list"
of what the program will do.
Each procedure will implement a section of the program logic, i.e., each procedure will
specify how the logic of its section is implemented. The program must be modularized into at
least the following procedures and sub-procedures:
introduction
getUserData
validate
showComposites
isComposite
prompt to go again
farewell
The upper limit should be defined and used as a constant.
Data validation is required. If the user enters a number outside the range [1..400] an error
message should be displayed and the user should be prompted to re-enter the number of
composites.
The usual requirements regarding documentation, readability, user-friendliness, etc., apply.
Submit your text code file (.asm) to Canvas by the due date.
Notes:
For this program, you may use global variables instead of passing parameters.
A number k is composite if it can be factored into a product of smaller integers. Every integer
greater than one is either prime or composite. Note that this implies that
a.1 is not composite.
b. The number must be positive.
There are several ways to make your isComposite procedure efficient.
Here is the code I have so far:
INCLUDE Irvine32.inc
; Constants
lowerBound equ 1
upperBound equ 400
.data
intro BYTE "Composites by .",0
introPrompt BYTE "Enter the number of composite numbers you would like to see.", 0
introPrompt2 BYTE "I will accept orders for up to 400 composites.", 0
goodbyeMsg BYTE "Results certified by. Goodbye", 0
compositePrompt BYTE "Enter the number of composites to display [1...400]: ",0
againPrompt BYTE "Would you like to go again (1=YES /0=NO): ",0
rangeError BYTE "Out of range. Try again", 0
compositeOut BYTE "Composite numbers: ",0
compositeInp DWORD ?
factorCounter DWORD ?
.code
main PROC
call introduction
call getUserData
call showComposites
call again
call farewell
main ENDP
introduction PROC
; 1. Introduction
mov edx, OFFSET intro
call WriteString
call Crlf
call Crlf
mov edx, OFFSET introPrompt
call WriteString
call Crlf
mov edx, OFFSET introPrompt2
call WriteString
call Crlf
introduction ENDP
getUserData PROC
; 2. Get number of composites
mov edx, OFFSET compositePrompt
call WriteString
call ReadInt
mov compositeInp, eax
call validate
getUserData ENDP
validate PROC
; 3. Validate input range
mov eax, compositeInp
cmp eax, lowerBound
jl rangeErr
cmp eax, upperBound
jg rangeErr
; If input is in range, proceed to show composites
call showComposites
ret
rangeErr:
; Display range error message and prompt again
mov edx, OFFSET rangeError
call WriteString
call Crlf
call getUserData
ret
validate ENDP
showComposites PROC
; 4. Find composites from 1 to n
; put ecx into the loop counter
mov eax, 1
mov ecx, compositeInp
; Display "Composite numbers: "
mov edx, OFFSET compositeOut
call WriteString
outerLoop:
mov eax, esi ; Load current number into eax
mov ebx, 1
mov edx, 0 ; Clear edx for division
mov factorCounter, 0 ; Reset factor counter to 0
i
 This assignment is designed to test your understanding of basic MASM

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!