(→Postfix Code) |
|||
Line 15: | Line 15: | ||
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 26: | Line 26: | ||
;; i = dim-2 | ;; i = dim-2 | ||
− | + | LOCAL 12 | |
+ | LOAD | ||
INT 2 | INT 2 | ||
SUB | SUB | ||
DUP | DUP | ||
− | + | LOCAL -8 | |
+ | STORE | ||
TRASH 4 | TRASH 4 | ||
;; res = x + dim - 1 | ;; res = x + dim - 1 | ||
− | + | LOCAL 8 | |
− | + | LOAD | |
+ | LOCAL 12 | ||
+ | LOAD | ||
INT 4 | INT 4 | ||
MUL | MUL | ||
Line 44: | Line 48: | ||
SUB | SUB | ||
DUP | DUP | ||
− | + | LOCAL -4 | |
+ | STORE | ||
TRASH 4 | TRASH 4 | ||
Line 50: | Line 55: | ||
ALIGN | ALIGN | ||
LABEL for | LABEL for | ||
− | + | LOCAL -8 | |
+ | LOAD | ||
INT 0 | INT 0 | ||
GE | GE | ||
Line 58: | Line 64: | ||
;; if test | ;; if test | ||
− | + | LOCAL 8 | |
− | + | LOAD ; x | |
+ | LOCAL -8 | ||
+ | LOAD ; i | ||
INT 4 | INT 4 | ||
MUL | MUL | ||
Line 65: | Line 73: | ||
LOAD ; x[i] = *(x+i) | LOAD ; x[i] = *(x+i) | ||
− | + | LOCAL -4 | |
+ | LOAD ; res | ||
LOAD ; *res | LOAD ; *res | ||
Line 72: | Line 81: | ||
;; if block | ;; if block | ||
− | + | LOCAL 8 | |
− | + | LOAD ; x | |
+ | LOCAL -8 | ||
+ | LOAD ; i | ||
INT 4 | INT 4 | ||
MUL | MUL | ||
ADD ; x+i = &x[i] | ADD ; x+i = &x[i] | ||
DUP | DUP | ||
− | + | LOCAL -4 | |
+ | STORE ; res = &x[i] | ||
TRASH 4 | TRASH 4 | ||
Line 87: | Line 99: | ||
ALIGN | ALIGN | ||
LABEL forincr | LABEL forincr | ||
− | + | LOCAL -8 | |
+ | LOAD ; i | ||
DUP | DUP | ||
INT 1 | INT 1 | ||
SUB | SUB | ||
− | + | LOCAL -8 | |
+ | STORE | ||
TRASH 4 | TRASH 4 | ||
Line 101: | Line 115: | ||
;; return | ;; return | ||
− | + | LOCAL -4 | |
+ | LOAD ; res | ||
POP | POP | ||
Line 107: | Line 122: | ||
RET | RET | ||
</asm> | </asm> | ||
+ | }} | ||
== Compiling and Running == | == Compiling and Running == |
Consider the following C function:
<c> int *click(int *x, int dim) {
int *res, i; for (i = dim-2, res = x+dim-1; i >= 0; i--) if (x[i] > *res) res = &x[i]; return res;
} </c>
The Postfix code for the above function is as follows:
Postfix code |
---|
{{{2}}} |
To compile the Postfix code directly, pf2asm can be used: