Question
Exercise 3: Reverse Polish Calculator Reverse Polish Notation (RPN) is an alternative to the way we usually write arithmetic expressions. When we want to add
Exercise 3: Reverse Polish Calculator Reverse Polish Notation (RPN) is an alternative to the way we usually write arithmetic expressions. When we want to add two numbers together, we usually write, "12 + 7" and get 19 as a result. In RPN, to express the same thing, we write, 12 7 +" and get 19 - i.e. we first specify the two operands, then the operation to be performed on them. In this exercise, you will implement a Reverse Polish Notation Calculator that performs a single operation, multiplication. 3 Subroutine (write me!) ; Subroutine: SUB_RPN_MULTIPLY ; Parameter (R4): BASE: A pointer to the base one less than the lowest available address) of the stack ; Parameter (R5): MAX: The "highest" available address in the stack ; Parameter (R6): TOS (Top of Stack): A pointer to the current top of the stack ; Postcondition: The subroutine has popped off the top two values of the stack, multiplied them together, and pushed the resulting value back onto the stack. ; Return value: R6 - updated to address ; Your main program must do the following: 1. Prompt user for a single digit numeric character, and convert it to a number in RO (if you wish, you can invoke a helper s/r to do this); then invoke PUSH s/r to push RO onto stack. 2. Repeat, to get second operand & push it onto stack. 3. Prompt for the operation symbol (in this case, a "*"). You can simply discard it once received, since multiplication is the only operation we are implementing. 4. Call the SUB_RPN_MULTIPLY subroutine to pop the top two values off the stack, multiply them, and push the result back onto the stack. - if you wish, you may use a helper s/r to do the actual multiplication - it only needs to handle the multiplication of two single digit numbers. 5. POP the result off the stack and print it out to the console in decimal format. - use a helper s/r to do the output: pass in the number in RO, and print it as numeric characters; it only has to be able to print 1 or 2 digit numbers. (You can use your lab 7 subroutine to do this). Hints: You will need the following subroutines to get the job done: SUB_STACK_PUSH (exercise 1) o SUB_STACK_POP (exercise 2) o SUB_RPN_MULTIPLY SUB_MULTIPLY (optional) SUB_GET_NUM (optional) O SUB_PRINT_DECIMAL (use the subroutine from lab 7) You do not need to implement any input validation - we will test only with single-digit numbers
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