Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

(Please only answer if you konw how to do this in ARM7 assembly language. Thank You) INTRODUCTION: In Reverse Polish(postfix) notation the operators follow their

(Please only answer if you konw how to do this in ARM7 assembly language. Thank You)

INTRODUCTION: In Reverse Polish(postfix) notation the operators follow their operands; for instance, to add three and four one would write "3 4 +" rather than "3 + 4". If there are multiple operations, the operator is given immediately after its second operand; so the expression written "3 4 + 5" in conventional infix notation would be written "3 4 5 +" in RPN: first subtract 4 from 3, then add 5 to that. An advantage of RPN is that it obviates the need for parentheses that are required by infix. While "3 4 + 5" can also be written "(3 4) + 5", that means something quite different from "3 (4 + 5)", and only the parentheses disambiguate the two meanings. In postfix, the latter would be written "3 4 5 + ", which unambiguously means "3 (4 5 +) ". Interpreters of Reverse Polish notation are stack-based; that is, operands are pushed onto a stack, and when an operation is performed, its operands are popped from a stack and its result pushed back on. Stacks, and therefore RPN, have the advantage of being easy to implement and very fast. Please complete the implementation of the two functions given in the questions section below. Test your functions using the main program given.

QUESTION 1: Write a function to convert a given function from infix to postfix in assembly. The basic structure of the function is given in the attached assembly language file. QUESTION 2: Write a function to convert a given function from postfix to infix in assembly language. The basic structure of the function is given in the attached assembly language file.

Infix to Postfix Conversion: In normal algebra we use the infix notation like a+b*c. The corresponding postfix notation is abc*+. The algorithm for the conversion is as follows: Scan the Infix string from left to right.

Initialize an empty stack.

If the scanned character is an operand, add it to the Postfix string. If the scanned character is an operator and if the stack is empty Push the character to stack.

If the scanned character is an Operand and the stack is not empty, compare the precedence of the character with the element on top of the stack (topStack). If topStack has higher precedence over the scanned character Pop the stack else Push the scanned character to stack. Repeat this step as long as stack is not empty and topStack has precedence over the character.Repeat this step till all the characters are scanned.

(After all characters are scanned, we have to add any character that the stack may have to the Postfix string.) If stack is not empty add topStack to Postfix string and Pop the stack. Repeat this step as long as stack is not empty.

Return the Postfix string.

The main C code to test your assembly code:

#include

extern char* toPostFix(char *); extern char* toInFix(char *);

int main(void) {

char convertedstring2[255]; char convertedstring1[255],checkstring1[255],checkstring2[255]; char *convstr1, *convstr2; char *chkstr1, *chkstr2;

char string1[255]="A*B+(C*D)+E"; char string2[255]="(A+B)*(C+D)+E"; convstr1 = convertedstring1; convstr2 = convertedstring2; convstr1=toPostFix(string1); convstr2=toPostFix(string2);

chkstr1 = checkstring1; chkstr2 = checkstring2; chkstr1=toPostFix(convertedstring1); chkstr1=toPostFix(convertedstring2);

printf(" String 1- Infix to Postfix is %s ",convertedstring1); printf(" String 2- Infix to Postfix is %s ",convertedstring2); printf(" String 1- Postfix to Infix is %s ",checkstring1); printf(" String 2- Postfix to Infix is %s ",checkstring2); return EXIT_SUCCESS; }

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

Put Your Data To Work 52 Tips And Techniques For Effectively Managing Your Database

Authors: Wes Trochlil

1st Edition

0880343079, 978-0880343077

More Books

Students also viewed these Databases questions

Question

11-1 What is the role of knowledge management systems in business?

Answered: 1 week ago

Question

How do Data Types perform data validation?

Answered: 1 week ago

Question

How does Referential Integrity work?

Answered: 1 week ago