Question: The below assembly program adds up a list of n numbers, where the size n is stored in memory address N, and NUM1 denotes

The below assembly program adds up a list of n numbers, where the size n is stored in memory address N, and

The below assembly program adds up a list of n numbers, where the size n is stored in memory address N, and NUM1 denotes the memory address of the first number. Rewrite the program so that the numbers in the list are summed up in the "reverse" order: that is, the first number accessed is the last number in the list (i.e., NUMn), and the last number accessed is at memory location NUM1. Notes: . . . The numbers are stored in the memory of successive addresses. Nevertheless, only the memory address of the first number (i.e., NUM1) is given, while the memory address of the last number (i.e., NUMn) is unknown. If your program directly uses "addr NUMn" to represent the address of the last number, you will only receive partial credit. You have to offer concrete comments for all the parts you revise to receive full credit. You may use other common instructions (such as multiply/divide instructions) to ease the program revision. LABEL OPCODE Load Clear Move Load Add Add Subtract LOOP: Branch_if_[R2]>0 Store OPERAND R2, N R3 R4, addr NUM1 R5, (R4) R3, R3, R5 R4, R4, #4 R2, R2, #1 LOOP R3, SUM COMMENT Load the size of the list. Initialize sum to 9. Get address of the first number. Get the next number. Add this number to sum. Increment the pointer to the list. Decrement the counter. Branch back if not finished. Store the final sum.

Step by Step Solution

3.43 Rating (159 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!