Code Generation/Exercise 5

From Wiki**3

< Code Generation
Revision as of 18:52, 6 May 2019 by Root (talk | contribs) (Compiling and Running)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

The Original Code

Consider the following C function:

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;
}

Postfix Code

The Postfix code for the above function is as follows:

Postfix code

Compiling and Running

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

pf2asm gcd.pf
yasm -felf gcd.asm