Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

MASM PROGRAM - ARRAYS Write and test a MASM program to perform the following tasks (check the Requirements section for specifics on program modularization): Introducethe

MASM PROGRAM - ARRAYS

Write and test a MASM program to perform the following tasks (check the Requirements section for specifics on program modularization):

  1. Introducethe program.
  2. Declareglobal constantsARRAYSIZE,LO, andHI.GenerateARRAYSIZErandom integers in the range fromLOtoHI(inclusive), storing them in consecutive elements of arrayrandArray(e.g. forLO= 20 andHI= 30, generate values from the set [20, 21, ... 30] )
  • ARRAYSIZEshould be initially set to 200,
  • LOshould be initially set to 15
  • HIshould be initially set to 50
  • Hint:RunRandomizeonce inmainto generate a random seed, then useRandomRangeto generate each random number.
  • Displaythe list of integers before sorting, 20 numbers per line with one space between each value.
  • Sortthe list in ascending order (i.e., smallest first).
  • Calculateanddisplaythe median value of the sortedrandArray, rounded to the nearest integer. (Using Round Half Up (Links to an external site.) rounding)
  • Displaythe sortedrandArray, 20 numbers per line with one space between each value.
  • Generatean arraycountswhich holds the number of times each value in the range [LO,HI] (with default constant values, this will be [15,50]) is seen inrandArray, even if that number of times is zero. For example withLO=15,counts[0]should equal the number instances of the value `15` in array.counts[14]should equal the number of instances of the value `29` inrandArray.
  • Displaythe arraycounts, 20 numbers per line with one space between each value.
  • Program Requirements

    1. The programmustbe constructed using procedures.At leastthe following procedures/parameters are required: NOTE:Regarding the syntax used below... procName{parameters:varA(value, input),varB(reference, output)} indicates that procedureprocNamemust be passedvarAas a value andvarBas a reference, and thatvarAis an input parameter andvarBis an output parameter.You may use more parameters than those specified but try to only use them if youneedthem.
      1. main
      2. introduction{parameters:intro1(reference, input),intro2(reference, input), ...)
      3. fillArray{parameters:someArray(reference, output)}NOTE:LO,HI,ARRAYSIZEwill be used as globals within this procedure.
      4. sortList{parameters:someArray(reference, input/output)}NOTE:ARRAYSIZEwill be used as a global within this procedure.
      5. exchangeElements(if your sorting algorithm exchanges element positions): {parameters:someArray[i](reference. input/output),someArray[j](reference, input/output), where i and j are the indexes of elements to be exchanged}
      6. displayMedian{parameters:someTitle(reference, input),someArray(reference, input)}NOTE:ARRAYSIZEwill likely be used as a global within this procedure.
      7. displayList{parameters:someTitle(reference, input),someArray(reference, input)}NOTE:ARRAYSIZEwill likely be used as a global within this procedure.
      8. countList{parameters:someArray1(reference, input),someArray2(reference, output)}NOTE:LO,HI, and ARRAYSIZEwill be used as globals within this procedure.
    2. Procedures (exceptmain)must notreference data segment variables by name. There is asignificantpenalty attached to violations of this rule.randArray,counts, titles for the sorted/unsorted lists, etc... should be declared in the .data precedingmain, butmustbe passed to procedures on the stack.
      1. ConstantsLO,HI, andARRAYSIZEmay be used as globals.
      2. Parametersmustbe passed on the system stack, by value or by reference, as noted above (see Module 7, Exploration 1 - Passing Parameters on the Stack for method).
      3. Strings/arraysmustbe passed by reference.
    1. Since you will not be using globals (except the constants) the programmustuse one (or more) of the addressing modes from the explorations (e.g.Register IndirectorIndexed Operandsaddressing for reading/writing array elements, andBase+Offsetaddressing for accessing parameters on the runtime stack.) See Module 7, Exploration 2 - Arrays in Assembly and Writing to Memory for details.
    2. The programmers name and program title, and a description of program functionality (in student's own words) to the user must appear in the output.
    3. LO,HI, andARRAYSIZEmustbe declared as constants. NOTE: Wewillbe changing these constant values to ensure they are implemented correctly. Expect ranges as follows LO: 5 to 20 HI: 30 to 60 ARRAYSIZE: 20 to 1000
    4. Theremustbe only one procedure to display arrays. This proceduremustbe called three times:
      1. to display the unsorted array
      2. to display the sorted array
      3. to display the counts array
    1. All listsmustbe identified when they are displayed (use thesomeTitleparameter for thedisplayListprocedure).
    2. Proceduresmayuse local variables when appropriate.
    3. The programmustbe fully documented and laid out according to the CS271 Style Guide Download CS271 Style Guide. This includes a complete header block for identification, description, etc., a comment outline to explain each section of code, and proper procedure headers/documentation.

    Notes

    1. You are now allowed to use theUSESdirective, but only for preserving/restoring registers. You may not use its extended syntax to create local labels for stack-passed parameters.
    2. The Irvine library provides procedures for generating random numbers. CallRandomizeonce at the beginning of the program (to set up so you don't get the same sequence every time), and callRandomRangeto get a pseudo-random number. See the documentation in the CS271 Irvine Procedure Reference Download CS271 Irvine Procedure Referencefor more information on using these procedures.
    3. The median is calculated after the array is sorted. It is the "middle" element of the sorted list. If the number of elements is even, the median is the average of the middle two elements.
    4. Expected results:

    Step by Step Solution

    There are 3 Steps involved in it

    Step: 1

    blur-text-image

    Get Instant Access to Expert-Tailored Solutions

    See step-by-step solutions with expert insights and AI powered tools for academic success

    Step: 2

    blur-text-image

    Step: 3

    blur-text-image

    Ace Your Homework with AI

    Get the answers you need in no time with our AI-driven, step-by-step assistance

    Get Started

    Recommended Textbook for

    Combinatorial Testing In Cloud Computing

    Authors: Wei-Tek Tsai ,Guanqiu Qi

    1st Edition

    9811044805, 978-9811044809

    More Books

    Students also viewed these Programming questions

    Question

    Describe the six elements of communication.

    Answered: 1 week ago