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
/
call2.out.bak
< prev
next >
Wrap
Text File
|
2006-03-05
|
14KB
|
746 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
display1: .word 0
display2: .word 0
.text
float6: .single 0r1.9002
float5: .single 0r1.9001
float4: .single 0r1.9
float3: .single 0r0.9002
float2: .single 0r0.9001
float1: .single 0r0.9
str43: .asciz "...Leaving foo2"
str42: .asciz ", z2 = "
str41: .asciz ", y2 = "
str40: .asciz "x2 = "
str39: .asciz ", z1 = "
str38: .asciz ", y1 = "
str37: .asciz "x1 = "
str36: .asciz ", z0 = "
str35: .asciz ", y0 = "
str34: .asciz "x0 = "
str33: .asciz "Changing non-locals..."
str32: .asciz ", z2 = "
str31: .asciz ", y2 = "
str30: .asciz "x2 = "
str29: .asciz ", z1 = "
str28: .asciz ", y1 = "
str27: .asciz "x1 = "
str26: .asciz ", z0 = "
str25: .asciz ", y0 = "
str24: .asciz "x0 = "
str23: .asciz "Within foo2..."
str22: .asciz "...Leaving foo1"
str21: .asciz ", z1 = "
str20: .asciz ", y1 = "
str19: .asciz "x1 = "
str18: .asciz ", z0 = "
str17: .asciz ", y0 = "
str16: .asciz "x0 = "
str15: .asciz ", z1 = "
str14: .asciz ", y1 = "
str13: .asciz "x1 = "
str12: .asciz ", z0 = "
str11: .asciz ", y0 = "
str10: .asciz "x0 = "
str9: .asciz "Within foo1..."
str8: .asciz "...Leaving main"
str7: .asciz ", z0 = "
str6: .asciz ", y0 = "
str5: .asciz "x0 = "
str4: .asciz ", z0 = "
str3: .asciz ", y0 = "
str2: .asciz "x0 = "
str1: .asciz "Within main..."
.align 8
! MAIN...
! mainEntry
.global main
main: save %sp,-104,%sp
set display0,%o0
st %fp,[%o0]
! VAR INITIALIZATION...
! x0 := 0
set 0,%o0
st %o0,[%fp+-4]
! VAR INITIALIZATION...
! y0 := x0
ld [%fp+-4],%o0
st %o0,[%fp+-8]
! VAR INITIALIZATION...
! z0 := 0.9
set float1,%o0
ld [%o0],%o0
st %o0,[%fp+-12]
! 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
! writeInt x0
ld [%fp+-4],%o1
sethi %hi(strInt),%o0
call printf
or %o0,%lo(strInt),%o0
! writeString str3
sethi %hi(str3),%o0
call printf
or %o0,%lo(str3),%o0
! writeInt y0
ld [%fp+-8],%o1
sethi %hi(strInt),%o0
call printf
or %o0,%lo(strInt),%o0
! writeString str4
sethi %hi(str4),%o0
call printf
or %o0,%lo(str4),%o0
! writeFloat z0
ld [%fp+-12],%f0
call writeFlt
nop
! writeNewline
sethi %hi(strNL),%o0
call printf
or %o0,%lo(strNL),%o0
! CALL STMT...
! call p1_foo1
call p1_foo1
nop
! WRITE STMT...
! writeString str5
sethi %hi(str5),%o0
call printf
or %o0,%lo(str5),%o0
! writeInt x0
ld [%fp+-4],%o1
sethi %hi(strInt),%o0
call printf
or %o0,%lo(strInt),%o0
! writeString str6
sethi %hi(str6),%o0
call printf
or %o0,%lo(str6),%o0
! writeInt y0
ld [%fp+-8],%o1
sethi %hi(strInt),%o0
call printf
or %o0,%lo(strInt),%o0
! writeString str7
sethi %hi(str7),%o0
call printf
or %o0,%lo(str7),%o0
! writeFloat z0
ld [%fp+-12],%f0
call writeFlt
nop
! 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
! MAIN EXIT...
! mainExit
ret
restore
! PROCEDURE...
! procEntry p1_foo1,lexLev=1,frameSize=104
p1_foo1: save %sp,-104,%sp
set display1,%o0
ld [%o0],%o1
st %o1,[%fp+64]
st %fp,[%o0]
! VAR INITIALIZATION...
! x1 := 1
set 1,%o0
st %o0,[%fp+-4]
! VAR INITIALIZATION...
! y1 := x1
ld [%fp+-4],%o0
st %o0,[%fp+-8]
! VAR INITIALIZATION...
! z1 := 0.9001
set float2,%o0
ld [%o0],%o0
st %o0,[%fp+-12]
! 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
! writeInt x0
set display0,%o1
ld [%o1],%o1
ld [%o1+-4],%o1
sethi %hi(strInt),%o0
call printf
or %o0,%lo(strInt),%o0
! writeString str11
sethi %hi(str11),%o0
call printf
or %o0,%lo(str11),%o0
! writeInt y0
set display0,%o1
ld [%o1],%o1
ld [%o1+-8],%o1
sethi %hi(strInt),%o0
call printf
or %o0,%lo(strInt),%o0
! writeString str12
sethi %hi(str12),%o0
call printf
or %o0,%lo(str12),%o0
! writeFloat z0
set display0,%o1
ld [%o1],%o1
ld [%o1+-12],%f0
call writeFlt
nop
! 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
! writeInt x1
ld [%fp+-4],%o1
sethi %hi(strInt),%o0
call printf
or %o0,%lo(strInt),%o0
! writeString str14
sethi %hi(str14),%o0
call printf
or %o0,%lo(str14),%o0
! writeInt y1
ld [%fp+-8],%o1
sethi %hi(strInt),%o0
call printf
or %o0,%lo(strInt),%o0
! writeString str15
sethi %hi(str15),%o0
call printf
or %o0,%lo(str15),%o0
! writeFloat z1
ld [%fp+-12],%f0
call writeFlt
nop
! writeNewline
sethi %hi(strNL),%o0
call printf
or %o0,%lo(strNL),%o0
! CALL STMT...
! call p2_foo2
call p2_foo2
nop
! WRITE STMT...
! writeString str16
sethi %hi(str16),%o0
call printf
or %o0,%lo(str16),%o0
! writeInt x0
set display0,%o1
ld [%o1],%o1
ld [%o1+-4],%o1
sethi %hi(strInt),%o0
call printf
or %o0,%lo(strInt),%o0
! writeString str17
sethi %hi(str17),%o0
call printf
or %o0,%lo(str17),%o0
! writeInt y0
set display0,%o1
ld [%o1],%o1
ld [%o1+-8],%o1
sethi %hi(strInt),%o0
call printf
or %o0,%lo(strInt),%o0
! writeString str18
sethi %hi(str18),%o0
call printf
or %o0,%lo(str18),%o0
! writeFloat z0
set display0,%o1
ld [%o1],%o1
ld [%o1+-12],%f0
call writeFlt
nop
! writeNewline
sethi %hi(strNL),%o0
call printf
or %o0,%lo(strNL),%o0
! WRITE STMT...
! writeString str19
sethi %hi(str19),%o0
call printf
or %o0,%lo(str19),%o0
! writeInt x1
ld [%fp+-4],%o1
sethi %hi(strInt),%o0
call printf
or %o0,%lo(strInt),%o0
! writeString str20
sethi %hi(str20),%o0
call printf
or %o0,%lo(str20),%o0
! writeInt y1
ld [%fp+-8],%o1
sethi %hi(strInt),%o0
call printf
or %o0,%lo(strInt),%o0
! writeString str21
sethi %hi(str21),%o0
call printf
or %o0,%lo(str21),%o0
! writeFloat z1
ld [%fp+-12],%f0
call writeFlt
nop
! writeNewline
sethi %hi(strNL),%o0
call printf
or %o0,%lo(strNL),%o0
! WRITE STMT...
! writeString str22
sethi %hi(str22),%o0
call printf
or %o0,%lo(str22),%o0
! writeNewline
sethi %hi(strNL),%o0
call printf
or %o0,%lo(strNL),%o0
! RETURN...
! returnVoid
set display1,%o0
ld [%fp+64],%o1
st %o1,[%o0]
ret
restore
! PROCEDURE...
! procEntry p2_foo2,lexLev=2,frameSize=104
p2_foo2: save %sp,-104,%sp
set display2,%o0
ld [%o0],%o1
st %o1,[%fp+64]
st %fp,[%o0]
! VAR INITIALIZATION...
! x2 := 2
set 2,%o0
st %o0,[%fp+-4]
! VAR INITIALIZATION...
! y2 := x2
ld [%fp+-4],%o0
st %o0,[%fp+-8]
! VAR INITIALIZATION...
! z2 := 0.9002
set float3,%o0
ld [%o0],%o0
st %o0,[%fp+-12]
! WRITE STMT...
! writeString str23
sethi %hi(str23),%o0
call printf
or %o0,%lo(str23),%o0
! writeNewline
sethi %hi(strNL),%o0
call printf
or %o0,%lo(strNL),%o0
! WRITE STMT...
! writeString str24
sethi %hi(str24),%o0
call printf
or %o0,%lo(str24),%o0
! writeInt x0
set display0,%o1
ld [%o1],%o1
ld [%o1+-4],%o1
sethi %hi(strInt),%o0
call printf
or %o0,%lo(strInt),%o0
! writeString str25
sethi %hi(str25),%o0
call printf
or %o0,%lo(str25),%o0
! writeInt y0
set display0,%o1
ld [%o1],%o1
ld [%o1+-8],%o1
sethi %hi(strInt),%o0
call printf
or %o0,%lo(strInt),%o0
! writeString str26
sethi %hi(str26),%o0
call printf
or %o0,%lo(str26),%o0
! writeFloat z0
set display0,%o1
ld [%o1],%o1
ld [%o1+-12],%f0
call writeFlt
nop
! writeNewline
sethi %hi(strNL),%o0
call printf
or %o0,%lo(strNL),%o0
! WRITE STMT...
! writeString str27
sethi %hi(str27),%o0
call printf
or %o0,%lo(str27),%o0
! writeInt x1
set display1,%o1
ld [%o1],%o1
ld [%o1+-4],%o1
sethi %hi(strInt),%o0
call printf
or %o0,%lo(strInt),%o0
! writeString str28
sethi %hi(str28),%o0
call printf
or %o0,%lo(str28),%o0
! writeInt y1
set display1,%o1
ld [%o1],%o1
ld [%o1+-8],%o1
sethi %hi(strInt),%o0
call printf
or %o0,%lo(strInt),%o0
! writeString str29
sethi %hi(str29),%o0
call printf
or %o0,%lo(str29),%o0
! writeFloat z1
set display1,%o1
ld [%o1],%o1
ld [%o1+-12],%f0
call writeFlt
nop
! writeNewline
sethi %hi(strNL),%o0
call printf
or %o0,%lo(strNL),%o0
! WRITE STMT...
! writeString str30
sethi %hi(str30),%o0
call printf
or %o0,%lo(str30),%o0
! writeInt x2
ld [%fp+-4],%o1
sethi %hi(strInt),%o0
call printf
or %o0,%lo(strInt),%o0
! writeString str31
sethi %hi(str31),%o0
call printf
or %o0,%lo(str31),%o0
! writeInt y2
ld [%fp+-8],%o1
sethi %hi(strInt),%o0
call printf
or %o0,%lo(strInt),%o0
! writeString str32
sethi %hi(str32),%o0
call printf
or %o0,%lo(str32),%o0
! writeFloat z2
ld [%fp+-12],%f0
call writeFlt
nop
! writeNewline
sethi %hi(strNL),%o0
call printf
or %o0,%lo(strNL),%o0
! WRITE STMT...
! writeString str33
sethi %hi(str33),%o0
call printf
or %o0,%lo(str33),%o0
! writeNewline
sethi %hi(strNL),%o0
call printf
or %o0,%lo(strNL),%o0
! ASSIGNMENT STMT...
! y0 := 1000
set 1000,%o0
set display0,%o1
ld [%o1],%o1
st %o0,[%o1+-8]
! ASSIGNMENT STMT...
! y1 := 1001
set 1001,%o0
set display1,%o1
ld [%o1],%o1
st %o0,[%o1+-8]
! ASSIGNMENT STMT...
! y2 := 1002
set 1002,%o0
st %o0,[%fp+-8]
! ASSIGNMENT STMT...
! z0 := 1.9
set float4,%o0
ld [%o0],%o0
set display0,%o1
ld [%o1],%o1
st %o0,[%o1+-12]
! ASSIGNMENT STMT...
! z1 := 1.9001
set float5,%o0
ld [%o0],%o0
set display1,%o1
ld [%o1],%o1
st %o0,[%o1+-12]
! ASSIGNMENT STMT...
! z2 := 1.9002
set float6,%o0
ld [%o0],%o0
st %o0,[%fp+-12]
! WRITE STMT...
! writeString str34
sethi %hi(str34),%o0
call printf
or %o0,%lo(str34),%o0
! writeInt x0
set display0,%o1
ld [%o1],%o1
ld [%o1+-4],%o1
sethi %hi(strInt),%o0
call printf
or %o0,%lo(strInt),%o0
! writeString str35
sethi %hi(str35),%o0
call printf
or %o0,%lo(str35),%o0
! writeInt y0
set display0,%o1
ld [%o1],%o1
ld [%o1+-8],%o1
sethi %hi(strInt),%o0
call printf
or %o0,%lo(strInt),%o0
! writeString str36
sethi %hi(str36),%o0
call printf
or %o0,%lo(str36),%o0
! writeFloat z0
set display0,%o1
ld [%o1],%o1
ld [%o1+-12],%f0
call writeFlt
nop
! writeNewline
sethi %hi(strNL),%o0
call printf
or %o0,%lo(strNL),%o0
! WRITE STMT...
! writeString str37
sethi %hi(str37),%o0
call printf
or %o0,%lo(str37),%o0
! writeInt x1
set display1,%o1
ld [%o1],%o1
ld [%o1+-4],%o1
sethi %hi(strInt),%o0
call printf
or %o0,%lo(strInt),%o0
! writeString str38
sethi %hi(str38),%o0
call printf
or %o0,%lo(str38),%o0
! writeInt y1
set display1,%o1
ld [%o1],%o1
ld [%o1+-8],%o1
sethi %hi(strInt),%o0
call printf
or %o0,%lo(strInt),%o0
! writeString str39
sethi %hi(str39),%o0
call printf
or %o0,%lo(str39),%o0
! writeFloat z1
set display1,%o1
ld [%o1],%o1
ld [%o1+-12],%f0
call writeFlt
nop
! writeNewline
sethi %hi(strNL),%o0
call printf
or %o0,%lo(strNL),%o0
! WRITE STMT...
! writeString str40
sethi %hi(str40),%o0
call printf
or %o0,%lo(str40),%o0
! writeInt x2
ld [%fp+-4],%o1
sethi %hi(strInt),%o0
call printf
or %o0,%lo(strInt),%o0
! writeString str41
sethi %hi(str41),%o0
call printf
or %o0,%lo(str41),%o0
! writeInt y2
ld [%fp+-8],%o1
sethi %hi(strInt),%o0
call printf
or %o0,%lo(strInt),%o0
! writeString str42
sethi %hi(str42),%o0
call printf
or %o0,%lo(str42),%o0
! writeFloat z2
ld [%fp+-12],%f0
call writeFlt
nop
! writeNewline
sethi %hi(strNL),%o0
call printf
or %o0,%lo(strNL),%o0
! WRITE STMT...
! writeString str43
sethi %hi(str43),%o0
call printf
or %o0,%lo(str43),%o0
! writeNewline
sethi %hi(strNL),%o0
call printf
or %o0,%lo(strNL),%o0
! RETURN...
! returnVoid
set display2,%o0
ld [%fp+64],%o1
st %o1,[%o0]
ret
restore