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 / error5.out.bak < prev    next >
Text File  |  2006-03-05  |  4KB  |  204 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 Count-not-positive message..."
  104.     .align    8
  105. ! MAIN...
  106. !   mainEntry
  107.     .global    main
  108. main:    save    %sp,-120,%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. ! VAR INITIALIZATION...
  116. !   i := 0
  117.     set    0,%o0
  118.     st    %o0,[%fp+-8]
  119. ! WRITE STMT...
  120. !   writeString str1
  121.     sethi    %hi(str1),%o0
  122.     call    printf
  123.     or    %o0,%lo(str1),%o0
  124. !   writeNewline
  125.     sethi    %hi(strNL),%o0
  126.     call    printf
  127.     or    %o0,%lo(strNL),%o0
  128. ! ASSIGNMENT STMT...
  129. !   t1 := 0
  130.     set    0,%o0
  131.     st    %o0,[%fp+-12]
  132. !   if i <= 0 goto runtimeError5        (integer)
  133.     ld    [%fp+-8],%o0
  134.     set    0,%o1
  135.     cmp    %o0,%o1
  136.     ble    runtimeError5
  137.     nop
  138. !   t1 := t1 + i        (integer)
  139.     ld    [%fp+-12],%o0
  140.     ld    [%fp+-8],%o1
  141.     add    %o0,%o1,%o1
  142.     st    %o1,[%fp+-12]
  143. !   t2 := t1 * 4        (integer)
  144.     ld    [%fp+-12],%o0
  145.     set    4,%o1
  146.     smul    %o0,%o1,%o1
  147.     st    %o1,[%fp+-16]
  148. !   t2 := t2 + 4        (integer)
  149.     ld    [%fp+-16],%o0
  150.     set    4,%o1
  151.     add    %o0,%o1,%o1
  152.     st    %o1,[%fp+-16]
  153. !   t2 := alloc (t2)
  154.     set    1,%o0
  155.     ld    [%fp+-16],%o1
  156.     call    calloc
  157.     nop
  158.     st    %o0,[%fp+-16]
  159. !   if t2 = 0 goto runtimeError1        (integer)
  160.     ld    [%fp+-16],%o0
  161.     set    0,%o1
  162.     cmp    %o0,%o1
  163.     be    runtimeError1
  164.     nop
  165. !   t3 := t2
  166.     ld    [%fp+-16],%o0
  167.     st    %o0,[%fp+-20]
  168. !   *t2 := t1
  169.     ld    [%fp+-12],%o0
  170.     ld    [%fp+-16],%o1
  171.     st    %o0,[%o1]
  172. !   t4 := i
  173.     ld    [%fp+-8],%o0
  174.     st    %o0,[%fp+-24]
  175. !   Label_1:
  176. Label_1:
  177. !   t2 := t2 + 4        (integer)
  178.     ld    [%fp+-16],%o0
  179.     set    4,%o1
  180.     add    %o0,%o1,%o1
  181.     st    %o1,[%fp+-16]
  182. !   *t2 := 0
  183.     set    0,%o0
  184.     ld    [%fp+-16],%o1
  185.     st    %o0,[%o1]
  186. !   t4 := t4 - 1        (integer)
  187.     ld    [%fp+-24],%o0
  188.     set    1,%o1
  189.     sub    %o0,%o1,%o1
  190.     st    %o1,[%fp+-24]
  191. !   if t4 > 0 goto Label_1        (integer)
  192.     ld    [%fp+-24],%o0
  193.     set    0,%o1
  194.     cmp    %o0,%o1
  195.     bg    Label_1
  196.     nop
  197. !   p := t3
  198.     ld    [%fp+-20],%o0
  199.     st    %o0,[%fp+-4]
  200. ! MAIN EXIT...
  201. !   mainExit
  202.     ret
  203.     restore
  204.