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 / error4a.out.bak < prev    next >
Text File  |  2006-03-05  |  5KB  |  259 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 index-out-of-bounds error..."
  104.     .align    8
  105. ! MAIN...
  106. !   mainEntry
  107.     .global    main
  108. main:    save    %sp,-128,%sp
  109.     set    display0,%o0
  110.     st    %fp,[%o0]
  111. ! VAR INITIALIZATION...
  112. !   a := 0
  113.     set    0,%o0
  114.     st    %o0,[%fp+-4]
  115. ! VAR INITIALIZATION...
  116. !   i := 0
  117.     set    0,%o0
  118.     st    %o0,[%fp+-8]
  119. ! ASSIGNMENT STMT...
  120. !   t1 := 0
  121.     set    0,%o0
  122.     st    %o0,[%fp+-12]
  123. !   t1 := t1 + 1        (integer)
  124.     ld    [%fp+-12],%o0
  125.     set    1,%o1
  126.     add    %o0,%o1,%o1
  127.     st    %o1,[%fp+-12]
  128. !   t1 := t1 + 1        (integer)
  129.     ld    [%fp+-12],%o0
  130.     set    1,%o1
  131.     add    %o0,%o1,%o1
  132.     st    %o1,[%fp+-12]
  133. !   t1 := t1 + 1        (integer)
  134.     ld    [%fp+-12],%o0
  135.     set    1,%o1
  136.     add    %o0,%o1,%o1
  137.     st    %o1,[%fp+-12]
  138. !   t2 := t1 * 4        (integer)
  139.     ld    [%fp+-12],%o0
  140.     set    4,%o1
  141.     smul    %o0,%o1,%o1
  142.     st    %o1,[%fp+-16]
  143. !   t2 := t2 + 4        (integer)
  144.     ld    [%fp+-16],%o0
  145.     set    4,%o1
  146.     add    %o0,%o1,%o1
  147.     st    %o1,[%fp+-16]
  148. !   t2 := alloc (t2)
  149.     set    1,%o0
  150.     ld    [%fp+-16],%o1
  151.     call    calloc
  152.     nop
  153.     st    %o0,[%fp+-16]
  154. !   if t2 = 0 goto runtimeError1        (integer)
  155.     ld    [%fp+-16],%o0
  156.     set    0,%o1
  157.     cmp    %o0,%o1
  158.     be    runtimeError1
  159.     nop
  160. !   t3 := t2
  161.     ld    [%fp+-16],%o0
  162.     st    %o0,[%fp+-20]
  163. !   *t2 := t1
  164.     ld    [%fp+-12],%o0
  165.     ld    [%fp+-16],%o1
  166.     st    %o0,[%o1]
  167. !   t2 := t2 + 4        (integer)
  168.     ld    [%fp+-16],%o0
  169.     set    4,%o1
  170.     add    %o0,%o1,%o1
  171.     st    %o1,[%fp+-16]
  172. !   *t2 := 111
  173.     set    111,%o0
  174.     ld    [%fp+-16],%o1
  175.     st    %o0,[%o1]
  176. !   t2 := t2 + 4        (integer)
  177.     ld    [%fp+-16],%o0
  178.     set    4,%o1
  179.     add    %o0,%o1,%o1
  180.     st    %o1,[%fp+-16]
  181. !   *t2 := 222
  182.     set    222,%o0
  183.     ld    [%fp+-16],%o1
  184.     st    %o0,[%o1]
  185. !   t2 := t2 + 4        (integer)
  186.     ld    [%fp+-16],%o0
  187.     set    4,%o1
  188.     add    %o0,%o1,%o1
  189.     st    %o1,[%fp+-16]
  190. !   *t2 := 333
  191.     set    333,%o0
  192.     ld    [%fp+-16],%o1
  193.     st    %o0,[%o1]
  194. !   a := t3
  195.     ld    [%fp+-20],%o0
  196.     st    %o0,[%fp+-4]
  197. ! WRITE STMT...
  198. !   writeString str1
  199.     sethi    %hi(str1),%o0
  200.     call    printf
  201.     or    %o0,%lo(str1),%o0
  202. !   writeNewline
  203.     sethi    %hi(strNL),%o0
  204.     call    printf
  205.     or    %o0,%lo(strNL),%o0
  206. ! ASSIGNMENT STMT...
  207. !   if a = 0 goto runtimeError2        (integer)
  208.     ld    [%fp+-4],%o0
  209.     set    0,%o1
  210.     cmp    %o0,%o1
  211.     be    runtimeError2
  212.     nop
  213. !   t5 := - 1           (integer)
  214.     set    1,%o0
  215.     neg    %o0,%o1
  216.     st    %o1,[%fp+-28]
  217. !   if t5 < 0 goto runtimeError4        (integer)
  218.     ld    [%fp+-28],%o0
  219.     set    0,%o1
  220.     cmp    %o0,%o1
  221.     bl    runtimeError4
  222.     nop
  223. !   t6 := *a
  224.     ld    [%fp+-4],%o0
  225.     ld    [%o0],%o0
  226.     st    %o0,[%fp+-32]
  227. !   if t5 >= t6 goto runtimeError4        (integer)
  228.     ld    [%fp+-28],%o0
  229.     ld    [%fp+-32],%o1
  230.     cmp    %o0,%o1
  231.     bge    runtimeError4
  232.     nop
  233. !   t6 := t5 * 4        (integer)
  234.     ld    [%fp+-28],%o0
  235.     set    4,%o1
  236.     smul    %o0,%o1,%o1
  237.     st    %o1,[%fp+-32]
  238. !   t6 := t6 + 4        (integer)
  239.     ld    [%fp+-32],%o0
  240.     set    4,%o1
  241.     add    %o0,%o1,%o1
  242.     st    %o1,[%fp+-32]
  243. !   t6 := a + t6        (integer)
  244.     ld    [%fp+-4],%o0
  245.     ld    [%fp+-32],%o1
  246.     add    %o0,%o1,%o1
  247.     st    %o1,[%fp+-32]
  248. !   t7 := *t6
  249.     ld    [%fp+-32],%o0
  250.     ld    [%o0],%o0
  251.     st    %o0,[%fp+-36]
  252. !   i := t7
  253.     ld    [%fp+-36],%o0
  254.     st    %o0,[%fp+-8]
  255. ! MAIN EXIT...
  256. !   mainExit
  257.     ret
  258.     restore
  259.