留学生辅导 Write a subroutine that performs a linear search on an unsorted array of 1

Write a subroutine that performs a linear search on an unsorted array of 16- bit 2’s compliment integers.
• The subroutine has three parameters:
1. The address of the array
2. N, which is the number of elements in the array

Copyright By PowCoder代写 加微信 powcoder

3. A target value to search for in the array.
• The parameters must be on the stack.
• If the target value is found in the array return the position at which it is
found, otherwise return -1.
• The first element is at position 0 and the last element is at position N-1.
• The result must be returned to the caller via the stack.
• Use R5 as the frame pointer and R6 as the stack pointer.
• Save and restore all registers used in the subroutine using the stack.
• Include a register dictionary and a map of the activation record for the subroutine.
• The main program must include the following declarations:
• ASCII .fill #48
• FOUNDMSG .stringz “\nFound at position: ”
• NOTFOUNDMSG .stringz “\nNot found.”
• EOPMSG .stringz “\nEnd of Processing”
• N .fill #10

• SOURCE .fill #-23
• .fill #91
• .fill #37
• .fill #0
• .fill #12
• .fill #-13
• .fill #17
• .fill #42
• .fill #-11
• .fill #24
• NUMTARGETS .fill #4
• TARGETS .fill #37
• .fill #2
• .fill #24
.fill #-13
• You may add any other declarations you require.
• As in the subroutine R6 must be used as the stack pointer.
• The array TARGETS contains target values to be searched for in the array SOURCE.
• ‘N’ is the number of elements in the array SOURCE
• NUMTARGETS is the number of elements in the array TARGETS.
For each element in the array TARGETS call the linear search subroutine to determine if the element / target is found in the SOURCE array and display the appropriate message as shown in the sample output given below.
• Before calling the subroutine push the arguments onto the stack in the following order:
o Address of the array SOURCE

o The value of N
o The current target value.
• Reserve space on the stack for the value returned by the subroutine.
The target 79 is found at position 7 within the SOURCE array so “”\nFound at position: “ and “7” are displayed, but the target 66 is not found in the SOURCE
array so “Not found.” is displayed.
Using the declarations given above the output must be:
Found at position: 2
Not found.
Found at position: 9
Found at position: 5

程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com