Find Maximum
Find the maximum value and its index in an array.
An array of 10 signed integers is stored in memory starting at location x5000. Write a program to find the maximum value and store it at memory location x6000. Also store the index (0-9) of the maximum value at location x6001.
How to Think About This Problem:
Step 1: Understand the data
• 10 integers at x5000, x5001, x5002... x5009
• They're signed (can be negative)
• Need to find biggest one and where it is
Step 2: Algorithm (think like a human first)
• Assume first element is the max
• Look at each other element
• If it's bigger than current max, update max and remember its position
• After checking all, you have the answer
Step 3: What registers do you need?
• R1 = pointer to current element
• R2 = loop counter
• R3 = current max value
• R4 = index of current max
• R5 = current index being checked
• R0 = temporary for loading/comparing
Step 4: Comparing signed numbers
To check if A > B:
• Compute A - B (using NOT + ADD for negation)
• If result is positive, A > B