Reference no: EM132293841
Assignment - Statistics of a sorted data set in MARIE
This task will require you computing the median of a set of sorted numbers. We will break it down into small steps for you. Most of the tasks require you to write code and test cases. The code must contain comments, and you must submit it as .mas files together with the rest of your assignment. The test cases should also be working, self-contained MARIE assembly files.
1.1 Inputting a list of numbers
The first step is to input a set of numbers (number-by-number, using the Input instruction). You can assume that this will be a set of positive integers and that the last number given will be a zero. This means you can keep reading numbers until you receive a zero.
Setup code in MARIE which reads a set of positive integers and stores these as an array (contiguous block of memory). Do not include the 0 in the array; as you accept numbers you should keep track of the size and store this in a variable once all the reading is complete. Print the size of the array using the Output instruction to help you test that your program is correct.
1.2 List input subroutine
Extend your list input so that it can be used as a subroutine.
1.3 Checking t h e order
This part will require you to determining whether the given array is in order. Once you have an array of positive numbers, step through this array and store 1 in a variable inOrder where it is in ascending order or 0 otherwise. You should implement this as a subroutine which can be triggered once all the array values have been entered. You may like to display this variable for testing purposes.
1.4 Division by 2
Prepare a MARIE subroutine DIV which computes the quotient and remainder for dividing a number by 2. This can be done by the method of successive subtraction. The strategy is as follows:
1. accept a numerator N and divisor D
2. set quotient Q to zero
3. while N ≥ D...
- increase Q by one
- reduce N by D
4. N now holds the remainder and Q holds the quotient
1.5 Finding the Median
Once you know that the set of numbers are in order, find the middle value in the array to use as the median. Your DIV subroutine should help here. If there are two middle values (e.g. there are an even number of items) you should use the left of these as the median.
1.6 Complete Program
As a final step, combine all the previous subroutines into a program that does the following:
- Let a user input a list of numbers using the subroutine from 2.2
- Check whether or not that list is in order using your subroutine from 2.3
- Find the median of this list of numbers using your subroutine from 2.5 (note this will also involve using your division by two subroutine from 2.4)
- Output whether the list is in order (as a 0 or 1) and then the median if there is one
Files to be submitted:
1. Six MARIE files
2.1 InputtingList
2.2 InputtingListSubroutine
2.3 CheckingOrder
2.4 DivisionBy2
2.5 FindingMedian and
2.6 CompleteProgram