# Arithmetic operations

Some Semantics:• Consider that “true” has an integer value of 1 and “false” has an integer value of 0.• No arithmetic operations are allowed for booleans.• The types must match for arithmetic operations (no conversions)Part 1) Symbol table Handling (3 points): Every identifier declared in the program shouldbe placed in a symbol table and accessed by the symbol table handling procedures.a) Each entry in the symbol table should hold the lexeme, and a “memory address” where anidentifier is placed within the symbol table. For example, define a global integer variable called“Memory_address” and set initially 5000 and increment it by one when a new identifier isdeclared and placed into the table.b) You need to write a procedure that will check to see if a particular identifier is already in thetable, a procedure that will insert into the table and a procedure that will printout all identifiers inthe table. If an identifier is used without declaring it, then the parser should provide an errormessage. Also, if an identifier is already in the table and wants to declare it for the second time,then the parser should provide an error message. Also, you should check the type match.Part 2) Generating the assembly code (12 points):Add code (See the partial solution) to your parser that will produce the assembly codeinstructions. The instructions should be kept in an array and at the end, the content of the array isprinted out to produce the listing of assembly code. Your array should hold at least 300 assemblyinstructions. The instruction starts from 1.The listing should include an array index for each entry so that it serves as labelto jump to. The compiler should also produce a listing of all the identifiers.

2Our target machine is a virtual machine based on a stack with the following instructionsI1. PUSHI {Integer Value} Pushes the {Integer Value} onto the Top of the Stack (TOS)I2. PUSHM {ML – Memory Location} Pushes the value stored at {ML} onto TOSI3. POPM {ML} Pops the value from the top of the stack and stores it at {ML}I4. STDOUT Pops the value from TOS and outputs it to the standard outputI5. STDIN Get the value from the standard input and place in onto the TOSI6. ADD Pop the first two items from stack and push the sum onto the TOSI7. SUB Pop the first two items from stack and push the difference onto the TOS( Second item – First item)I8. MUL Pop the first two items from stack and push the product onto the TOSI9. DIV Pop the first two items from stack and push the result onto the TOS( Second item / First item and ignore the remainder)I10. GRT Pops two items from the stack and pushes 1 onto TOS if second item islarger otherwise push 0I11. LES Pops two items from the stack and pushes 1 onto TOS if the second item issmaller than first item otherwise push 0I12. EQU Pops two items from the stack and pushes 1 onto TOS if they are equalotherwise push 0I13. JUMPZ {IL – Instruction Location} Pop the stack and if the value is 0 then jump to {IL}I14. JUMP {IL} Unconditionally jump to {IL}I15. LABEL Empty Instruction; Provides the instruction location to jump to.A Sample Source Code\$\$[* declarations *]integer iinteger max;integer sum;sum = 0;i = 1;get ( max);while (i < max) {sum = sum + i;i = i + 1;}sum = sum + max;put (sum);\$\$3One Possible Assembly Code Listing1 PUSHI 02 POPM 50023 PUSHI 14 POPM 50005 STDIN6 POPM 50017 LABEL8 PUSHM 50009 PUSHM 500110 LES11 JUMPZ 2112 PUSHM 500213 PUSHM 500014 ADD15 POPM 500217 PUSHM 500017 PUSHI 118 ADD19 POPM 500020 JUMP 721 PUSHM 500222 PUSHM 500123 ADD24 POPM 500225 PUSHM 500224 STDOUTSymbol TableIdentifier Memory Location Typei 5000 integermax 5001 integersum 5002 integerNOTE:

DO NOT CREATE YOUR OWN ASSEMBLY INSTRUCTIONS.USE ONLY PROVIDED INSTRUCTIONS.Turn in your document according to the instructions given in theproject outline.

Sample Solution
The post Arithmetic operations