Question: Question 4 - Fix the subroutine ( 2 + 6 pts ) You are given following subroutine and contract ` ` ` 1 0 0

Question 4- Fix the subroutine (2+6 pts)
You are given following subroutine and contract
```
100;
Subroutine: x_mod_N
input: R5 unsigned 16-bit integer x -- returned unchanged
R6 unsigned 16-bit nonzero integer N -- returned unchanged
output: R12 unsigned 16-bit integer y -- may be modified
y is the remainder when x is divided by N
Modifies R12, all other core registers in R4-R15 unchanged
108;
----------------------------------------------------------------------------
109 x_mod_N:
110 mov.w R5, R12
111 repeat:
112 cmp.w R6, R12 ; set status bits for (x-N)
113 jn end_div ; if (x-N)0 we are done
```
```
115 sub.w R6, R12 ; x - x-N
```
```
117end_div:
118 ret
```
Sometimes it works correctly (e.g., it can correctly compute \(31273\%5=3\)), and at other times it does not. Can you find the error and fix the subroutine?
(a) What line needs to be fixed? Enter the line number.
(b) What should the correct line be? Enter the instruction and operands. Watch out for autocorrect when entering your line.
Question 4 - Fix the subroutine ( 2 + 6 pts ) You

Step by Step Solution

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!