Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a complete program in MIPS assembly language that evaluates arithmetic expressions. The expressions must be fully parenthesized and include the following expressions + (addition)

Write a complete program in MIPS assembly language that evaluates arithmetic expressions. The expressions must be fully parenthesized and include the following expressions

  1. + (addition)
  2. - (subtraction)

For simplicity all numbers in the expression will have only one base ten digit (0, 1, 2, 3, 4, 5, 6, 7, 8, 9) in them. Your program must be composed of four states: input, convert-to-postfix, evaluate, and output states. At input data must be provided through the console and stored as an array of characters. After one expression is entered your program moves to the convert-to-postfix state. At this state your expression must be converted to the postfix notation using a stack-based algorithm. Your program must then move to the evaluate state which evaluates the postfix expression using a stack-based algorithm. At the output state your code must display the complete expression in the postfix notation followed by the = symbol and the expressions numeric result.

Example

Some valid expressions and their corresponding postfix notations are:

  1. ((1-3)+5) corresponds to 13-5+ in postfix notation
  2. (1-(3+5)) corresponds to 135+- in postfix notation

Shown below is the Console display for expression a) above:

Console

Expression to be evaluated:

((1 - 3) + 5)

13-5+ = 3

Postfix Notation

Consider a set of all valid, completely parenthesized, infix arithmetic expressions consisting of nonnegative integer digits, and the two operations +, -. The following definition gives all such valid expressions:

  1. Any nonnegative integer is a valid infix expression.
  2. If a and b are valid infix expressions, then (a+b), and (a-b) are valid infix expressions.
  3. The only valid infix expressions are those defined by steps 1 and 2.

The character string ((5-1) +3) is an example of a complete parenthesized expression. All valid fully parenthesized infix expressions will have at least one operator.

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

Case Studies In Business Data Bases

Authors: James Bradley

1st Edition

0030141346, 978-0030141348

More Books

Students also viewed these Databases questions

Question

Define procedural justice. How does that relate to unions?

Answered: 1 week ago