Question: I need help with the following Project: Write and test a MASM program to perform the following tasks: Display the program title and programmers name.

I need help with the following Project:

Write and test a MASM program to perform the following tasks:

  1. Display the program title and programmers name.
  2. Get the user's name, and greet the user.
  3. Display instructions for the user.
  4. Repeatedly prompt the user to enter a number.
    1. Validate the user input to be in [-200, -100] or [-50, -1] (inclusive).
    2. Notify the user of any invalid negative numbers (negative, but not in the ranges specified)
    3. Count and accumulate the valid user numbers until a non-negative number is entered. Detect this using the SIGN flag. (The non-negative number and any numbers not in the specified ranges are discarded.)
  5. Calculate the (rounded integer) average of the valid numbers and store in a variable.
  6. Display:
    1. the count of validated numbers entered NOTE: if no valid numbers were entered, display a special message and skip to (f)
    2. the sum of valid numbers
    3. the maximum (closest to 0) valid user value entered
    4. the minimum (farthest from 0) valid user value entered
    5. the average, rounded to the nearest integer
      1. -20.01 rounds to -20
      2. -20.5 rounds to -20
      3. -20.51 rounds to -21
      4. -20.99 rounds to -21
    6. a parting message (with the users name)

Program Requirements

  1. The program must be fully documented and laid out according to the CS271 Style Guide. This includes a complete header block for identification, description, etc., and a comment outline to explain each section of code.
  2. The main procedure must be modularized into commented logical sections (procedures are not required this time)
  3. The four value limits must be defined as constants.
  4. The user input loop should terminate depending on the value of the SIGN flag.
  5. The Min, Max, Count, Sum, and Average must all be stored in named variables as they are calculated

I am struggling with the average part and do not know if what I have is right or how to go about it ( I know I do not have any code to find Min or Max yet but I know how to take care of that part). Any help would be GREATLY appreciated.

Here is what I have so far:

INCLUDE Irvine32.inc

; (insert macro definitions here)

; (insert constant definitions here)

.data

; (insert variable definitions here)

projectTitle BYTE "Welcome to the Integer Accumulator by Cory Yeomans", 0 intro BYTE "What is your name?: ", 0 userName BYTE 33 DUP(0) greeting BYTE "Hello there, ", 0 extraCredit_1 BYTE "***EC: Numbered Input Lines", 0 extraCredit_2 BYTE "***EC: Decimal-point average calculation", 0 instructions_1 BYTE "Please enter any amount of numbers in the range [-200, -100] or [-50, -1].", 0 instructions_2 BYTE "When you are finished, please enter any non negative number to receive calculations.", 0 error_1 BYTE "That number is not in either of the ranges [-200, -100] or [-50, -1]. Please try again.", 0 error_2 BYTE "That number is not in range you choose, [-200, -100]. Please try again.", 0 error_3 BYTE "That number is not in range you choose, [-50, -1]. Please try again.", 0 prompt BYTE "Please enter a valid negative number: ", 0 maxPrompt BYTE "The maximum number entered is: ", 0 minPrompt BYTE "The minimum number entered is: ", 0 countPrompt BYTE "The total amount of valid numbers entered: ", 0 sumPrompt BYTE "The sum of the valid numbers is: ", 0 averagePrompt BYTE "The rounded average of the valid number is: ", 0 ecAverage BYTE "The decimal-point average is: ", 0 farewell BYTE "The caclulations are now completed. Thank you and have a great day!", 0 count DWORD ? sum DWORD ? special_message BYTE "Attention: Due to no valid numbers being entered, no calculations will be displayed", 0 line_text BYTE "Line number ", 0 line_text_2 BYTE ": "

.code main PROC

; Introduction

mov EDX, OFFSET projectTitle call WriteString call CrLf mov EDX, OFFSET extraCredit_1 call WriteString call CrLf mov EDX, OFFSET extraCredit_2 call WriteString call CrLf call CrLf

; Get User's Name and Greeeting

mov EDX, OFFSET intro call WriteString mov EDX, OFFSET userName mov ECX, 32 call ReadString call CrLf mov EDX, OFFSET greeting call WriteString mov EDX, OFFSET userName call WriteString call CrLf call CrLf

; Display Instructions

mov EDX, OFFSET instructions_1 call WriteString call CrLf mov EDX, OFFSET instructions_2 call WriteString call CrLf call CrLf

; Repeatedly Prompt User for Number until User Enters Non Negative

_enterFirstNumber: ; Asks the user the first number to determine the range. mov EDX, OFFSET line_text call WriteString mov count, 1 mov EAX, count call WriteDec mov EDX, OFFSET line_text_2 call WriteString mov EDX, OFFSET prompt call WriteString

;Now the program finds out which range it is working in call ReadInt cmp EAX, -200 ;If number is < -200, it fits neither range jl _error_1 cmp EAX, -100 ;Now checks if num fits in first range option jle _first_range cmp EAX, -50 ;If number is < -50 but > -100, then it fits in niether range jl _error_2 cmp EAX, -1 ;If num makes it this far and passes, user is now choosing numbers in 2nd range option jle _second_range jmp _special_message ;No valid numbers were enterd by the user

_error_1: ; If the first number is not in either acceptable ranges sub sum, EAX sub count, 1 mov EDX, OFFSET error_1 call WriteString call CrLf jmp _enterFirstNumber

_error_2: ; The error message for those who choose the range [-200, -100] sub sum, EAX sub count, 1 mov EDX, OFFSET error_2 call WriteString call CrLf jmp _first_range

_error_3: ; The error message for those who choose the range [-50, -1] sub sum, EAX sub count, 1 mov EDX, OFFSET error_3 call WriteString call CrLf jmp _second_range

_first_range: ;For entering numbers in the range [-200, -100] add sum, EAX add count, 1 mov EDX, OFFSET line_text call WriteString mov EAX, count call WriteDec mov EDX, OFFSET line_text_2 call WriteString mov EDX, OFFSET prompt call WriteString call ReadInt cmp EAX, -200 jl _error_2 cmp EAX, 0 jge _calculations cmp EAX, -100 jg _error_2 jmp _first_range

_second_range: ;For entering numbers in the range [-50, -1] add sum, EAX add count, 1 mov EDX, OFFSET line_text call WriteString mov EAX, count call WriteDec mov EDX, OFFSET line_text_2 call WriteString mov EDX, OFFSET prompt call WriteString call ReadInt cmp EAX, -50 jl _error_3 cmp EAX, -1 jg _calculations jmp _second_range call CrLf

_special_message: ;Scenario of no valid numbers being entered mov EDX, OFFSET special_message call WriteString call CrLf jmp _calculations

; Calculate the Averages and Store in a Variable

_calculations: add sum, EAX sub count, 1 ;Because Line numbering is using count and starts at 1, must take away 1 for calc. round_average EQU

; Display Calculations Found

;Program will now show sum, max, min, and the two different averages of the valid numbers mov EDX, OFFSET sumPrompt call WriteString mov EAX, sum call WriteInt call CrLf mov EDX, OFFSET countPrompt call WriteString mov EAX, count call WriteDec call CrLf mov EDX, OFFSET averagePrompt call WriteString mov EAX, round_average call WriteDec

; Farwell Message

Invoke ExitProcess,0 ; exit to operating system main ENDP

; (insert additional procedures here)

END main

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!