(→Postfix Code) |
(→Postfix Code) |
||
Line 38: | Line 38: | ||
LABEL "while" | LABEL "while" | ||
LOCV -4 ; n | LOCV -4 ; n | ||
− | + | DUP32 ; n (because of n--) | |
INT 1 | INT 1 | ||
SUB ; n-1 | SUB ; n-1 | ||
Line 48: | Line 48: | ||
LOCV -12 ; j | LOCV -12 ; j | ||
ADD ; i+j | ADD ; i+j | ||
− | + | DUP32 ; same value (for assignment) | |
LOCV -16 ; seg | LOCV -16 ; seg | ||
− | + | STINT ; *seg = i+j | |
CALL "print" ; we assume that "print" does not return any value | CALL "print" ; we assume that "print" does not return any value | ||
TRASH 4 ; trash argument (int) | TRASH 4 ; trash argument (int) | ||
Line 68: | Line 68: | ||
ALIGN | ALIGN | ||
LABEL "end3" | LABEL "end3" | ||
− | + | DUP32 ; trenary operator's value (duplicated because of assignment) | |
LOCA -16 ; seg = (seg == &i) ? &j : &i | LOCA -16 ; seg = (seg == &i) ? &j : &i | ||
TRASH 4 ; trash assignment's value, since we used it as an instruction | TRASH 4 ; trash assignment's value, since we used it as an instruction | ||
Line 79: | Line 79: | ||
;-- rest of function | ;-- rest of function | ||
INT 0 | INT 0 | ||
− | + | STFVAL32 ; return value is 0 | |
LEAVE | LEAVE | ||
RET | RET |
Consider the following C function: <c> int main() {
int n = 45, i = 0, j = 1, *seg = &i; while (n-- > 0) { print(*seg = i + j); seg = (seg == &i) ? &j : &i; } return 0;
} </c>
The Postfix code for the above function is as follows:
[Expand] Postfix code |
---|