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
/
speed.out.bak
< prev
next >
Wrap
Text File
|
2006-03-05
|
10KB
|
523 lines
!
! PCAT Compiler Version 1.0
!
.global .div
.global .rem
!
! Standard data fields
!
.data
.align 8
temp: .double 0
.text
strNL: .asciz "\n"
strInt: .asciz "%d"
strFlt: .asciz "%g"
strTrue: .asciz "TRUE"
strFalse: .asciz "FALSE"
message1: .asciz "Execution Error: Allocation failed!\n"
message2: .asciz "Execution Error: Pointer is NIL!\n"
message3: .asciz "Execution Error: Read statement failed!\n"
message4: .asciz "Execution Error: Array index is out of bounds!\n"
message5: .asciz "Execution Error: Count is not positive in array constructor!\n"
.align 8
!
! runtimeError1-5
!
! Branch to one of these labels to print an error message and abort.
!
runtimeError1:
set message1,%o0
call printf
nop
call exit
mov 1,%o0
runtimeError2:
set message2,%o0
call printf
nop
call exit
mov 1,%o0
runtimeError3:
set message3,%o0
call printf
nop
call exit
mov 1,%o0
runtimeError4:
set message4,%o0
call printf
nop
call exit
mov 1,%o0
runtimeError5:
set message5,%o0
call printf
nop
call exit
mov 1,%o0
! writeFlt
!
! This routine is passed a single precision floating number in %f0.
! It prints it by calling printf. It uses registers %f0, %f1.
!
writeFlt:
save %sp,-128,%sp
fstod %f0,%f0
set temp,%l0
std %f0,[%l0]
ldd [%l0],%o0
mov %o1,%o2
mov %o0,%o1
set strFlt,%o0
call printf
nop
ret
restore
! writeBool
!
! This routine is passed an integer in %i0/o0. It prints "FALSE" if this
! integer is 0 and "TRUE" otherwise.
!
writeBool:
save %sp,-128,%sp
cmp %i0,%g0
be printFalse
nop
set strTrue,%o0
ba printEnd
nop
printFalse:
set strFalse,%o0
printEnd:
call printf
nop
ret
restore
!
! Additional Fields
!
.data
display0: .word 0
.text
str15: .asciz "Should print the numbers between 1 and 300:"
str14: .asciz " F"
str13: .asciz " E "
str12: .asciz "D "
str11: .asciz " C"
str10: .asciz " B "
str9: .asciz "A "
str8: .asciz " assignment takes."
str7: .asciz " and dividing by 10,000,000 will allow you to determine how long the"
str6: .asciz " Comparing the different times (between B and C, versus between E and F)"
str5: .asciz " x := y + z;"
str4: .asciz " The only difference is that the FOR loop contains the statement"
str3: .asciz " times. Between E and F is a FOR loop which also executes 10,000,000 times."
str2: .asciz " which executes 10,000,000 times. The program then prints D-E-F several"
str1: .asciz "Should print A-B-C several times. Between B and C is an empty FOR loop"
.align 8
! MAIN...
! mainEntry
.global main
main: save %sp,-200,%sp
set display0,%o0
st %fp,[%o0]
! VAR INITIALIZATION...
! i := 0
set 0,%o0
st %o0,[%fp+-4]
! VAR INITIALIZATION...
! j := i
ld [%fp+-4],%o0
st %o0,[%fp+-8]
! VAR INITIALIZATION...
! x := i
ld [%fp+-4],%o0
st %o0,[%fp+-12]
! VAR INITIALIZATION...
! y := i
ld [%fp+-4],%o0
st %o0,[%fp+-16]
! VAR INITIALIZATION...
! z := i
ld [%fp+-4],%o0
st %o0,[%fp+-20]
! WRITE STMT...
! writeString str1
sethi %hi(str1),%o0
call printf
or %o0,%lo(str1),%o0
! writeNewline
sethi %hi(strNL),%o0
call printf
or %o0,%lo(strNL),%o0
! WRITE STMT...
! writeString str2
sethi %hi(str2),%o0
call printf
or %o0,%lo(str2),%o0
! writeNewline
sethi %hi(strNL),%o0
call printf
or %o0,%lo(strNL),%o0
! WRITE STMT...
! writeString str3
sethi %hi(str3),%o0
call printf
or %o0,%lo(str3),%o0
! writeNewline
sethi %hi(strNL),%o0
call printf
or %o0,%lo(strNL),%o0
! WRITE STMT...
! writeString str4
sethi %hi(str4),%o0
call printf
or %o0,%lo(str4),%o0
! writeNewline
sethi %hi(strNL),%o0
call printf
or %o0,%lo(strNL),%o0
! WRITE STMT...
! writeString str5
sethi %hi(str5),%o0
call printf
or %o0,%lo(str5),%o0
! writeNewline
sethi %hi(strNL),%o0
call printf
or %o0,%lo(strNL),%o0
! WRITE STMT...
! writeString str6
sethi %hi(str6),%o0
call printf
or %o0,%lo(str6),%o0
! writeNewline
sethi %hi(strNL),%o0
call printf
or %o0,%lo(strNL),%o0
! WRITE STMT...
! writeString str7
sethi %hi(str7),%o0
call printf
or %o0,%lo(str7),%o0
! writeNewline
sethi %hi(strNL),%o0
call printf
or %o0,%lo(strNL),%o0
! WRITE STMT...
! writeString str8
sethi %hi(str8),%o0
call printf
or %o0,%lo(str8),%o0
! writeNewline
sethi %hi(strNL),%o0
call printf
or %o0,%lo(strNL),%o0
! FOR...
! t4 := &i
add %fp,-4,%o0
st %o0,[%fp+-36]
! t1 := 1
set 1,%o0
st %o0,[%fp+-24]
! t2 := 4
set 4,%o0
st %o0,[%fp+-28]
! t3 := 1
set 1,%o0
st %o0,[%fp+-32]
! *t4 := t1
ld [%fp+-24],%o0
ld [%fp+-36],%o1
st %o0,[%o1]
! Label_1:
Label_1:
! if t1 > t2 goto Label_2 (integer)
ld [%fp+-24],%o0
ld [%fp+-28],%o1
cmp %o0,%o1
bg Label_2
nop
! WRITE STMT...
! writeString str9
sethi %hi(str9),%o0
call printf
or %o0,%lo(str9),%o0
! writeNewline
sethi %hi(strNL),%o0
call printf
or %o0,%lo(strNL),%o0
! WRITE STMT...
! writeString str10
sethi %hi(str10),%o0
call printf
or %o0,%lo(str10),%o0
! writeNewline
sethi %hi(strNL),%o0
call printf
or %o0,%lo(strNL),%o0
! FOR...
! t8 := &j
add %fp,-8,%o0
st %o0,[%fp+-52]
! t5 := 1
set 1,%o0
st %o0,[%fp+-40]
! t6 := 10000000
set 10000000,%o0
st %o0,[%fp+-44]
! t7 := 1
set 1,%o0
st %o0,[%fp+-48]
! *t8 := t5
ld [%fp+-40],%o0
ld [%fp+-52],%o1
st %o0,[%o1]
! Label_3:
Label_3:
! if t5 > t6 goto Label_4 (integer)
ld [%fp+-40],%o0
ld [%fp+-44],%o1
cmp %o0,%o1
bg Label_4
nop
! END FOR...
! t5 := *t8
ld [%fp+-52],%o0
ld [%o0],%o0
st %o0,[%fp+-40]
! t5 := t5 + t7 (integer)
ld [%fp+-40],%o0
ld [%fp+-48],%o1
add %o0,%o1,%o1
st %o1,[%fp+-40]
! *t8 := t5
ld [%fp+-40],%o0
ld [%fp+-52],%o1
st %o0,[%o1]
! goto Label_3
ba Label_3
nop
! Label_4:
Label_4:
! WRITE STMT...
! writeString str11
sethi %hi(str11),%o0
call printf
or %o0,%lo(str11),%o0
! writeNewline
sethi %hi(strNL),%o0
call printf
or %o0,%lo(strNL),%o0
! END FOR...
! t1 := *t4
ld [%fp+-36],%o0
ld [%o0],%o0
st %o0,[%fp+-24]
! t1 := t1 + t3 (integer)
ld [%fp+-24],%o0
ld [%fp+-32],%o1
add %o0,%o1,%o1
st %o1,[%fp+-24]
! *t4 := t1
ld [%fp+-24],%o0
ld [%fp+-36],%o1
st %o0,[%o1]
! goto Label_1
ba Label_1
nop
! Label_2:
Label_2:
! FOR...
! t12 := &i
add %fp,-4,%o0
st %o0,[%fp+-68]
! t9 := 1
set 1,%o0
st %o0,[%fp+-56]
! t10 := 4
set 4,%o0
st %o0,[%fp+-60]
! t11 := 1
set 1,%o0
st %o0,[%fp+-64]
! *t12 := t9
ld [%fp+-56],%o0
ld [%fp+-68],%o1
st %o0,[%o1]
! Label_5:
Label_5:
! if t9 > t10 goto Label_6 (integer)
ld [%fp+-56],%o0
ld [%fp+-60],%o1
cmp %o0,%o1
bg Label_6
nop
! WRITE STMT...
! writeString str12
sethi %hi(str12),%o0
call printf
or %o0,%lo(str12),%o0
! writeNewline
sethi %hi(strNL),%o0
call printf
or %o0,%lo(strNL),%o0
! WRITE STMT...
! writeString str13
sethi %hi(str13),%o0
call printf
or %o0,%lo(str13),%o0
! writeNewline
sethi %hi(strNL),%o0
call printf
or %o0,%lo(strNL),%o0
! FOR...
! t16 := &j
add %fp,-8,%o0
st %o0,[%fp+-84]
! t13 := 1
set 1,%o0
st %o0,[%fp+-72]
! t14 := 10000000
set 10000000,%o0
st %o0,[%fp+-76]
! t15 := 1
set 1,%o0
st %o0,[%fp+-80]
! *t16 := t13
ld [%fp+-72],%o0
ld [%fp+-84],%o1
st %o0,[%o1]
! Label_7:
Label_7:
! if t13 > t14 goto Label_8 (integer)
ld [%fp+-72],%o0
ld [%fp+-76],%o1
cmp %o0,%o1
bg Label_8
nop
! ASSIGNMENT STMT...
! t17 := y + z (integer)
ld [%fp+-16],%o0
ld [%fp+-20],%o1
add %o0,%o1,%o1
st %o1,[%fp+-88]
! x := t17
ld [%fp+-88],%o0
st %o0,[%fp+-12]
! END FOR...
! t13 := *t16
ld [%fp+-84],%o0
ld [%o0],%o0
st %o0,[%fp+-72]
! t13 := t13 + t15 (integer)
ld [%fp+-72],%o0
ld [%fp+-80],%o1
add %o0,%o1,%o1
st %o1,[%fp+-72]
! *t16 := t13
ld [%fp+-72],%o0
ld [%fp+-84],%o1
st %o0,[%o1]
! goto Label_7
ba Label_7
nop
! Label_8:
Label_8:
! WRITE STMT...
! writeString str14
sethi %hi(str14),%o0
call printf
or %o0,%lo(str14),%o0
! writeNewline
sethi %hi(strNL),%o0
call printf
or %o0,%lo(strNL),%o0
! END FOR...
! t9 := *t12
ld [%fp+-68],%o0
ld [%o0],%o0
st %o0,[%fp+-56]
! t9 := t9 + t11 (integer)
ld [%fp+-56],%o0
ld [%fp+-64],%o1
add %o0,%o1,%o1
st %o1,[%fp+-56]
! *t12 := t9
ld [%fp+-56],%o0
ld [%fp+-68],%o1
st %o0,[%o1]
! goto Label_5
ba Label_5
nop
! Label_6:
Label_6:
! WRITE STMT...
! writeString str15
sethi %hi(str15),%o0
call printf
or %o0,%lo(str15),%o0
! writeNewline
sethi %hi(strNL),%o0
call printf
or %o0,%lo(strNL),%o0
! FOR...
! t21 := &i
add %fp,-4,%o0
st %o0,[%fp+-104]
! t18 := 1
set 1,%o0
st %o0,[%fp+-92]
! t19 := 300
set 300,%o0
st %o0,[%fp+-96]
! t20 := 1
set 1,%o0
st %o0,[%fp+-100]
! *t21 := t18
ld [%fp+-92],%o0
ld [%fp+-104],%o1
st %o0,[%o1]
! Label_9:
Label_9:
! if t18 > t19 goto Label_10 (integer)
ld [%fp+-92],%o0
ld [%fp+-96],%o1
cmp %o0,%o1
bg Label_10
nop
! WRITE STMT...
! writeInt i
ld [%fp+-4],%o1
sethi %hi(strInt),%o0
call printf
or %o0,%lo(strInt),%o0
! writeNewline
sethi %hi(strNL),%o0
call printf
or %o0,%lo(strNL),%o0
! END FOR...
! t18 := *t21
ld [%fp+-104],%o0
ld [%o0],%o0
st %o0,[%fp+-92]
! t18 := t18 + t20 (integer)
ld [%fp+-92],%o0
ld [%fp+-100],%o1
add %o0,%o1,%o1
st %o1,[%fp+-92]
! *t21 := t18
ld [%fp+-92],%o0
ld [%fp+-104],%o1
st %o0,[%o1]
! goto Label_9
ba Label_9
nop
! Label_10:
Label_10:
! MAIN EXIT...
! mainExit
ret
restore