Question: FIX THE DIVISON AND ONLY THE DIVISION CODE SO IT ACTUALLY DISPLAYS THE QUOTANT AND REMAINDER. NOT THIS OUTPUT: ENTER FIRST OPERAND : 5 ENTER

FIX THE DIVISON AND ONLY THE DIVISION CODE SO IT ACTUALLY DISPLAYS THE QUOTANT AND REMAINDER. NOT THIS OUTPUT:

ENTER FIRST OPERAND : 5

ENTER SECOND OPERAND: 4

ADDITION: 9

SUBTRACTION: 1

MULTIPLICATION: D

Division RESULT QUOTIENT: 1

DIVISION RESULT REMAINDER: )

**(REMAINDER SHOULD BE 1)**

.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 for Quotient LEA R0, QUO_RESULT PUTS

; Initialize R4 to 0 (quotient) 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

BRz DIV_DONE ; Exit the loop if R1 is zero

BRp DIV_LOOP ; Continue the loop if R1 is non-negative

ADD R4, R4, #-1 ; Adjust quotient for negative results ADD R1, R1, R2 ; Restore the value of R1

DIV_DONE

; Calculate the remainder ADD R3, R1, #0 ; R3 <- R1 (remainder)

; Display the '-' sign for negative results LD R0, MINUS BRn DIV_DISPLAY ; If R1 is negative, skip displaying '+' sign

DIV_DISPLAY ; OUT ; Display the '-' sign

; Display the quotient ADD R0, R4, R6 ; Convert the quotient to ASCII OUT ; Display the quotient

LEA R0, REM_RESULT PUTS ; Output a message for the remainder

; Display 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

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 Databases Questions!