lc3 divide two numbers
;
; A subroutine to divide the value stored at R2 (dividend) with the value stored at R3 (divisor) (R2 / R3). The result (quotient) is saved at R3.
;
MyDIV AND R1, R1, #0 ; Clear R1 for counter
NOT R3, R3 ; Invert R3
ADD R3, R3, #1 ; 2's Compliment, R3 is now -R3
DIV ADD R2, R2, R3 ; R2 - R3
BRn EndDiv ; If negative then go to end
ADD R1, R1, #1 ; Increase counter
BRp DIV ; If positive repeat (we can still divide)
EndDiv AND R3, R3, #0 ; Clear R3
ADD R3, R3, R1 ; Move final answer to R3
RET