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
/
write.out.bak
< prev
next >
Wrap
Text File
|
2006-03-05
|
7KB
|
362 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
float3: .single 0r0.0
float2: .single 0r123.456
float1: .single 0r654.321
str14: .asciz "Test complete!"
str13: .asciz ", b2 = "
str12: .asciz "b1 = "
str11: .asciz "Should print b1 = FALSE, b2 = TRUE..."
str10: .asciz "Should print 4321..."
str9: .asciz "Should print 654.321..."
str8: .asciz "Test printing variables..."
str7: .asciz "Should print FALSE..."
str6: .asciz "Should print TRUE..."
str5: .asciz "Should print 0..."
str4: .asciz "Should print 123.456..."
str3: .asciz "Should print 1234..."
str2: .asciz "Should print 1234..."
str1: .asciz "Test printing constants..."
.align 8
! MAIN...
! mainEntry
.global main
main: save %sp,-120,%sp
set display0,%o0
st %fp,[%o0]
! VAR INITIALIZATION...
! i := 4321
set 4321,%o0
st %o0,[%fp+-4]
! VAR INITIALIZATION...
! j := i
ld [%fp+-4],%o0
st %o0,[%fp+-8]
! VAR INITIALIZATION...
! k := i
ld [%fp+-4],%o0
st %o0,[%fp+-12]
! VAR INITIALIZATION...
! x := 654.321
set float1,%o0
ld [%o0],%o0
st %o0,[%fp+-16]
! VAR INITIALIZATION...
! b1 := 0
set 0,%o0
st %o0,[%fp+-20]
! VAR INITIALIZATION...
! b2 := 1
set 1,%o0
st %o0,[%fp+-24]
! 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...
! writeInt 1234
set 1234,%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 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...
! writeInt 1234
set 1234,%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...
! writeFloat 123.456
set float2,%o1
ld [%o1],%f0
call writeFlt
nop
! 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...
! writeFloat 0.0
set float3,%o1
ld [%o1],%f0
call writeFlt
nop
! 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...
! writeBoolean 1
set 1,%o0
call writeBool
nop
! 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...
! writeBoolean 0
set 0,%o0
call writeBool
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
! 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...
! writeFloat x
ld [%fp+-16],%f0
call writeFlt
nop
! 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
! 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
! 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
! WRITE STMT...
! writeString str12
sethi %hi(str12),%o0
call printf
or %o0,%lo(str12),%o0
! writeBoolean b1
ld [%fp+-20],%o0
call writeBool
nop
! writeString str13
sethi %hi(str13),%o0
call printf
or %o0,%lo(str13),%o0
! writeBoolean b2
ld [%fp+-24],%o0
call writeBool
nop
! 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
! MAIN EXIT...
! mainExit
ret
restore