Question
LC3 CAN SOMEONE FIX WHAT I HAVE SO TTHE RESULT IS SOMETHING LIKE Enter the first operand: 4 Enter the second operand: 2 Addition result
LC3 CAN SOMEONE FIX WHAT I HAVE SO TTHE RESULT IS SOMETHING LIKE
Enter the first operand: 4
Enter the second operand: 2
Addition result = 6
Subtraction result = 2
Multiplication result = 8
Division result Quotient = 2
Division result Remainder = 0
Exiting.
.ORIG x3000
LD R3, MINUSx30 ; Operand 1 LEA R0, getop1 PUTS GETC OUT ADD R1, R0, R3 ; Operand 2 LEA R0, getop2 PUTS GETC OUT ADD R2, R0, R3
; Add ADD R0, R1, R2 LD R3, PLUSx30 ADD R0, R0, R3
LEA R0, ADD_RESULT PUTS OUT
; Subtract NOT R2, R2 ADD R2, R2, #1
LEA R0, SUB_RESULT PUTS
ADD R0, R1, R2 BRZP POS ADD R4, R0, #0
BRNZP SKIP_INPUT
LEA R0, MINUS PUTS ADD R0, R4, #0 NOT R0, R0 ADD R0, R0, #1
POS LD R3, PLUSx30 ADD R0, R3, R0 OUT
SKIP_INPUT
; Multiply ADD R0, R1, #0 ADD R2, R2, #0
MUL_LOOP BRZP MUL_PRINT ADD R0, R0, R1 ADD R2, R2, #1 ADD R2, R2, #-1 BRNZP MUL_LOOP
MUL_PRINT LEA R0, MUL_RESULT PUTS OUT
JSR Divide
; Print Quotient LEA R0, DIV_RESULT_QUO PUTS OUT ADD R0, R0, R0
; Print Remainder LEA R0, DIV_RESULT_REM PUTS OUT
; Exit Message LEA R0, EXIT_MSG PUTS HALT
; Divide subroutine Divide ST R3, SaveReg3 LD R1, dividend LD R2, divisor AND R0, R0, #0 NOT R3, R2 ; TWOs complement ADD R3, R3, #1 DivideLoop ADD R1, R1, R3 ; subtraction loop BRN DivideDone ST R1, REM ; R1 has remainder ADD R0, R0, #1 ; R0 = Quotient BRNZP DivideLoop DivideDone LD R1, REM LD R3, SaveReg3 RET
; DATA SaveReg3 .FILL #0 ; Place to save R3 REM .FILL #0 ; Remainder dividend .FILL #4 ; Operand 1 divisor .FILL #2 ; Operand 2
ADD_RESULT .STRINGZ " Addition result = " SUB_RESULT .STRINGZ " Subtraction result = " MUL_RESULT .STRINGZ " Multiplication result = " DIV_RESULT_QUO .STRINGZ " Division result Quotient = " DIV_RESULT_REM .STRINGZ " Division result Remainder = " EXIT_MSG .STRINGZ " Exiting."
PLUSx30 .FILL x30 MINUSx30 .FILL x-30 MINUS .FILL X2D
getop1 .STRINGZ " Enter the first operand: " getop2 .STRINGZ " Enter the second operand: "
.END
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