The aim of this task is to use all your MIPS knowledge (conditions, loops, array access,
function definition, etc) together again. This task requires you to faithfully translate a
recursive function from python to MIPS.
Consider the following Python code, which defines the function
Copyright By Assignmentchef assignmentchef
binary_search(the _list, target, low, high), which searches for the target item in the
sorted list the list. The two parameters low and high, should indicate the sub list to
search in. Initially this should be set to low = 0 and high = len(the list) 1.
def binary_search(the _list: list, target: int, low: int, high: int)
if low > high:
mid = (high + low) // 2
if the list[mid] == target:
return mid
elif the list[mid] > target:
return binary_search(the_list, target, low, mid 1)
return binary_search(the _list, target, mid + 1, high)
def main() -> None:
arr = [1, 5, 10, 11, 12]
index = binary search(arr, 11, 0, len(arr) 1)
print (index)
You are asked to do two subtasks:
1. Properly document the task5.py file provided (in the scaffold), and add line by line
comments to the binary _search() function. Your comments should explain what each
line does.
2. Faithfully translate the above code (ignoring type hints) into a properly commented
MIPS program using the task5.asm file provided.
CS: assignmentchef QQ: 1823890830 Email: [email protected]
Reviews
There are no reviews yet.