;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; Start of reserved section - DO NOT CHANGE ANYTHING HERE!!! ; The only exception is that you can modify the .FILL value of Needle to make ; it easy to test. .ORIG x3000 BR Main ; Stack base Stack .FILL x4000 ; Parameter and result Needle .FILL #4 Result .FILL xFFFF ; Entry point Main LD R6, Stack ; Stack initialization LD R5, Stack ; LD R0, Count ; Load the number of elements LEA R1, Haystack ; Load loAddress LD R2, Needle ; Load the element to search for AND R3, R3, #0 ; Calculate hiAddress ADD R3, R3, #-1 ; ADD R3, R0, R3 ; ADD R3, R1, R3 ; PUSH R3 ; Push parameters in reverse order PUSH R1 ; PUSH R2 ; JSR BinarySearch ; Call BinarySearch POP R0 ; Retrieve the return value ADD R6, R6, #3 ; Clean up ST R0, Result ; Store the result in global variable Finish HALT ; End of reserved section ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; DO NOT ADD ANYTHING IN BETWEEN THESE SECTIONS ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; Start of the array definition - DO NOT CHANGE THE LABEL NAMES OR POSITIONS!!! ; In this section, you're only allowed to change the .FILL value for Count ; (number of elements in the array) and the .FILL values of the array but DO NOT ; delete or add any lines in this section (otherwise, you risk getting no ; credit). If you want fewer elements in the array, simply change Count. Note ; that the maximum number of elements in the array is 20. Count .FILL #7 Haystack .FILL #14 .FILL #12 .FILL #10 .FILL #8 .FILL #6 .FILL #4 .FILL #2 .FILL #0 .FILL #0 .FILL #0 .FILL #0 .FILL #0 .FILL #0 .FILL #0 .FILL #0 .FILL #0 .FILL #0 .FILL #0 .FILL #0 .FILL #0 ; End of the array definition ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; Start of the function definition ; This is where you will implement your BinarySearch function. DO NOT implement ; any other functions (not even helper functions). ; int *BinarySearch(int x, int *loAddress, int *hiAddress); BinarySearch ; Start here ; My solution was 75 lines (including empty lines and comments) RET ; End of the function definition ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; .END