Debug IA32 Code Generation in C

In Progress Posted Apr 15, 2013 Paid on delivery
In Progress Paid on delivery

This is a high level programming project, thus I need someone who fits this skill set. I have already written the code called hw9.gen.parser.c, as a text file, however I need help debugging the program. I will need this program in 11 hours, and I have attached all the files you need to run this as well.

In this homework, we are going to do the Intel IA32 codes generation by processing the abstract syntax tree constructed from the parsing process.

For a C program, one can run gcc to generate the Intel assembly codes by the following command:

gcc -S prog.c

The assembly codes are found in the file with the name prog.s.

For this homework, we want to learn to generate codes for 32-bit Intel architecture, which are simpler than the codes for 64-bit architecture. Also, the codes generated by the older gcc (gcc 3.x) is also easier for follow.

To run gcc 3.x, add the following alias to your Linux environment:

alias gcc3 /home/CS473/sp12/gcc34/bin/gcc -m32

Moreover, you may want to run it with a low level of optimization as in:

gcc3 -O1 -S prog.c

or

gcc3 -O0 -S prog.c

From the assembly codes, you can learn a lot about IA32 instructions.

Your job is to write a program hw9.gen.codes.c, which you can modify from hw8.gen.codes.c (which generates codes for three-address intermediate codes, while IA32 are two-address codes).

To make a function call, one way is to follow the instructions given here under "Calling Functions". Arguments are passed by pushl, followed by a call to the function, then discarding the arguments by changing the stack pointer %esp using addl, and finally retrieve the function result from register %eax. In this homework, we suggest you to use the above method. However, gcc (or, gcc 3.x) uses a more efficient way. You can run gcc3 -S to see the assembly codes generated for calling a function. We will explain the method used by gcc's in class. Next, consider the function call:

c = f(a,b);

We need to push the argument b first, then push the argument a, followed by calling function f, saved the value of %eax to c. In order to generate the pushes for the arguments in the right order, when processing an ast node of the type AST_ARG_LIST, the correct logic is to process the right subtree before the left subtree.

C Programming

Project ID: #4433041

About the project

1 proposal Remote project Active Apr 16, 2013

Awarded to:

xuhaijiao

Hi, i am interested with this work

$99 USD in 1 day
(0 Reviews)
0.0