Consider a 0address stack machine with the following instruc

Consider a 0-address (stack) machine with the following instruction types, where M is a memory address: PUSH M push contents of M onto the stack POP M pop the stack into M ADD pop top two items, add and push the result SUB pop top two items, subtract the top one from the bottom of the two and push the result MUL pop top two items, multiply and push the result DIV pop top two items, divide the bottom of the two by the top one and push the result Write the postfix notation for the expression: (A + B * C)/(D - E * F) Write a program to compute, without destroying the original contents of A to F. X = (A + B * C)/(D - E * F) You may use additional variables if necessary. All data items are integers.

Solution

1.

a.)

Infix expression is : ( A + B * C ) / ( D - E * F )

-> Postfix notation :

-> In postfix notation operand should be after operands.

i.e postfix notation of A + B is A B +

postfix notation of ( A + B * C ) / ( D - E * F ) :

=> ( A + B * C ) ( D - E * F ) /

=> ( A + B * C ) ( D E * F - ) /

=> ( A + B * C ) ( D E F * - ) /

=> ( A B * C + ) ( D E F * - ) /

=> ( A B C * + ) ( D E F * - ) /

=>  A B C * + D E F * - /

postfix notation of ( A + B * C ) / ( D - E * F ) is A B C * + D E F * - /

b.)

// Program for computing X = ( A + B * C ) / ( D - E * F ) using 0 - address machine instruction types

 Consider a 0-address (stack) machine with the following instruction types, where M is a memory address: PUSH M push contents of M onto the stack POP M pop the

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site