Hello, if you have any need, please feel free to consult us, this is my wechat: wx91due
COMP1036 Coursework Part II (25 marks)
Release Date: 24 November 2024 17:00
Deadline: 20 December 2024 17:00
Tasks
Write a program in Hack Assembly Language that sorts an array of integers in ascending or descending order. The unsorted array contains 5 or more elements, located at a range of memory locations starting from RAM[50]. The integers in the array can be positive, negative, or zero.
The program should allow you to sort either the entire array or a portion of it. The number of elements to be sorted is determined by the integers stored in RAM[0] and RAM[1], as described below:
Read two input values, X and Y, from RAM[0] and RAM[1], respectively, and output the computed result, Z, to RAM[2]. X and Y can be positive or negative. The program should function correctly regardless of whether X < Y, X > Y, or X = Y.
Different rules will be applied based on whether X and Y are even or odd integers, as follows:
Example 1:
Given RAM[0] = X = -4; RAM[1] = Y = 2
Applying Rule (1): RAM[2] = Z = (-4) + (-2) + 0 + 2 = -4.
Applying Rule (6) for Z = -4: Sort the first 4 elements of the array in descending order.
Example 2:
Given RAM[0] = X = -5; RAM[1] = Y = 5
The range of integers between X and Y (inclusive) is [-5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5].
Applying Rule (2): RAM[2] = Z = (-5) + (-3) + (-1) + 1 + 3 + 5 = 0.
Applying Rule (7) for Z = 0: No sorting should be done.
Example 3:
The range of integers between X and Y (inclusive) is [2, 3].
Applying Rule (3): RAM[2] = Z = 2 + 3 = 5.
Applying Rule (5) for Z = 5: Sort the first 5 elements of the array in ascending order.
|
In |
Out
|
In
|
Out
|
In
|
Out
|
In
|
Out
|
In
|
Out
|
In
|
Out
|
In
|
Out
|
In
|
Out
|
In
|
Out
|
In
|
Out |
RAM[0]
|
1
|
|
-2
|
|
2
|
|
-4 |
|
-3 |
|
-4 |
|
-5 |
|
-5 |
|
3 |
|
5 |
|
RAM[1]
|
1
|
|
3
|
|
3
|
|
2
|
|
-2
|
|
5
|
|
4
|
|
5
|
|
3
|
|
-4 |
|
RAM[2]
|
|
1
|
|
3
|
|
5
|
|
-4
|
|
-5
|
|
5
|
|
-5
|
|
0
|
|
3
|
|
5 |
Ignore the values in RAM[3], RAM[4], …, RAM[49] |
||||||||||||||||||||
RAM[50]
|
3
|
3 |
3
|
2
|
3
|
1
|
3
|
5
|
3
|
5
|
-3
|
-5
|
-3
|
-1
|
3
|
3
|
3
|
2
|
-3
|
-5
|
RAM[51]
|
2 |
2
|
2
|
3
|
2
|
2
|
2
|
3
|
2
|
4
|
-2
|
-4
|
-2
|
-2
|
2
|
2
|
2
|
3
|
-2
|
-4 |
RAM[52]
|
5 |
5
|
5
|
5
|
5
|
3
|
5
|
2
|
5
|
3
|
-5
|
-3
|
-5
|
-3
|
5
|
5
|
5
|
5
|
-5
|
-3 |
RAM[53]
|
1 |
1
|
1
|
1
|
1
|
4
|
1
|
1
|
1
|
2
|
-1
|
-2
|
-1
|
-4
|
1
|
1 |
1
|
1
|
-1
|
-2 |
RAM[54]
|
4 |
4
|
4
|
4
|
4
|
5
|
4
|
4
|
4
|
1
|
-4
|
-1
|
-4
|
-5
|
4
|
4
|
4
|
4
|
-4
|
-1 |
Requirements
Marking Criteria
4. The efficiency of your program will also be considered. A limited number of tick-tocks will be given for each test case. If your program does not generate the expected results within the given number of tick-tocks, you will lose one mark for that test case.
Plagiarism
How to submit?
You should zip your file “main.asm” into one zip file. Name your zip file: YOURSTUDENTID_YOURNAME.zip (e.g., 20514000_Danting_Wang.zip).
Remember to include your student ID and your name at the beginning of the “main.asm” file. Submit your zip file to the Moodle page. Please note that each new submission overwrites all the files from the previous one. If you submit several times, ensure that your last submission is the correct version.
Check the submission after you submit it. There have been instances in the past where the submitted file was corrupted. Ensure that the submitted file is complete and executable. You will receive zero marks if your submitted file is corrupted or not executable.
For late submissions, the standard late submission policy applies: a 5% marks deduction for every 24 hours, including weekends and public holidays.