Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Utilizing these two subroutines create a third subroutine per instructions. PRINTDEC - Print a 1 6 - bit number as decimal 2 . A 1
Utilizing these two subroutines create a third subroutine per instructions.
PRINTDEC Print a bit number as decimal
A bit number will be stored in R You will have to figure out each digit one at a time and print
each.
DO NOT PRINT leading zeros. Loop until a nonzero digit is found and then print the rest of the digits.
YOU CAN NOT ignore all zeros. Only ignore leading zeros.
DO NOT PRINT a newline at the end.
Your program should print a single if R is
Assume you have a number like in R
Divide by to get add and print it
Divide by to get Mod by to get add and print it
Divide by to get Mod by to get add and print it
Divide by to get Mod by to get add and print it
Divide by to get Mod by to get add and print it
Assume you have a number like in R
Divide by to get Ignore it
Divide by to get Ignore it
Divide by to get Mod by to get add and print it
Divide by to get Mod by to get add and print it
Divide by to get Mod by to get add and print it
; Division subroutine
DIV
ST R PUSHR ; Save R
ST R PUSHR ; Save R
ST R PUSHR ; Save R
ST R PUSHR ; Save R
ST R PUSHR ; Save R
AND R R # ; Clear R to use as counterresult
; Check for division by zero or negative inputs
ADD R R # ; Prepare to check R
BRz DIVERROR ; Division by zero
BRn DIVERROR ; Negative divisor
ADD R R # ; Prepare to check R
BRn DIVERROR ; Negative dividend
; Main division loop
DIVLOOP
ADD R R # ; Check if we can still subtract
NOT R R
ADD R R #
ADD R R R ; R R R
BRn DIVEND ; If R is negative, we're done
ADD R R R ; Subtract R from R
ADD R R # ; Increment the result
BR DIVLOOP ; Repeat the loop
DIVERROR
LD R NEGONE ; Set R to to indicate error
DIVEND
LD R PUSHR ; Restore R
LD R PUSHR ; Restore R
LD R PUSHR ; Restore R
LD R PUSHR ; Restore R
LD R PUSHR ; Restore R
RET ; Return from the subroutine
; Modulo subroutine
MOD
ST R PUSHR ; Save R
ST R PUSHR ; Save R
ST R PUSHR ; Save R
ST R PUSHR ; Save R
ST R PUSHR ; Save R
AND R R # ; Clear R to use for the result
; Modulo checks and operations
ADD R R # ; Check if divisor R is zero
BRz MODERROR ; If zero, cannot mod by zero, error
BRn MODERROR ; Negative divisor, error
ADD R R # ; Check if dividend R is negative
BRn MODERROR ; Negative dividend, error
MODLOOP
ADD R R # ; Prepare for subtraction
NOT R R
ADD R R # ; Get R for subtraction
ADD R R R ; Try subtracting R from R
BRn MODEND ; If R R we have our remainder
ADD R R R ; Subtract R from R and continue loop
BR MODLOOP
MODERROR
LD R NEGONE ; Error, set R to
MODEND
LD R PUSHR ; Restore R
LD R PUSHR ; Restore R
LD R PUSHR ; Restore R
LD R PUSHR ; Restore R
LD R PUSHR ; Restore R
RET ; Return from subroutine
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started