Question
FIX THE DIVISION AND ONLY THE DIVISION SO IT OUTPUTS BOTH THE QUOTIENT AND REMAINDER. FIX IT SO IT OUTPUT THE NEEDED OUTPUT CURRENT OUTPUT:
FIX THE DIVISION AND ONLY THE DIVISION SO IT OUTPUTS BOTH THE QUOTIENT AND REMAINDER. FIX IT SO IT OUTPUT THE NEEDED OUTPUT
CURRENT OUTPUT: ENTER FIRST OPERAND : 2 ENTER SECOND OPERAND: 4
ADDITION: 6 SUBTRACTION: -2 MULTIPLICATION: 8 Division RESULT QUOTIENT: -0 DIVISION RESULT REMAINDER: *
OUTPUT NEEDED: Enter the first operand: 2 Enter the second operand: 4 Addition result = 6 Subtraction result = -2 Multiplication result = 8 Division result Quotient= 0 Division result Remainder = 2 Exiting.
.ORIG x3000
ld R3, MINUSx30 ; R3 <- x-30 (ASCII 0) ld R6, PLUSx30
; GET THE FIRST OPERAND lea R0, getop1 ;Prompt user puts getc ; Read the character out ; Echo the character add R1, R0, R3 ; first operand is in R1
; GET THE SECOND OPERAND lea R0, getop2 puts getc ; Read the next character out ; Echo the character add R2, R0, R3 ; second operand in R2
; OUTPUT A NEXT-LINE CHARACTER (10) and R0, R0, #0 add R0, R0, #10 ;#10 is Line feed in ASCI out ;;;;;;;;;;;;;;;;;;;;;; ADDITION
; Output a Message LEA R0, ADD_RESULT PUTS
; ADD the two numbers, Convert result to ASCII & Display add R0, R1, R2 ; R0 <- R1 + R2 add R0, R0, R6 ; R0 <- R0 +x30 out ; Output result
;;;;;;;;;;;;;;;;;;;;;; SUBTRACTION
;Get twos compliment of second operand NOT R3, R2 ADD R3, R3, #1
; Output a Message LEA R0, SUB_RESULT PUTS
; Perform subtraction by addition ;ADD R0,R1,R3 ; Perform operation ; *** if first operand is larger ADD R4,R1,R3 ; Perform operation ; *** if first operand is smaller BRZP POS ; Result is positive ; Result is negative, display - sign LD R0, MINUS ; Result negative. Display '-' OUT ;ADD R0, R4, #0 ; R0 <- R4 NOT R4, R4 ; Take twos complement of result ADD R4, R4, #1 POS LD R3, PLUS30 ADD R0, R3, R4 ;Converts to ASCII digit OUT ;Display Result
;;;;;;;;;;;;;;;;;;;;;; MULTIPLICATION
; Output a Message
LEA R0, MUL_RESULT PUTS
AND R3, R3, #0 ; Clear R3
AND R4, R4, #0 ; Initialize R4 to 0 (quotient) ADD R5, R2, #0
MUL_LOOP ADD R3, R3, R1 ; Accumulate R1 in R3 ADD R4, R4, #1 ; Increment quotient ADD R5, R5, #-1 ; Decrement multiplier BRP MUL_LOOP
ADD R0, R3, R6 OUT
;;;;;;;;;;;;;;;;;;;;;; DIVISION
; Output a Message LEA R0, QUO_RESULT PUTS
; Initialize R4 to 0 (quotient) and R5 to 0 (sign flag) AND R3, R3, #0 AND R4, R4, #0 AND R5, R5, #0
NOT R2, R2 ; Negate R2 (if R2 is negative) ADD R2, R2, #1 ; Flip the sign flag
DIV_LOOP ADD R4, R4, #1 ADD R1, R1, R2 ; Subtract R2 from R1
BRp DIV_LOOP ; If R1 is non-negative, continue the loop BRz DIV_DONE ; If R1 is zero, exit the loop
ADD R4, R4, #-1 ; Adjust quotient for negative results ADD R1, R1, R2 ; Restore the value of R1
; Calculate the remainder ADD R3, R1, #0 ; R3 <- R1 (remainder)
; Display the '-' sign for negative results LD R0, MINUS OUT
DIV_DONE ADD R0, R4, R6 ; Convert the quotient to ASCII OUT ; Display the quotient
LEA R0, REM_RESULT PUTS ; Output a message for the remainder
ADD R0, R3, R6 ; Convert the remainder to ASCII OUT ; Display the remainder ;;;;;;;;;;;;;;;;;;; EXIT
LEA R0, EXIT PUTS
HALT ; Done
; DATA DECLARATIONS
getop1 .STRINGZ " ENTER FIRST OPERAND : " getop2 .STRINGZ " ENTER SECOND OPERAND: " ADD_RESULT .STRINGZ " ADDITION: " SUB_RESULT .STRINGZ " SUBTRACTION: " MUL_RESULT .STRINGZ " MULTIPLICATION: " QUO_RESULT .STRINGZ " Division RESULT QUOTIENT: " REM_RESULT .STRINGZ " DIVISION RESULT REMAINDER: " EXIT .STRINGZ " Exiting"
MINUSx30 .FILL x-30 PLUSx30 .FILL x30 PLUS30 .FILL x30 MINUS30 .FILL x-30 MINUS .FILL X2D .end ; END OF CODE
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