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 / array2.out.bak < prev    next >
Text File  |  2006-03-05  |  7KB  |  366 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. str3:    .asciz    "Should print -7654..."
  104. str2:    .asciz    "Should print -7654..."
  105. str1:    .asciz    "Should print -7654..."
  106.     .align    8
  107. ! MAIN...
  108. !   mainEntry
  109.     .global    main
  110. main:    save    %sp,-144,%sp
  111.     set    display0,%o0
  112.     st    %fp,[%o0]
  113. ! VAR INITIALIZATION...
  114. !   a := 0
  115.     set    0,%o0
  116.     st    %o0,[%fp+-4]
  117. ! VAR INITIALIZATION...
  118. !   i := 0
  119.     set    0,%o0
  120.     st    %o0,[%fp+-8]
  121. ! ASSIGNMENT STMT...
  122. !   t1 := 0
  123.     set    0,%o0
  124.     st    %o0,[%fp+-12]
  125. !   if 100 <= 0 goto runtimeError5        (integer)
  126.     set    100,%o0
  127.     set    0,%o1
  128.     cmp    %o0,%o1
  129.     ble    runtimeError5
  130.     nop
  131. !   t1 := t1 + 100        (integer)
  132.     ld    [%fp+-12],%o0
  133.     set    100,%o1
  134.     add    %o0,%o1,%o1
  135.     st    %o1,[%fp+-12]
  136. !   t2 := - 7654           (integer)
  137.     set    7654,%o0
  138.     neg    %o0,%o1
  139.     st    %o1,[%fp+-16]
  140. !   t3 := t1 * 4        (integer)
  141.     ld    [%fp+-12],%o0
  142.     set    4,%o1
  143.     smul    %o0,%o1,%o1
  144.     st    %o1,[%fp+-20]
  145. !   t3 := t3 + 4        (integer)
  146.     ld    [%fp+-20],%o0
  147.     set    4,%o1
  148.     add    %o0,%o1,%o1
  149.     st    %o1,[%fp+-20]
  150. !   t3 := alloc (t3)
  151.     set    1,%o0
  152.     ld    [%fp+-20],%o1
  153.     call    calloc
  154.     nop
  155.     st    %o0,[%fp+-20]
  156. !   if t3 = 0 goto runtimeError1        (integer)
  157.     ld    [%fp+-20],%o0
  158.     set    0,%o1
  159.     cmp    %o0,%o1
  160.     be    runtimeError1
  161.     nop
  162. !   t4 := t3
  163.     ld    [%fp+-20],%o0
  164.     st    %o0,[%fp+-24]
  165. !   *t3 := t1
  166.     ld    [%fp+-12],%o0
  167.     ld    [%fp+-20],%o1
  168.     st    %o0,[%o1]
  169. !   t5 := 100
  170.     set    100,%o0
  171.     st    %o0,[%fp+-28]
  172. !   Label_1:
  173. Label_1:
  174. !   t3 := t3 + 4        (integer)
  175.     ld    [%fp+-20],%o0
  176.     set    4,%o1
  177.     add    %o0,%o1,%o1
  178.     st    %o1,[%fp+-20]
  179. !   *t3 := t2
  180.     ld    [%fp+-16],%o0
  181.     ld    [%fp+-20],%o1
  182.     st    %o0,[%o1]
  183. !   t5 := t5 - 1        (integer)
  184.     ld    [%fp+-28],%o0
  185.     set    1,%o1
  186.     sub    %o0,%o1,%o1
  187.     st    %o1,[%fp+-28]
  188. !   if t5 > 0 goto Label_1        (integer)
  189.     ld    [%fp+-28],%o0
  190.     set    0,%o1
  191.     cmp    %o0,%o1
  192.     bg    Label_1
  193.     nop
  194. !   a := t4
  195.     ld    [%fp+-24],%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. !   if a = 0 goto runtimeError2        (integer)
  203.     ld    [%fp+-4],%o0
  204.     set    0,%o1
  205.     cmp    %o0,%o1
  206.     be    runtimeError2
  207.     nop
  208. !   if 0 < 0 goto runtimeError4        (integer)
  209.     set    0,%o0
  210.     set    0,%o1
  211.     cmp    %o0,%o1
  212.     bl    runtimeError4
  213.     nop
  214. !   t6 := *a
  215.     ld    [%fp+-4],%o0
  216.     ld    [%o0],%o0
  217.     st    %o0,[%fp+-32]
  218. !   if 0 >= t6 goto runtimeError4        (integer)
  219.     set    0,%o0
  220.     ld    [%fp+-32],%o1
  221.     cmp    %o0,%o1
  222.     bge    runtimeError4
  223.     nop
  224. !   t6 := 0 * 4        (integer)
  225.     set    0,%o0
  226.     set    4,%o1
  227.     smul    %o0,%o1,%o1
  228.     st    %o1,[%fp+-32]
  229. !   t6 := t6 + 4        (integer)
  230.     ld    [%fp+-32],%o0
  231.     set    4,%o1
  232.     add    %o0,%o1,%o1
  233.     st    %o1,[%fp+-32]
  234. !   t6 := a + t6        (integer)
  235.     ld    [%fp+-4],%o0
  236.     ld    [%fp+-32],%o1
  237.     add    %o0,%o1,%o1
  238.     st    %o1,[%fp+-32]
  239. !   t7 := *t6
  240.     ld    [%fp+-32],%o0
  241.     ld    [%o0],%o0
  242.     st    %o0,[%fp+-36]
  243. !   writeInt t7
  244.     ld    [%fp+-36],%o1
  245.     sethi    %hi(strInt),%o0
  246.     call    printf
  247.     or    %o0,%lo(strInt),%o0
  248. !   writeNewline
  249.     sethi    %hi(strNL),%o0
  250.     call    printf
  251.     or    %o0,%lo(strNL),%o0
  252. ! WRITE STMT...
  253. !   writeString str2
  254.     sethi    %hi(str2),%o0
  255.     call    printf
  256.     or    %o0,%lo(str2),%o0
  257. !   if a = 0 goto runtimeError2        (integer)
  258.     ld    [%fp+-4],%o0
  259.     set    0,%o1
  260.     cmp    %o0,%o1
  261.     be    runtimeError2
  262.     nop
  263. !   if 50 < 0 goto runtimeError4        (integer)
  264.     set    50,%o0
  265.     set    0,%o1
  266.     cmp    %o0,%o1
  267.     bl    runtimeError4
  268.     nop
  269. !   t8 := *a
  270.     ld    [%fp+-4],%o0
  271.     ld    [%o0],%o0
  272.     st    %o0,[%fp+-40]
  273. !   if 50 >= t8 goto runtimeError4        (integer)
  274.     set    50,%o0
  275.     ld    [%fp+-40],%o1
  276.     cmp    %o0,%o1
  277.     bge    runtimeError4
  278.     nop
  279. !   t8 := 50 * 4        (integer)
  280.     set    50,%o0
  281.     set    4,%o1
  282.     smul    %o0,%o1,%o1
  283.     st    %o1,[%fp+-40]
  284. !   t8 := t8 + 4        (integer)
  285.     ld    [%fp+-40],%o0
  286.     set    4,%o1
  287.     add    %o0,%o1,%o1
  288.     st    %o1,[%fp+-40]
  289. !   t8 := a + t8        (integer)
  290.     ld    [%fp+-4],%o0
  291.     ld    [%fp+-40],%o1
  292.     add    %o0,%o1,%o1
  293.     st    %o1,[%fp+-40]
  294. !   t9 := *t8
  295.     ld    [%fp+-40],%o0
  296.     ld    [%o0],%o0
  297.     st    %o0,[%fp+-44]
  298. !   writeInt t9
  299.     ld    [%fp+-44],%o1
  300.     sethi    %hi(strInt),%o0
  301.     call    printf
  302.     or    %o0,%lo(strInt),%o0
  303. !   writeNewline
  304.     sethi    %hi(strNL),%o0
  305.     call    printf
  306.     or    %o0,%lo(strNL),%o0
  307. ! WRITE STMT...
  308. !   writeString str3
  309.     sethi    %hi(str3),%o0
  310.     call    printf
  311.     or    %o0,%lo(str3),%o0
  312. !   if a = 0 goto runtimeError2        (integer)
  313.     ld    [%fp+-4],%o0
  314.     set    0,%o1
  315.     cmp    %o0,%o1
  316.     be    runtimeError2
  317.     nop
  318. !   if 99 < 0 goto runtimeError4        (integer)
  319.     set    99,%o0
  320.     set    0,%o1
  321.     cmp    %o0,%o1
  322.     bl    runtimeError4
  323.     nop
  324. !   t10 := *a
  325.     ld    [%fp+-4],%o0
  326.     ld    [%o0],%o0
  327.     st    %o0,[%fp+-48]
  328. !   if 99 >= t10 goto runtimeError4        (integer)
  329.     set    99,%o0
  330.     ld    [%fp+-48],%o1
  331.     cmp    %o0,%o1
  332.     bge    runtimeError4
  333.     nop
  334. !   t10 := 99 * 4        (integer)
  335.     set    99,%o0
  336.     set    4,%o1
  337.     smul    %o0,%o1,%o1
  338.     st    %o1,[%fp+-48]
  339. !   t10 := t10 + 4        (integer)
  340.     ld    [%fp+-48],%o0
  341.     set    4,%o1
  342.     add    %o0,%o1,%o1
  343.     st    %o1,[%fp+-48]
  344. !   t10 := a + t10        (integer)
  345.     ld    [%fp+-4],%o0
  346.     ld    [%fp+-48],%o1
  347.     add    %o0,%o1,%o1
  348.     st    %o1,[%fp+-48]
  349. !   t11 := *t10
  350.     ld    [%fp+-48],%o0
  351.     ld    [%o0],%o0
  352.     st    %o0,[%fp+-52]
  353. !   writeInt t11
  354.     ld    [%fp+-52],%o1
  355.     sethi    %hi(strInt),%o0
  356.     call    printf
  357.     or    %o0,%lo(strInt),%o0
  358. !   writeNewline
  359.     sethi    %hi(strNL),%o0
  360.     call    printf
  361.     or    %o0,%lo(strNL),%o0
  362. ! MAIN EXIT...
  363. !   mainExit
  364.     ret
  365.     restore
  366.