Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Conceptual Database Design An Entity Relationship Approach

Authors: Carol Batini, Stefano Ceri, Shamkant B. Navathe

1st Edition

0805302441, 978-0805302448

More Books

Students also viewed these Databases questions