Line 38: | Line 38: | ||
LOAD2 | LOAD2 | ||
− | + | LOCAL -16 ; write value to "e" | |
+ | STORE2 | ||
;;-- to perform the second assignment (to "d"), duplicate the value on the stack | ;;-- to perform the second assignment (to "d"), duplicate the value on the stack | ||
Line 44: | Line 45: | ||
LOAD2 | LOAD2 | ||
− | + | LOCAL -8 ; write value to "d" | |
+ | STORE2 | ||
;;-- the assignments are an instruction: trash the value left on the stack | ;;-- the assignments are an instruction: trash the value left on the stack | ||
Line 50: | Line 52: | ||
;;-- now to perform the add operation | ;;-- now to perform the add operation | ||
− | + | LOCAL -8 | |
− | + | LOAD2 ; load "d" | |
+ | LOCAL -16 | ||
+ | LOAD2 ; load "e" | ||
+ | |||
DADD ; leaves result on the stack | DADD ; leaves result on the stack | ||
The following pure-Postfix program illustrates duplication of double-precision floating point numbers on the stack.
The C equivalent would be (roughly):
<c> int main() {
extern void printd(double); double d, e; d = e = 3.3e-2; printd(d + e); return 0;
} </c>
Note that this program's code does not necessarily correspond to any particular code generator output.
<asm>
TEXT ALIGN GLOBL _main, FUNC LABEL _main ENTER 16 ; d@-8 and e@-16
RODATA ALIGN LABEL _L123 DOUBLE 3.3e-2
TEXT ADDR _L123 LOAD2
SP LOAD2
LOCAL -16 ; write value to "e" STORE2
SP LOAD2
LOCAL -8 ; write value to "d" STORE2
TRASH 8
LOCAL -8 LOAD2 ; load "d" LOCAL -16 LOAD2 ; load "e"
DADD ; leaves result on the stack
EXTRN printd CALL printd
TRASH 8 ; argument value no longer needed
INT 0 POP LEAVE RET </asm>
Assuming that the code above is in file dbl.pf, the following commands would compile and run the program: