Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

FIX THE DIVISION AND ONLY THE DIVISION SO IT OUTPUTS BOTH THE QUOTIENT AND REMAINDER. EXAMPLE: Enter the first operand: 2 Enter the second operand:

FIX THE DIVISION AND ONLY THE DIVISION SO IT OUTPUTS BOTH THE QUOTIENT AND REMAINDER.

EXAMPLE:

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.

IN THIS CODE IN LC3:

.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, DIV_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 R3 is non-positive, exit the loop

BRz DIV_DONE ADD R4, R4, #-1 BR DIV_DONE

; Display the '-' sign for negative results LD R0, MINUS OUT

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

;;;;;;;;;;;;;;;;;;; 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: " DIV_RESULT .STRINGZ " DIVISION: " 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_2

Step: 3

blur-text-image_3

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

Fundamentals Of Database Management Systems

Authors: Mark L. Gillenson

2nd Edition

0470624701, 978-0470624708

More Books

Students also viewed these Databases questions

Question

1. Explain how business strategy affects HR strategy.

Answered: 1 week ago