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 / read1.out.bak < prev    next >
Text File  |  2006-03-05  |  10KB  |  513 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. display1:    .word    0
  103.     .text
  104. str18:    .asciz    "i3 = "
  105. str17:    .asciz    "i2 = "
  106. str16:    .asciz    "i1 = "
  107. str15:    .asciz    "PLEASE ENTER 3 INTEGERS:"
  108. str14:    .asciz    "About to call readInt (i1, i2, i3)..."
  109. str13:    .asciz    "j3 = "
  110. str12:    .asciz    "j2 = "
  111. str11:    .asciz    "j1 = "
  112. str10:    .asciz    "PLEASE ENTER 3 INTEGERS:"
  113. str9:    .asciz    "About to call readInt (j1, j2, j3)..."
  114. str8:    .asciz    "i3 = "
  115. str7:    .asciz    "i2 = "
  116. str6:    .asciz    "i1 = "
  117. str5:    .asciz    "PLEASE ENTER 3 INTEGERS:"
  118. str4:    .asciz    "About to call readInt (i1, i2, i3)..."
  119. str3:    .asciz    "i1 = "
  120. str2:    .asciz    "PLEASE ENTER AN INTEGER:"
  121. str1:    .asciz    "About to call readInt(i)..."
  122.     .align    8
  123. ! MAIN...
  124. !   mainEntry
  125.     .global    main
  126. main:    save    %sp,-120,%sp
  127.     set    display0,%o0
  128.     st    %fp,[%o0]
  129. ! VAR INITIALIZATION...
  130. !   i1 := 0
  131.     set    0,%o0
  132.     st    %o0,[%fp+-4]
  133. ! VAR INITIALIZATION...
  134. !   i2 := i1
  135.     ld    [%fp+-4],%o0
  136.     st    %o0,[%fp+-8]
  137. ! VAR INITIALIZATION...
  138. !   i3 := i1
  139.     ld    [%fp+-4],%o0
  140.     st    %o0,[%fp+-12]
  141. ! WRITE STMT...
  142. !   writeString str1
  143.     sethi    %hi(str1),%o0
  144.     call    printf
  145.     or    %o0,%lo(str1),%o0
  146. !   writeNewline
  147.     sethi    %hi(strNL),%o0
  148.     call    printf
  149.     or    %o0,%lo(strNL),%o0
  150. ! WRITE STMT...
  151. !   writeString str2
  152.     sethi    %hi(str2),%o0
  153.     call    printf
  154.     or    %o0,%lo(str2),%o0
  155. !   writeNewline
  156.     sethi    %hi(strNL),%o0
  157.     call    printf
  158.     or    %o0,%lo(strNL),%o0
  159. ! READ STMT...
  160. !   t1 := &i1
  161.     add    %fp,-4,%o0
  162.     st    %o0,[%fp+-16]
  163. !   readInt t1
  164.     ld    [%fp+-16],%o1
  165.     sethi    %hi(strInt),%o0
  166.     call    scanf
  167.     or    %o0,%lo(strInt),%o0
  168.     cmp    %o0,0
  169.     be    runtimeError3
  170.     nop
  171. ! WRITE STMT...
  172. !   writeString str3
  173.     sethi    %hi(str3),%o0
  174.     call    printf
  175.     or    %o0,%lo(str3),%o0
  176. !   writeInt i1
  177.     ld    [%fp+-4],%o1
  178.     sethi    %hi(strInt),%o0
  179.     call    printf
  180.     or    %o0,%lo(strInt),%o0
  181. !   writeNewline
  182.     sethi    %hi(strNL),%o0
  183.     call    printf
  184.     or    %o0,%lo(strNL),%o0
  185. ! WRITE STMT...
  186. !   writeString str4
  187.     sethi    %hi(str4),%o0
  188.     call    printf
  189.     or    %o0,%lo(str4),%o0
  190. !   writeNewline
  191.     sethi    %hi(strNL),%o0
  192.     call    printf
  193.     or    %o0,%lo(strNL),%o0
  194. ! WRITE STMT...
  195. !   writeString str5
  196.     sethi    %hi(str5),%o0
  197.     call    printf
  198.     or    %o0,%lo(str5),%o0
  199. !   writeNewline
  200.     sethi    %hi(strNL),%o0
  201.     call    printf
  202.     or    %o0,%lo(strNL),%o0
  203. ! READ STMT...
  204. !   t2 := &i1
  205.     add    %fp,-4,%o0
  206.     st    %o0,[%fp+-20]
  207. !   readInt t2
  208.     ld    [%fp+-20],%o1
  209.     sethi    %hi(strInt),%o0
  210.     call    scanf
  211.     or    %o0,%lo(strInt),%o0
  212.     cmp    %o0,0
  213.     be    runtimeError3
  214.     nop
  215. !   t3 := &i2
  216.     add    %fp,-8,%o0
  217.     st    %o0,[%fp+-24]
  218. !   readInt t3
  219.     ld    [%fp+-24],%o1
  220.     sethi    %hi(strInt),%o0
  221.     call    scanf
  222.     or    %o0,%lo(strInt),%o0
  223.     cmp    %o0,0
  224.     be    runtimeError3
  225.     nop
  226. !   t4 := &i3
  227.     add    %fp,-12,%o0
  228.     st    %o0,[%fp+-28]
  229. !   readInt t4
  230.     ld    [%fp+-28],%o1
  231.     sethi    %hi(strInt),%o0
  232.     call    scanf
  233.     or    %o0,%lo(strInt),%o0
  234.     cmp    %o0,0
  235.     be    runtimeError3
  236.     nop
  237. ! WRITE STMT...
  238. !   writeString str6
  239.     sethi    %hi(str6),%o0
  240.     call    printf
  241.     or    %o0,%lo(str6),%o0
  242. !   writeInt i1
  243.     ld    [%fp+-4],%o1
  244.     sethi    %hi(strInt),%o0
  245.     call    printf
  246.     or    %o0,%lo(strInt),%o0
  247. !   writeNewline
  248.     sethi    %hi(strNL),%o0
  249.     call    printf
  250.     or    %o0,%lo(strNL),%o0
  251. ! WRITE STMT...
  252. !   writeString str7
  253.     sethi    %hi(str7),%o0
  254.     call    printf
  255.     or    %o0,%lo(str7),%o0
  256. !   writeInt i2
  257.     ld    [%fp+-8],%o1
  258.     sethi    %hi(strInt),%o0
  259.     call    printf
  260.     or    %o0,%lo(strInt),%o0
  261. !   writeNewline
  262.     sethi    %hi(strNL),%o0
  263.     call    printf
  264.     or    %o0,%lo(strNL),%o0
  265. ! WRITE STMT...
  266. !   writeString str8
  267.     sethi    %hi(str8),%o0
  268.     call    printf
  269.     or    %o0,%lo(str8),%o0
  270. !   writeInt i3
  271.     ld    [%fp+-12],%o1
  272.     sethi    %hi(strInt),%o0
  273.     call    printf
  274.     or    %o0,%lo(strInt),%o0
  275. !   writeNewline
  276.     sethi    %hi(strNL),%o0
  277.     call    printf
  278.     or    %o0,%lo(strNL),%o0
  279. ! CALL STMT...
  280. !   param 1,1
  281.     set    1,%o0
  282.     st    %o0,[%sp+68]
  283. !   param 2,2
  284.     set    2,%o0
  285.     st    %o0,[%sp+72]
  286. !   param 3,3
  287.     set    3,%o0
  288.     st    %o0,[%sp+76]
  289. !   call p1_foo
  290.     call    p1_foo
  291.     nop
  292. ! MAIN EXIT...
  293. !   mainExit
  294.     ret
  295.     restore
  296. ! PROCEDURE...
  297. !   procEntry p1_foo,lexLev=1,frameSize=120
  298. p1_foo:    save    %sp,-120,%sp
  299.     set    display1,%o0
  300.     ld    [%o0],%o1
  301.     st    %o1,[%fp+64]
  302.     st    %fp,[%o0]
  303. !   formal 1,j1
  304. !   formal 2,j2
  305. !   formal 3,j3
  306. ! WRITE STMT...
  307. !   writeString str9
  308.     sethi    %hi(str9),%o0
  309.     call    printf
  310.     or    %o0,%lo(str9),%o0
  311. !   writeNewline
  312.     sethi    %hi(strNL),%o0
  313.     call    printf
  314.     or    %o0,%lo(strNL),%o0
  315. ! WRITE STMT...
  316. !   writeString str10
  317.     sethi    %hi(str10),%o0
  318.     call    printf
  319.     or    %o0,%lo(str10),%o0
  320. !   writeNewline
  321.     sethi    %hi(strNL),%o0
  322.     call    printf
  323.     or    %o0,%lo(strNL),%o0
  324. ! READ STMT...
  325. !   t5 := &j1
  326.     add    %fp,68,%o0
  327.     st    %o0,[%fp+-4]
  328. !   readInt t5
  329.     ld    [%fp+-4],%o1
  330.     sethi    %hi(strInt),%o0
  331.     call    scanf
  332.     or    %o0,%lo(strInt),%o0
  333.     cmp    %o0,0
  334.     be    runtimeError3
  335.     nop
  336. !   t6 := &j2
  337.     add    %fp,72,%o0
  338.     st    %o0,[%fp+-8]
  339. !   readInt t6
  340.     ld    [%fp+-8],%o1
  341.     sethi    %hi(strInt),%o0
  342.     call    scanf
  343.     or    %o0,%lo(strInt),%o0
  344.     cmp    %o0,0
  345.     be    runtimeError3
  346.     nop
  347. !   t7 := &j3
  348.     add    %fp,76,%o0
  349.     st    %o0,[%fp+-12]
  350. !   readInt t7
  351.     ld    [%fp+-12],%o1
  352.     sethi    %hi(strInt),%o0
  353.     call    scanf
  354.     or    %o0,%lo(strInt),%o0
  355.     cmp    %o0,0
  356.     be    runtimeError3
  357.     nop
  358. ! WRITE STMT...
  359. !   writeString str11
  360.     sethi    %hi(str11),%o0
  361.     call    printf
  362.     or    %o0,%lo(str11),%o0
  363. !   writeInt j1
  364.     ld    [%fp+68],%o1
  365.     sethi    %hi(strInt),%o0
  366.     call    printf
  367.     or    %o0,%lo(strInt),%o0
  368. !   writeNewline
  369.     sethi    %hi(strNL),%o0
  370.     call    printf
  371.     or    %o0,%lo(strNL),%o0
  372. ! WRITE STMT...
  373. !   writeString str12
  374.     sethi    %hi(str12),%o0
  375.     call    printf
  376.     or    %o0,%lo(str12),%o0
  377. !   writeInt j2
  378.     ld    [%fp+72],%o1
  379.     sethi    %hi(strInt),%o0
  380.     call    printf
  381.     or    %o0,%lo(strInt),%o0
  382. !   writeNewline
  383.     sethi    %hi(strNL),%o0
  384.     call    printf
  385.     or    %o0,%lo(strNL),%o0
  386. ! WRITE STMT...
  387. !   writeString str13
  388.     sethi    %hi(str13),%o0
  389.     call    printf
  390.     or    %o0,%lo(str13),%o0
  391. !   writeInt j3
  392.     ld    [%fp+76],%o1
  393.     sethi    %hi(strInt),%o0
  394.     call    printf
  395.     or    %o0,%lo(strInt),%o0
  396. !   writeNewline
  397.     sethi    %hi(strNL),%o0
  398.     call    printf
  399.     or    %o0,%lo(strNL),%o0
  400. ! WRITE STMT...
  401. !   writeString str14
  402.     sethi    %hi(str14),%o0
  403.     call    printf
  404.     or    %o0,%lo(str14),%o0
  405. !   writeNewline
  406.     sethi    %hi(strNL),%o0
  407.     call    printf
  408.     or    %o0,%lo(strNL),%o0
  409. ! WRITE STMT...
  410. !   writeString str15
  411.     sethi    %hi(str15),%o0
  412.     call    printf
  413.     or    %o0,%lo(str15),%o0
  414. !   writeNewline
  415.     sethi    %hi(strNL),%o0
  416.     call    printf
  417.     or    %o0,%lo(strNL),%o0
  418. ! READ STMT...
  419. !   t8 := &i1
  420.     set    display0,%o0
  421.     ld    [%o0],%o0
  422.     add    %o0,-4,%o0
  423.     st    %o0,[%fp+-16]
  424. !   readInt t8
  425.     ld    [%fp+-16],%o1
  426.     sethi    %hi(strInt),%o0
  427.     call    scanf
  428.     or    %o0,%lo(strInt),%o0
  429.     cmp    %o0,0
  430.     be    runtimeError3
  431.     nop
  432. !   t9 := &i2
  433.     set    display0,%o0
  434.     ld    [%o0],%o0
  435.     add    %o0,-8,%o0
  436.     st    %o0,[%fp+-20]
  437. !   readInt t9
  438.     ld    [%fp+-20],%o1
  439.     sethi    %hi(strInt),%o0
  440.     call    scanf
  441.     or    %o0,%lo(strInt),%o0
  442.     cmp    %o0,0
  443.     be    runtimeError3
  444.     nop
  445. !   t10 := &i3
  446.     set    display0,%o0
  447.     ld    [%o0],%o0
  448.     add    %o0,-12,%o0
  449.     st    %o0,[%fp+-24]
  450. !   readInt t10
  451.     ld    [%fp+-24],%o1
  452.     sethi    %hi(strInt),%o0
  453.     call    scanf
  454.     or    %o0,%lo(strInt),%o0
  455.     cmp    %o0,0
  456.     be    runtimeError3
  457.     nop
  458. ! WRITE STMT...
  459. !   writeString str16
  460.     sethi    %hi(str16),%o0
  461.     call    printf
  462.     or    %o0,%lo(str16),%o0
  463. !   writeInt i1
  464.     set    display0,%o1
  465.     ld    [%o1],%o1
  466.     ld    [%o1+-4],%o1
  467.     sethi    %hi(strInt),%o0
  468.     call    printf
  469.     or    %o0,%lo(strInt),%o0
  470. !   writeNewline
  471.     sethi    %hi(strNL),%o0
  472.     call    printf
  473.     or    %o0,%lo(strNL),%o0
  474. ! WRITE STMT...
  475. !   writeString str17
  476.     sethi    %hi(str17),%o0
  477.     call    printf
  478.     or    %o0,%lo(str17),%o0
  479. !   writeInt i2
  480.     set    display0,%o1
  481.     ld    [%o1],%o1
  482.     ld    [%o1+-8],%o1
  483.     sethi    %hi(strInt),%o0
  484.     call    printf
  485.     or    %o0,%lo(strInt),%o0
  486. !   writeNewline
  487.     sethi    %hi(strNL),%o0
  488.     call    printf
  489.     or    %o0,%lo(strNL),%o0
  490. ! WRITE STMT...
  491. !   writeString str18
  492.     sethi    %hi(str18),%o0
  493.     call    printf
  494.     or    %o0,%lo(str18),%o0
  495. !   writeInt i3
  496.     set    display0,%o1
  497.     ld    [%o1],%o1
  498.     ld    [%o1+-12],%o1
  499.     sethi    %hi(strInt),%o0
  500.     call    printf
  501.     or    %o0,%lo(strInt),%o0
  502. !   writeNewline
  503.     sethi    %hi(strNL),%o0
  504.     call    printf
  505.     or    %o0,%lo(strNL),%o0
  506. ! RETURN...
  507. !   returnVoid
  508.     set    display1,%o0
  509.     ld    [%fp+64],%o1
  510.     st    %o1,[%o0]
  511.     ret
  512.     restore
  513.