home *** CD-ROM | disk | FTP | other *** search
/ ftp.ee.pdx.edu / 2014.02.ftp.ee.pdx.edu.tar / ftp.ee.pdx.edu / pub / users / Harry / compilers / p11 / tst / error1.out.bak < prev    next >
Text File  |  2006-03-05  |  4KB  |  200 lines

  1. !
  2. ! PCAT Compiler Version 1.0
  3. !
  4.              .global  .div
  5.              .global  .rem
  6. !
  7. ! Standard data fields
  8. !
  9.              .data
  10.              .align   8
  11. temp:        .double  0
  12.              .text
  13. strNL:       .asciz   "\n"
  14. strInt:      .asciz   "%d"
  15. strFlt:      .asciz   "%g"
  16. strTrue:     .asciz   "TRUE"
  17. strFalse:    .asciz   "FALSE"
  18. message1:    .asciz   "Execution Error: Allocation failed!\n"
  19. message2:    .asciz   "Execution Error: Pointer is NIL!\n"
  20. message3:    .asciz   "Execution Error: Read statement failed!\n"
  21. message4:    .asciz   "Execution Error: Array index is out of bounds!\n"
  22. message5:    .asciz   "Execution Error: Count is not positive in array constructor!\n"
  23.              .align   8
  24. !
  25. ! runtimeError1-5
  26. !
  27. ! Branch to one of these labels to print an error message and abort.
  28. !
  29. runtimeError1:
  30.              set      message1,%o0
  31.              call     printf
  32.              nop
  33.              call     exit
  34.              mov      1,%o0
  35. runtimeError2:
  36.              set      message2,%o0
  37.              call     printf
  38.              nop
  39.              call     exit
  40.              mov      1,%o0
  41. runtimeError3:
  42.              set      message3,%o0
  43.              call     printf
  44.              nop
  45.              call     exit
  46.              mov      1,%o0
  47. runtimeError4:
  48.              set      message4,%o0
  49.              call     printf
  50.              nop
  51.              call     exit
  52.              mov      1,%o0
  53. runtimeError5:
  54.              set      message5,%o0
  55.              call     printf
  56.              nop
  57.              call     exit
  58.              mov      1,%o0
  59. ! writeFlt
  60. !
  61. ! This routine is passed a single precision floating number in %f0.
  62. ! It prints it by calling printf.  It uses registers %f0, %f1.
  63. !
  64. writeFlt:
  65.         save    %sp,-128,%sp
  66.         fstod   %f0,%f0
  67.         set     temp,%l0
  68.         std     %f0,[%l0]
  69.         ldd     [%l0],%o0
  70.         mov     %o1,%o2
  71.         mov     %o0,%o1
  72.         set     strFlt,%o0
  73.         call    printf
  74.         nop
  75.         ret
  76.         restore
  77. ! writeBool
  78. !
  79. ! This routine is passed an integer in %i0/o0.  It prints "FALSE" if this
  80. ! integer is 0 and "TRUE" otherwise.
  81. !
  82. writeBool:
  83.         save    %sp,-128,%sp
  84.         cmp     %i0,%g0
  85.         be      printFalse
  86.         nop
  87.         set     strTrue,%o0
  88.         ba      printEnd
  89.         nop
  90. printFalse:
  91.         set     strFalse,%o0
  92. printEnd:
  93.         call    printf
  94.         nop
  95.         ret
  96.         restore
  97. !
  98. ! Additional Fields
  99. !
  100.     .data
  101. display0:    .word    0
  102.     .text
  103. str1:    .asciz    "Should cause an allocation-failed message..."
  104.     .align    8
  105. ! MAIN...
  106. !   mainEntry
  107.     .global    main
  108. main:    save    %sp,-112,%sp
  109.     set    display0,%o0
  110.     st    %fp,[%o0]
  111. ! VAR INITIALIZATION...
  112. !   p := 0
  113.     set    0,%o0
  114.     st    %o0,[%fp+-4]
  115. ! WRITE STMT...
  116. !   writeString str1
  117.     sethi    %hi(str1),%o0
  118.     call    printf
  119.     or    %o0,%lo(str1),%o0
  120. !   writeNewline
  121.     sethi    %hi(strNL),%o0
  122.     call    printf
  123.     or    %o0,%lo(strNL),%o0
  124. ! ASSIGNMENT STMT...
  125. !   t1 := 0
  126.     set    0,%o0
  127.     st    %o0,[%fp+-8]
  128. !   if 1000 <= 0 goto runtimeError5        (integer)
  129.     set    1000,%o0
  130.     set    0,%o1
  131.     cmp    %o0,%o1
  132.     ble    runtimeError5
  133.     nop
  134. !   t1 := t1 + 1000        (integer)
  135.     ld    [%fp+-8],%o0
  136.     set    1000,%o1
  137.     add    %o0,%o1,%o1
  138.     st    %o1,[%fp+-8]
  139. !   t2 := t1 * 4        (integer)
  140.     ld    [%fp+-8],%o0
  141.     set    4,%o1
  142.     smul    %o0,%o1,%o1
  143.     st    %o1,[%fp+-12]
  144. !   t2 := t2 + 4        (integer)
  145.     ld    [%fp+-12],%o0
  146.     set    4,%o1
  147.     add    %o0,%o1,%o1
  148.     st    %o1,[%fp+-12]
  149. !   t2 := alloc (t2)
  150.     set    1,%o0
  151.     ld    [%fp+-12],%o1
  152.     call    calloc
  153.     nop
  154.     st    %o0,[%fp+-12]
  155. !   if t2 = 0 goto runtimeError1        (integer)
  156.     ld    [%fp+-12],%o0
  157.     set    0,%o1
  158.     cmp    %o0,%o1
  159.     be    runtimeError1
  160.     nop
  161. !   t3 := t2
  162.     ld    [%fp+-12],%o0
  163.     st    %o0,[%fp+-16]
  164. !   *t2 := t1
  165.     ld    [%fp+-8],%o0
  166.     ld    [%fp+-12],%o1
  167.     st    %o0,[%o1]
  168. !   t4 := 1000
  169.     set    1000,%o0
  170.     st    %o0,[%fp+-20]
  171. !   Label_1:
  172. Label_1:
  173. !   t2 := t2 + 4        (integer)
  174.     ld    [%fp+-12],%o0
  175.     set    4,%o1
  176.     add    %o0,%o1,%o1
  177.     st    %o1,[%fp+-12]
  178. !   *t2 := 0
  179.     set    0,%o0
  180.     ld    [%fp+-12],%o1
  181.     st    %o0,[%o1]
  182. !   t4 := t4 - 1        (integer)
  183.     ld    [%fp+-20],%o0
  184.     set    1,%o1
  185.     sub    %o0,%o1,%o1
  186.     st    %o1,[%fp+-20]
  187. !   if t4 > 0 goto Label_1        (integer)
  188.     ld    [%fp+-20],%o0
  189.     set    0,%o1
  190.     cmp    %o0,%o1
  191.     bg    Label_1
  192.     nop
  193. !   p := t3
  194.     ld    [%fp+-16],%o0
  195.     st    %o0,[%fp+-4]
  196. ! MAIN EXIT...
  197. !   mainExit
  198.     ret
  199.     restore
  200.