Code Generation/Exercise 7

From Wiki**3

< Code Generation
Revision as of 00:39, 2 May 2018 by Root (talk | contribs) (Postfix Code)

The Original Code

Consider the following C function:

<c> int *traverse(int vec[], int lim) {

 int *ptr = vec + lim - 1, ix = lim - 2;
 while (ix >= 0) {
   ptr = (vec[ix] > *ptr) ? vec + ix : ptr;
   ix--;
 }
 return ptr;

} </c>

Postfix Code

The Postfix code for the above function is as follows:

Postfix code
{{{2}}}

Compiling and Running

To compile the Postfix code directly, pf2asm can be used:

pf2asm traverse.pf
yasm -felf traverse.asm