定制写作代写服务成功案例
<p>
<span style="color:rgba(0, 0, 0, 0.85);font-family:"font-size:18px;background-color:#F5F5F5;">2012年-2022年十年品牌服务,砥砺前行,精准有效服务广大客户</span>
</p>
COMP1036 Coursework Part II (25 marks)
Coursework Part II
项目类别:计算机
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:
(1)
IF both X and Y are even integers, THEN Z is the sum of all even integers between X and Y (inclusive).
(2)
IF both X and Y are odd integers, THEN Z is the sum of all odd integers between X and Y (inclusive).
(3)
IF one of X or Y is odd and the other is even, THEN Z is the sum of all integers between X and Y (inclusive).
(4)
IF X = Y, THEN Z = X or Z = Y.
(5)
IF Z is positive, THEN sort the array in ascending order.
(6)
IF Z is negative, THEN sort the array in descending order.
(7)
IF Z is zero, THEN no sorting should be done.
Example 1:
Given RAM[0] = X = -4; RAM[1] = Y = 2
The range of integers between X and Y (inclusive) is [-4, -3, -2, -1, 0, 1, 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:
Given RAM[0] = X = 2; RAM[1] = Y = 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.
Example 4:
Given RAM[0] = X = 3; RAM[1] = Y = 3
The range of integers between X and Y (inclusive) is [3].
Applying Rule (4): RAM[2] = Z = 3.
Applying Rule (5) for Z = 3: Sort the first 3 elements of the array in ascending order.