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 / itof.out.bak < prev    next >
Text File  |  2006-03-05  |  4KB  |  188 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. float2:    .single    0r0.0
  104. float1:    .single    0r0.0
  105. str2:    .asciz    "Should print -321..."
  106. str1:    .asciz    "Should print 123..."
  107.     .align    8
  108. ! MAIN...
  109. !   mainEntry
  110.     .global    main
  111. main:    save    %sp,-120,%sp
  112.     set    display0,%o0
  113.     st    %fp,[%o0]
  114. ! VAR INITIALIZATION...
  115. !   i := 123
  116.     set    123,%o0
  117.     st    %o0,[%fp+-4]
  118. ! VAR INITIALIZATION...
  119. !   t1 := - 321           (integer)
  120.     set    321,%o0
  121.     neg    %o0,%o1
  122.     st    %o1,[%fp+-20]
  123. !   j := t1
  124.     ld    [%fp+-20],%o0
  125.     st    %o0,[%fp+-8]
  126. ! VAR INITIALIZATION...
  127. !   x := 0.0
  128.     set    float1,%o0
  129.     ld    [%o0],%o0
  130.     st    %o0,[%fp+-12]
  131. ! VAR INITIALIZATION...
  132. !   y := 0.0
  133.     set    float2,%o0
  134.     ld    [%o0],%o0
  135.     st    %o0,[%fp+-16]
  136. ! ASSIGNMENT STMT...
  137. !   t2 := intToFloat (i)
  138.     ld    [%fp+-4],%o0
  139.     set    temp,%o1
  140.     st    %o0,[%o1]
  141.     ld    [%o1],%f0
  142.     fitos    %f0,%f0
  143.     st    %f0,[%fp+-24]
  144. !   x := t2
  145.     ld    [%fp+-24],%o0
  146.     st    %o0,[%fp+-12]
  147. ! WRITE STMT...
  148. !   writeString str1
  149.     sethi    %hi(str1),%o0
  150.     call    printf
  151.     or    %o0,%lo(str1),%o0
  152. !   writeFloat x
  153.     ld    [%fp+-12],%f0
  154.     call    writeFlt
  155.     nop
  156. !   writeNewline
  157.     sethi    %hi(strNL),%o0
  158.     call    printf
  159.     or    %o0,%lo(strNL),%o0
  160. ! ASSIGNMENT STMT...
  161. !   t3 := intToFloat (j)
  162.     ld    [%fp+-8],%o0
  163.     set    temp,%o1
  164.     st    %o0,[%o1]
  165.     ld    [%o1],%f0
  166.     fitos    %f0,%f0
  167.     st    %f0,[%fp+-28]
  168. !   y := t3
  169.     ld    [%fp+-28],%o0
  170.     st    %o0,[%fp+-16]
  171. ! WRITE STMT...
  172. !   writeString str2
  173.     sethi    %hi(str2),%o0
  174.     call    printf
  175.     or    %o0,%lo(str2),%o0
  176. !   writeFloat y
  177.     ld    [%fp+-16],%f0
  178.     call    writeFlt
  179.     nop
  180. !   writeNewline
  181.     sethi    %hi(strNL),%o0
  182.     call    printf
  183.     or    %o0,%lo(strNL),%o0
  184. ! MAIN EXIT...
  185. !   mainExit
  186.     ret
  187.     restore
  188.