Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

SQL Antipatterns Avoiding The Pitfalls Of Database Programming

Authors: Bill Karwin

1st Edition

1680508989, 978-1680508987

More Books

Students also viewed these Databases questions

Question

How does an in-depth interview differ from a survey?

Answered: 1 week ago

Question

=+8.12. Show that sup ,, no(i, j) = is possible in Lemma 2.

Answered: 1 week ago

Question

Detailed note on the contributions of F.W.Taylor

Answered: 1 week ago

Question

1. Identify three approaches to culture.

Answered: 1 week ago

Question

2. Define communication.

Answered: 1 week ago