Code Generation/Exercise 7: Difference between revisions
From Wiki**3
< Code Generation
| Line 17: | Line 17: | ||
The Postfix code for the above function is as follows:    | The Postfix code for the above function is as follows:    | ||
{{CollapsedCode|Postfix code|  | |||
<asm>  | <asm>  | ||
TEXT  | TEXT  | ||
| Line 129: | Line 129: | ||
RET  | RET  | ||
</asm>  | </asm>  | ||
}}  | |||
== Compiling and Running ==  | == Compiling and Running ==  | ||
Revision as of 07:33, 9 May 2017
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