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 >
Wrap
Text File
|
2006-03-05
|
10KB
|
513 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
.text
str18: .asciz "i3 = "
str17: .asciz "i2 = "
str16: .asciz "i1 = "
str15: .asciz "PLEASE ENTER 3 INTEGERS:"
str14: .asciz "About to call readInt (i1, i2, i3)..."
str13: .asciz "j3 = "
str12: .asciz "j2 = "
str11: .asciz "j1 = "
str10: .asciz "PLEASE ENTER 3 INTEGERS:"
str9: .asciz "About to call readInt (j1, j2, j3)..."
str8: .asciz "i3 = "
str7: .asciz "i2 = "
str6: .asciz "i1 = "
str5: .asciz "PLEASE ENTER 3 INTEGERS:"
str4: .asciz "About to call readInt (i1, i2, i3)..."
str3: .asciz "i1 = "
str2: .asciz "PLEASE ENTER AN INTEGER:"
str1: .asciz "About to call readInt(i)..."
.align 8
! MAIN...
! mainEntry
.global main
main: save %sp,-120,%sp
set display0,%o0
st %fp,[%o0]
! VAR INITIALIZATION...
! i1 := 0
set 0,%o0
st %o0,[%fp+-4]
! VAR INITIALIZATION...
! i2 := i1
ld [%fp+-4],%o0
st %o0,[%fp+-8]
! VAR INITIALIZATION...
! i3 := i1
ld [%fp+-4],%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
! writeNewline
sethi %hi(strNL),%o0
call printf
or %o0,%lo(strNL),%o0
! READ STMT...
! t1 := &i1
add %fp,-4,%o0
st %o0,[%fp+-16]
! readInt t1
ld [%fp+-16],%o1
sethi %hi(strInt),%o0
call scanf
or %o0,%lo(strInt),%o0
cmp %o0,0
be runtimeError3
nop
! WRITE STMT...
! writeString str3
sethi %hi(str3),%o0
call printf
or %o0,%lo(str3),%o0
! writeInt i1
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
! 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
! READ STMT...
! t2 := &i1
add %fp,-4,%o0
st %o0,[%fp+-20]
! readInt t2
ld [%fp+-20],%o1
sethi %hi(strInt),%o0
call scanf
or %o0,%lo(strInt),%o0
cmp %o0,0
be runtimeError3
nop
! t3 := &i2
add %fp,-8,%o0
st %o0,[%fp+-24]
! readInt t3
ld [%fp+-24],%o1
sethi %hi(strInt),%o0
call scanf
or %o0,%lo(strInt),%o0
cmp %o0,0
be runtimeError3
nop
! t4 := &i3
add %fp,-12,%o0
st %o0,[%fp+-28]
! readInt t4
ld [%fp+-28],%o1
sethi %hi(strInt),%o0
call scanf
or %o0,%lo(strInt),%o0
cmp %o0,0
be runtimeError3
nop
! WRITE STMT...
! writeString str6
sethi %hi(str6),%o0
call printf
or %o0,%lo(str6),%o0
! writeInt i1
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
! WRITE STMT...
! writeString str7
sethi %hi(str7),%o0
call printf
or %o0,%lo(str7),%o0
! writeInt i2
ld [%fp+-8],%o1
sethi %hi(strInt),%o0
call printf
or %o0,%lo(strInt),%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
! writeInt i3
ld [%fp+-12],%o1
sethi %hi(strInt),%o0
call printf
or %o0,%lo(strInt),%o0
! writeNewline
sethi %hi(strNL),%o0
call printf
or %o0,%lo(strNL),%o0
! CALL STMT...
! param 1,1
set 1,%o0
st %o0,[%sp+68]
! param 2,2
set 2,%o0
st %o0,[%sp+72]
! param 3,3
set 3,%o0
st %o0,[%sp+76]
! call p1_foo
call p1_foo
nop
! MAIN EXIT...
! mainExit
ret
restore
! PROCEDURE...
! procEntry p1_foo,lexLev=1,frameSize=120
p1_foo: save %sp,-120,%sp
set display1,%o0
ld [%o0],%o1
st %o1,[%fp+64]
st %fp,[%o0]
! formal 1,j1
! formal 2,j2
! formal 3,j3
! 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
! READ STMT...
! t5 := &j1
add %fp,68,%o0
st %o0,[%fp+-4]
! readInt t5
ld [%fp+-4],%o1
sethi %hi(strInt),%o0
call scanf
or %o0,%lo(strInt),%o0
cmp %o0,0
be runtimeError3
nop
! t6 := &j2
add %fp,72,%o0
st %o0,[%fp+-8]
! readInt t6
ld [%fp+-8],%o1
sethi %hi(strInt),%o0
call scanf
or %o0,%lo(strInt),%o0
cmp %o0,0
be runtimeError3
nop
! t7 := &j3
add %fp,76,%o0
st %o0,[%fp+-12]
! readInt t7
ld [%fp+-12],%o1
sethi %hi(strInt),%o0
call scanf
or %o0,%lo(strInt),%o0
cmp %o0,0
be runtimeError3
nop
! WRITE STMT...
! writeString str11
sethi %hi(str11),%o0
call printf
or %o0,%lo(str11),%o0
! writeInt j1
ld [%fp+68],%o1
sethi %hi(strInt),%o0
call printf
or %o0,%lo(strInt),%o0
! writeNewline
sethi %hi(strNL),%o0
call printf
or %o0,%lo(strNL),%o0
! WRITE STMT...
! writeString str12
sethi %hi(str12),%o0
call printf
or %o0,%lo(str12),%o0
! writeInt j2
ld [%fp+72],%o1
sethi %hi(strInt),%o0
call printf
or %o0,%lo(strInt),%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
! writeInt j3
ld [%fp+76],%o1
sethi %hi(strInt),%o0
call printf
or %o0,%lo(strInt),%o0
! writeNewline
sethi %hi(strNL),%o0
call printf
or %o0,%lo(strNL),%o0
! 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
! 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
! READ STMT...
! t8 := &i1
set display0,%o0
ld [%o0],%o0
add %o0,-4,%o0
st %o0,[%fp+-16]
! readInt t8
ld [%fp+-16],%o1
sethi %hi(strInt),%o0
call scanf
or %o0,%lo(strInt),%o0
cmp %o0,0
be runtimeError3
nop
! t9 := &i2
set display0,%o0
ld [%o0],%o0
add %o0,-8,%o0
st %o0,[%fp+-20]
! readInt t9
ld [%fp+-20],%o1
sethi %hi(strInt),%o0
call scanf
or %o0,%lo(strInt),%o0
cmp %o0,0
be runtimeError3
nop
! t10 := &i3
set display0,%o0
ld [%o0],%o0
add %o0,-12,%o0
st %o0,[%fp+-24]
! readInt t10
ld [%fp+-24],%o1
sethi %hi(strInt),%o0
call scanf
or %o0,%lo(strInt),%o0
cmp %o0,0
be runtimeError3
nop
! WRITE STMT...
! writeString str16
sethi %hi(str16),%o0
call printf
or %o0,%lo(str16),%o0
! writeInt i1
set display0,%o1
ld [%o1],%o1
ld [%o1+-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
! WRITE STMT...
! writeString str17
sethi %hi(str17),%o0
call printf
or %o0,%lo(str17),%o0
! writeInt i2
set display0,%o1
ld [%o1],%o1
ld [%o1+-8],%o1
sethi %hi(strInt),%o0
call printf
or %o0,%lo(strInt),%o0
! writeNewline
sethi %hi(strNL),%o0
call printf
or %o0,%lo(strNL),%o0
! WRITE STMT...
! writeString str18
sethi %hi(str18),%o0
call printf
or %o0,%lo(str18),%o0
! writeInt i3
set display0,%o1
ld [%o1],%o1
ld [%o1+-12],%o1
sethi %hi(strInt),%o0
call printf
or %o0,%lo(strInt),%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