Consider the following C function:
<c> extern int printf(const char *format, ...); int printlist(int lo, int hi) {
int ix = lo; while (ix < hi) { printf("%d\n", ix); ix++; } return ix;
} </c>
The Postfix code for the above function is as follows:
<asm> EXTRN printf
TEXT ALIGN GLOBL printlist, FUNC LABEL printlist
ENTER 4 ; ix@-4 lo@+8 hi@+12
LOCV +8 ; read lo LOCA -4 ; write to ix
ALIGN LABEL whiletest LOCV -4 ; read ix LOCV +12 ; read hi JZ whileend
RODATA ALIGN LABEL strlit STR "%d\n"
TEXT
LOCV -4 ; second printf arg: read ix ADDR strlit ; first printf arg: string lit address CALL printf
TRASH 8
PUSH
TRASH 4
LOCV -4 ; read ix DUP INT 1 ADD LOCA -4 ; ix = ix + 1
JMP whiletest
ALIGN LABEL whileend
LOCV -4 ; read ix
POP
LEAVE
RET
</asm>
To compile the Postfix code directly, pf2asm can be used: