You are here

Laboratory 8

In laboratory 8 you will be performing code generation for the x86 architecture. Start by downloading the laboratory 8 template. This template contains a lexer and parser for the csem intermediate form and contains many support routines for code generation. For this lab you will need to generate working code for the test example named "test.t". The provided make file will build the example intermediate form into an executable by combining its resulting assembly with the file "test.c" and compiling both using GCC (using "make test").

After the test program has been built, you can test the program by simply executing it like any other program on your machine. If your program crashes, due to incorrect code generation, you can debug your program using the standard GDB debugger.

For code generation itself, see the listed assembly references below. Additionally, you can see the assembly generated by GCC by using the "-S" flag. For instance, executing "gcc -S -o test.S test.c" will produce an assembly file named "test.S" that is the result of compiling the C file "test.c" into X86 assembly. You can use this to help you construct the correct code during code generation.

Reference Material for X86 Assembly:

  1. http://ref.x86asm.net/coder32.html
  2. http://en.wikibooks.org/wiki/X86_Assembly/GAS_Syntax
  3. http://en.wikibooks.org/wiki/X86_Disassembly/Calling_Conventions
  4. http://siyobik.info/index.php?module=x86

Laboratory 8 Extension

Once done with the first part of the laboratory, extend the parser to generate code for the entire integer subset of the intermediate form. Once completed, your code generator should be able to correctly generator code for all of the following:

  1. Integer unary operations
    integer negation, integer bitwise inversion, and integer dereferencing

  2. Integer binary operations
    integer add, integer subtract, integer multiply, integer divide, integer modulus, integer shift left, integer shift right, integer and, integer or, integer xor, integer assignment, and integer indexing

  3. Integer comparison operations
    integer greater than or equal to, integer greater than, integer equal to, integer not equal to, integer less than, and integer less than or equal to.

  4. Function calls
    integer call, integer return, and integer argument

Note that you do not need to implement integer to floating point conversion. Additionally, you will need to construct and submit a complete test case for all of the operations by extending the test case (test.t and test.c) present in the project template.

Theme by Danetsoft and Danang Probo Sayekti inspired by Maksimer