         Edinburgh IMP77 Compiler - Version 8.4-2024.12.18

     1  %begin
 0000 C8 00 00 01                           ENTER 0000,1
     2  
     3      ! An example program which uses a %routinespec and a call
     4      ! to the routine BEFORE actually the routine implementation
     5  
     6      %routinespec css
     7  
     8      selectoutput(0)
 0004 6A 00                                 PUSH #0
 0006 E8 2D 00                              CALL 'SELECTOUTPUT' (EXTERN 45)
 0009 83 C4 04                              ADD %ESP,#4
     9      printstring("start %SPEC test"); newline
 000C 81 EC 00 01 00 00                     SUB %ESP,#256
 0012 89 E0                                 MOV %EAX,%ESP
 0014 50                                    PUSH %EAX
 0015 B8 00 00 00 00                        MOV %EAX,COT+#0
 001A 50                                    PUSH %EAX
 001B 68 FF 00 00 00                        PUSH #255
 0020 E8 03 00                              CALL '_IMPSTRCPY' (EXTERN 3)
 0023 83 C4 0C                              ADD %ESP,#12
 0026 E8 3B 00                              CALL 'PRINTSTRING' (EXTERN 59)
 0029 81 C4 00 01 00 00                     ADD %ESP,#256
 002F E8 43 00                              CALL 'NEWLINE' (EXTERN 67)
    10      css
 0032 E8 00 00                              CALL 'CSS' (INTERNAL L1001 )
    11      printstring("end %SPEC test"); newline
 0035 81 EC 00 01 00 00                     SUB %ESP,#256
 003B 89 E0                                 MOV %EAX,%ESP
 003D 50                                    PUSH %EAX
 003E B8 11 00 00 00                        MOV %EAX,COT+#17
 0043 50                                    PUSH %EAX
 0044 68 FF 00 00 00                        PUSH #255
 0049 E8 03 00                              CALL '_IMPSTRCPY' (EXTERN 3)
 004C 83 C4 0C                              ADD %ESP,#12
 004F E8 3B 00                              CALL 'PRINTSTRING' (EXTERN 59)
 0052 81 C4 00 01 00 00                     ADD %ESP,#256
 0058 E8 43 00                              CALL 'NEWLINE' (EXTERN 67)
    12  
    13      %routine css
 005B EB 00                                 JMP L1002
 005D                      L1001  EQU $
 005D C8 00 00 02                           ENTER 0000,2
    14          %integer a,b,c
    15  
    16          %integerfnspec three(%integer p1,p2,p3)
    17          %integerfnspec two(%integer p1,p2)
    18          
    19          c = 5
 0061 C7 45 EC 05 00 00 00                  MOV DWORD PTR [%EBP-20],#5
    20  
    21          %integerfn one(%integer p1)
 0068 EB 00                                 JMP L1005
 006A                      L1006  EQU $
 006A C8 00 00 03                           ENTER 0000,3
    22              %integer a1,b1,c1,d1
    23              %owninteger callcount
    24              
    25              %begin
 006E E8 00 00                              CALL '$L1007' (INTERNAL L1007 )
 0071 EB 00                                 JMP L1008
 0073                      L1007  EQU $
 0073 C8 00 00 04                           ENTER 0000,4
    26                  a1 = p1
 0077 8B 75 F4                              MOV %ESI,[%EBP-12]
 007A 8B 46 08                              MOV %EAX,[%ESI+8]
 007D 89 46 F0                              MOV [%ESI-16],%EAX
    27                  b1 = 2*p1
 0080 8B 46 08                              MOV %EAX,[%ESI+8]
 0083 D1 E0                                 SHL %EAX,#1
 0085 89 46 EC                              MOV [%ESI-20],%EAX
    28                  c1 = 3*p1
 0088 8B 46 08                              MOV %EAX,[%ESI+8]
 008B F7 2D 20 00 00 00                     IMUL DWORD PTR [COT+0020]
 0091 89 46 E8                              MOV [%ESI-24],%EAX
    29                  callcount = callcount + 1
 0094 FF 05 00 00 00 00                     INC DWORD PTR [DATA+0000]
    30              %end
 009A C9                                    LEAVE
 009B C3                                    RET
 009C                      L1008  EQU $
    31  
    32              ! Use callcount as a defence against repeated calls to routine 'three'
    33              ! which would cause a stack overflow.
    34              %if (callcount < 10) %then d1 = three(a1,b1,c1) %else d1 = -1
 009C A1 00 00 00 00                        MOV %EAX,[DATA+0000]
 00A1 3D 0A 00 00 00                        CMP %EAX,#10
 00A6 7D 00                                 JGE L1009
 00A8 FF 75 F0                              PUSH DWORD PTR [%EBP-16]
 00AB FF 75 EC                              PUSH DWORD PTR [%EBP-20]
 00AE FF 75 E8                              PUSH DWORD PTR [%EBP-24]
 00B1 E8 00 00                              CALL 'THREE' (INTERNAL L1003 )
 00B4 83 C4 0C                              ADD %ESP,#12
 00B7 89 45 E4                              MOV [%EBP-28],%EAX
 00BA EB 00                                 JMP L1010
 00BC                      L1009  EQU $
 00BC C7 45 E4 FF FF FF FF                  MOV DWORD PTR [%EBP-28],#-1
 00C3                      L1010  EQU $
    35              %result = d1
 00C3 8B 45 E4                              MOV %EAX,[%EBP-28]
 00C6 C9                                    LEAVE
 00C7 C3                                    RET
    36          %end
 00C8                      L1005  EQU $
    37  
    38          b = 3
 00C8 C7 45 F0 03 00 00 00                  MOV DWORD PTR [%EBP-16],#3
    39  
    40          %integerfn three(%integer p1,p2,p3)
 00CF EB 00                                 JMP L1011
 00D1                      L1003  EQU $
 00D1 C8 00 00 03                           ENTER 0000,3
    41              %integer a3,b3
    42              a3 = one(p1)
 00D5 FF 75 10                              PUSH DWORD PTR [%EBP+16]
 00D8 E8 00 00                              CALL 'ONE' (INTERNAL L1006 )
 00DB 83 C4 04                              ADD %ESP,#4
 00DE 89 45 F0                              MOV [%EBP-16],%EAX
    43              b3 = two(p2,p3)
 00E1 FF 75 0C                              PUSH DWORD PTR [%EBP+12]
 00E4 FF 75 08                              PUSH DWORD PTR [%EBP+8]
 00E7 E8 00 00                              CALL 'TWO' (INTERNAL L1004 )
 00EA 83 C4 08                              ADD %ESP,#8
 00ED 89 45 EC                              MOV [%EBP-20],%EAX
    44              %result = a3 + b3
 00F0 8B 45 F0                              MOV %EAX,[%EBP-16]
 00F3 03 45 EC                              ADD %EAX,[%EBP-20]
 00F6 C9                                    LEAVE
 00F7 C3                                    RET
    45          %end        
 00F8                      L1011  EQU $
    46  
    47          a = three(b,c,b+c)
 00F8 FF 75 F0                              PUSH DWORD PTR [%EBP-16]
 00FB FF 75 EC                              PUSH DWORD PTR [%EBP-20]
 00FE 8B 45 F0                              MOV %EAX,[%EBP-16]
 0101 03 45 EC                              ADD %EAX,[%EBP-20]
 0104 50                                    PUSH %EAX
 0105 E8 00 00                              CALL 'THREE' (INTERNAL L1003 )
 0108 83 C4 0C                              ADD %ESP,#12
 010B 89 45 F4                              MOV [%EBP-12],%EAX
    48  
    49          %integerfn two(%integer p1,p2)
 010E EB 00                                 JMP L1012
 0110                      L1004  EQU $
 0110 C8 00 00 03                           ENTER 0000,3
    50              %integer a2,b2
    51              
    52              %result = one(p1+p2)
 0114 8B 45 0C                              MOV %EAX,[%EBP+12]
 0117 03 45 08                              ADD %EAX,[%EBP+8]
 011A 50                                    PUSH %EAX
 011B E8 00 00                              CALL 'ONE' (INTERNAL L1006 )
 011E 83 C4 04                              ADD %ESP,#4
 0121 C9                                    LEAVE
 0122 C3                                    RET
    53          %end
 0123                      L1012  EQU $
?B2 unused
?A2 unused
    54  
    55      %end
 0123 C9                                    LEAVE
 0124 C3                                    RET
 0125                      L1002  EQU $
    56  
    57  %endofprogram
 0125 C9                                    LEAVE
 0126 C3                                    RET

    39 Statements compiled



 ELF object file generated from IMP source file: '/home/gtoal/src/compilers101/new-parser/imps/tests/test219.imp'
 +----------+---------------------+---------+---------+---------+------------+
 | Sections |       Symbols       | Code    | Data    | Diag    | Total size |
 +----------+----------+----------+---------+---------+---------+------------+
 |  (count) | Internal | External | (bytes) | (bytes) | (bytes) | (bytes)    |
 +----------+----------+----------+---------+---------+---------+------------+
 |       13 |       11 |       10 |     326 |      40 |     192 |        558 |
 +----------+----------+----------+---------+---------+---------+------------+


