Code Generation/Exercise 5: Difference between revisions
From Wiki**3
< Code Generation
(Created page with "== The Original Code == Consider the following C function: <c> int gcd(int a, int b) { static int temp = 0; if (temp) temp = swap(&a, &b); while (1) { a %= b; if ...") |
No edit summary |
||
| Line 32: | Line 32: | ||
* yasm -felf gcd.asm | * yasm -felf gcd.asm | ||
[[category: | [[category:Compiladores]] | ||
[[category: | [[category:Ensino]] | ||
Revision as of 14:30, 6 April 2015
The Original Code
Consider the following C function:
<c> int gcd(int a, int b) {
static int temp = 0;
if (temp) temp = swap(&a, &b);
while (1) {
a %= b;
if (a == 0) break;
b %= a;
if (b == 0) return a;
}
return b;
} </c>
Postfix Code
The Postfix code for the above function is as follows:
<asm>
</asm>
Compiling and Running
To compile the Postfix code directly, pf2asm can be used:
- pf2asm gcd.pf
- yasm -felf gcd.asm