All submissions for this problem are available.
PostFix Instructions to Assembly Code
A very famous company requires a backend for a translator for a Simplified Instructional Computer.
Input to the translator will be arithmetic expressions in postfix form and the output will be assembly language code.
A single register will be present in the target machine along with the following instructions, where the operand is either an identifier or a storage location.
L -- load the operand into the register A -- add the operand to the contents of the register S -- subtract the operand from the contents of the register M -- multiply the contents of the register by the operand D -- divide the contents of the register by the operand N -- negate the contents of the register ST -- store the contents of the register in the operand location
The contents of the register are replaced with the expression result by an arithmetic operation.
Assembler allocates temporary storage locations for an operand of the form "$n" where n is a single digit.
The input file consists of several legitimate postfix expressions, each on A separate line. Expression operands are single letters and operators are the normaL arithmetic operators (+, -, *, /)
Output must be assembly language code that meets the following requirements: 1. One instruction per line with the instruction mnemonic separated from the operand (if any) by one blank. 2. One blank line must separate the assembly code for successive expressions. 3. The originaL order of the operands must be preserved in the assembly code. 4. Assembly code must be generated for each operator as soon as it is encountered. 5. As few temporaries as possible shouL be used (given the above restrictions). 6. For each operator in the expression, the minimum number of instructions must be generated (given the above restrictions).
Input: AB+CD+EF++GH+++ AB+CD+- Output: L A A B ST $1 L C A D ST $2 L E A F A $2 ST $2 L G A H A $2 A $1 L A A B ST $1 L C A D N A $1
|Time Limit:||6 sec|
|Source Limit:||50000 Bytes|
|Languages:||C, CPP14, JAVA, GO, NODEJS, PYP3|
Fetching successful submissions
If you are still having problems, see a sample solution here.