Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a division subroutine that takes two values and divides the first by the s

ID: 3861297 • Letter: W

Question

Write a division subroutine that takes two values and divides the first by the second. The numerator should be stored in R1 and the denominator in R2 before division is called, and the result should be stored in R0 before division returns. Since LC-3 only has integers, any remainder should be ignored. Think about how division can be implemented with the tools that we have already – addition and subtraction. Write division to start at x3200. PLEASE USE SPECIFIC NUMBERS AND PLACES SPECIFIED IN PROMPT

Explanation / Answer

MOV R1,#128 ;divide R1

MOV R2,#4 ;by R2

MOV R0,#0 ;initialise counter

.subtract

SUBS R1,R1,R2 ;subtract R2 from

;R1 and store

;result back in

;R1 setting flags

ADD R0,R0,#1 ;add 1 to counter,

;NOT setting flags

BHI subtract ;branch to start of

;loop on condition

;Higher, i.e. R1 is

;still greater than

;R2. Answer now in R0

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote