|
|
(5 intermediate revisions by the same user not shown) |
Line 1: |
Line 1: |
| == The Original Code ==
| | #REDIRECT [[ist:Code Generation/Exercise 8]] |
| | |
| 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>
| |
| | |
| '''directivas:''' text data rodata bss align label extrn globl const str char id byte double
| |
| | |
| '''acesso:''' addr addra addrv local loca locv load dload ldchr store dstore stchr alloc dup swap push pop int sp
| |
| | |
| '''aritmética/lógica:''' add dadd sub dsub mul dmul div ddiv mod neg gt ge lt le eq ne cmp
| |
| | |
| '''bit a bit:''' rotl rotr shtl shtru shtrs and or not xor
| |
| | |
| '''funções/saltos:''' call ret start enter leave trash jmp jz jnz branch leap
| |
| | |
| == Postfix Code ==
| |
| | |
| The Postfix code for the above function is as follows:
| |
| | |
| <asm>
| |
| | |
| </asm>
| |
| | |
| == Compiling and Running ==
| |
| | |
| To compile the Postfix code directly, [[Pf2asm]] can be used:
| |
| | |
| *pf2asm printlist.pf
| |
| *yasm -felf printlist.asm
| |
| | |
| [[Category:Compilers]] [[Category:Teaching]]
| |