Question: my program does not perform the desired operation correctly. For addition it performs subtraction and for the other operations it just performs addition. / Addition,

my program does not perform the desired operation correctly. For addition it performs subtraction and for the other operations it just performs addition.
/ Addition, Subtraction, Multiplication, and Division Calculator
/ Main Loop
MainLoop, CLEAR / Clear the result
STORE Result / Store zero in Result
INPUT / Prompt user to enter the first integer
STORE X / Store the input in variable X
INPUT / Prompt user to enter the operator (enter ASCII value in decimal)
STORE Operator / Store the operator in variable Operator
INPUT / Prompt user to enter the second integer
STORE Y / Store the input in variable Y
/ Determine which operation to perform
LOAD Operator
SUBT PlusOp
SKIPCOND 400
JUMP ADD
LOAD Operator
SUBT MinusOp
SKIPCOND 400
JUMP SUBTRACT
LOAD Operator
SUBT MultOp
SKIPCOND 400
JUMP MULTIPLY
LOAD Operator
SUBT DivOp
SKIPCOND 400
JUMP DIVIDE
/ Invalid operator entered
JUMP InvalidOp
/ Addition Subroutine
ADD, LOAD X
ADD Y
STORE Result
JUMP DISPLAY
/ Subtraction Subroutine
SUBTRACT, LOAD X
SUBT Y
STORE Result
JUMP DISPLAY
/ Multiplication Subroutine
MULTIPLY, CLEAR
STORE Result
LOAD Y
STORE TempY
MULTIPLY_LOOP, LOAD TempY
SKIPCOND 000
JUMP MULTIPLY_END
LOAD X
ADD Result
STORE Result
LOAD TempY
SUBT One
STORE TempY
JUMP MULTIPLY_LOOP
MULTIPLY_END, JUMP DISPLAY
/ Division Subroutine
DIVIDE, CLEAR
STORE Quotient
LOAD X
STORE Remainder
DIVIDE_LOOP, LOAD Remainder
SUBT Y
SKIPCOND 800
JUMP DIV_EXIT
STORE Remainder
LOAD Quotient
ADD One
STORE Quotient
JUMP DIVIDE_LOOP
DIV_EXIT, LOAD Quotient
STORE Result
JUMP DISPLAY
/ Invalid operator handling
InvalidOp, CLEAR
STORE Result
JUMP DISPLAY
/ Display the result
DISPLAY, LOAD Result
OUTPUT
JUMP MainLoop / Go back to main loop
/ Define variables
X, DEC 0
Y, DEC 0
Operator, DEC 0
Result, DEC 0
Quotient, DEC 0
Remainder, DEC 0
TempY, DEC 0
PlusOp, DEC 43/ ASCII code for '+'
MinusOp, DEC 45/ ASCII code for '-'
MultOp, DEC 42/ ASCII code for '*'
DivOp, DEC 47/ ASCII code for '/'
One, DEC 1

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!