Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

LC-3 help please!! Exercise 1: Stack PUSH 1. Write the following subroutine: ; Subroutine: SUB_STACK_PUSH ; Parameter (RO): The value to push onto the stack

LC-3 help please!!

image text in transcribedimage text in transcribed

Exercise 1: Stack PUSH 1. Write the following subroutine: ; Subroutine: SUB_STACK_PUSH ; Parameter (RO): The value to push onto the stack ; 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 pushed (RO) onto the stack (i.e to address TOS+1). ; If the stack was already full (TOS = MAX), the subroutine has printed an ; overflow error message and terminated. ; Return value: R6 updated TOS Test Harness: To ensure that your subroutine works, write a short test harness. Make sure your stack stores the values as expected in memory and prints an overflow error message as necessary. Exercise 2: Stack POP Write the following subroutine: ; Subroutine: SUB_STACK_POP ; 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 MEM[TOS] off of the stack and copied it to RO. ; If the stack was already empty (TOS = BASE), the subroutine has printed an underflow error message and terminated. ; Return values: RO value popped off the stack ; R6 updated TOS 3 Test Harness: Add a call to the POP subroutine to your test harness from exercise 1. Make sure your TOS value updates as expected, and that overflow/underflow error messages print appropriately. 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

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

The Manga Guide To Databases

Authors: Mana Takahashi, Shoko Azuma, Co Ltd Trend

1st Edition

1593271905, 978-1593271909

More Books

Students also viewed these Databases questions