Question: Subroutine: x _ mod _ N input: R 5 unsigned 1 6 - bit integer x - - returned unchanged R 6 unsigned 1 6

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
----------
x_mod_N:
mov.w R5,R12
repeat:
cmp.w R6,R12 ;set status bits for (x-N)
jn end_div ;if (x-N)<0 we are done
;otherwise
sub.w R6,R12 ;x <-x-N
jmp repeat land repeat from top
end_div:
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.

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!