Description
Esad Yusuf Atik – Orkun Mahir Kılıç
In this project, we started with planning the a86 labels and their contents. As a86 is limited in terms of registers and capabilities, writing the code was straightforward after determining the algorithm.
Postfix evaluation algorithm works as following;
1. Create a stack.
2. Scan the input starting from left.
3. If input is a hex number, push it to stack.
4. If input is operator, pop the last two from stack and evaluate with operator.
Source: https://www.geeksforgeeks.org/stack-set-4-evaluation-postfix-expression/ After running the program, flow goes like this:
● First the program initializes the registers. We used 2 additional registers as helpers for input and output operations. “si” register is used for counting output digits. “di” is used for determining whether the input is an operator or a number.
● Program starts an interrupt to read input from the console.
● If input is space, the program looks at the type of the input before. If it is an operator, the program continues reading.
● If it is a number, pushes it into the stack.
● If it is a letter, the program converts it to a number in order to make operations.
● Then if it continues, then the input is multidigit. The program evaluates the multi digits and converts into a number.
● If input is “enter” character. It jumps to the output label.
● New interrupt is started
● Pop and divide by 10 for 4 times as we need to output 4 digits. Then push in every cycle.
● Jump to the final label.
● Pop from stack, if it is letter-number. Convert it to ascii in order to print correctly. (x4 times again).
Reviews
There are no reviews yet.