== Expressions ==
An expression includes all forms of commands that require usage of the ALU excepting logic functions . They also include function calls but these will be covered later. In this chapter we deal with the conversion of simple expressions or expressions excluding parenthesis and function calls or any sort of referencing.
== Basic Operations ==
We all know the four basic arithmetic operations that is +,-,*,/. Together they combine to form expressions such as :
a*b+cHowever assembly language does not recognize such expressions, but it only recognizes binary commands such as:
Also it does not recognize precedence. It just executes commands as they are presented in a sequential order. Thus we have to order theses commands by ourselves.
Also the results are always stored in a certain location known as a register. More specifically it is stored in the Eax register.
== Instructions ==
There are the following instructions for each operation on integers. For operations on char replace eax by al:
Cdq (sign extension, mandatory but only once in the program)
Following are the corresponding instructions for floats.
There is no modulus for float variables.
== Algorithm For Conversion ==
1. While character not ; or *,/,%.
1.1 If character be ; goto part2
1.2 get operand before operator and after
1.3 depending on operator use the appropriate instructions as given above.
1.4 remove the operands and operator from the line
1.5 if next operator be add or sub replace by var[NUM] where NUM is an int and incremented. Write var[NUM] as a variable of type of expression. Assign eax to var[NUM].
1.6 else replace by eax.
2. Repeat step 1
For char replace eax by al and for float assign st(1) to var[NUM].
1. While character not ; or + or -
1.1 If character be ; end process
1.2 get operand before and after the operator
1.3 depending on operator use the appropriate instruction as given above
(Follow steps 1.4 to 1.6)
2. Repeat step 1