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
/
alloc2.out.bak
< prev
next >
Wrap
Text File
|
2006-03-05
|
12KB
|
612 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
float4: .single 0r555.666
float3: .single 0r222.333
float2: .single 0r654.321
float1: .single 0r123.456
str10: .asciz "Should print 555.666..."
str9: .asciz "Should print 444..."
str8: .asciz "Should print FALSE..."
str7: .asciz "Should print 222.333..."
str6: .asciz "Should print 111..."
str5: .asciz "Should print 654.321..."
str4: .asciz "Should print 321..."
str3: .asciz "Should print TRUE..."
str2: .asciz "Should print 123.456..."
str1: .asciz "Should print 123..."
.align 8
! MAIN...
! mainEntry
.global main
main: save %sp,-224,%sp
set display0,%o0
st %fp,[%o0]
! VAR INITIALIZATION...
! p := 0
set 0,%o0
st %o0,[%fp+-4]
! ASSIGNMENT STMT...
! t1 := alloc (24)
set 1,%o0
set 24,%o1
call calloc
nop
st %o0,[%fp+-8]
! if t1 = 0 goto runtimeError1 (integer)
ld [%fp+-8],%o0
set 0,%o1
cmp %o0,%o1
be runtimeError1
nop
! t2 := t1 + 0 (integer)
ld [%fp+-8],%o0
set 0,%o1
add %o0,%o1,%o1
st %o1,[%fp+-12]
! *t2 := 123
set 123,%o0
ld [%fp+-12],%o1
st %o0,[%o1]
! t2 := t1 + 4 (integer)
ld [%fp+-8],%o0
set 4,%o1
add %o0,%o1,%o1
st %o1,[%fp+-12]
! *t2 := 123.456
set float1,%o0
ld [%o0],%o0
ld [%fp+-12],%o1
st %o0,[%o1]
! t2 := t1 + 8 (integer)
ld [%fp+-8],%o0
set 8,%o1
add %o0,%o1,%o1
st %o1,[%fp+-12]
! *t2 := 1
set 1,%o0
ld [%fp+-12],%o1
st %o0,[%o1]
! t2 := t1 + 12 (integer)
ld [%fp+-8],%o0
set 12,%o1
add %o0,%o1,%o1
st %o1,[%fp+-12]
! *t2 := 321
set 321,%o0
ld [%fp+-12],%o1
st %o0,[%o1]
! t2 := t1 + 16 (integer)
ld [%fp+-8],%o0
set 16,%o1
add %o0,%o1,%o1
st %o1,[%fp+-12]
! *t2 := 654.321
set float2,%o0
ld [%o0],%o0
ld [%fp+-12],%o1
st %o0,[%o1]
! t3 := alloc (20)
set 1,%o0
set 20,%o1
call calloc
nop
st %o0,[%fp+-16]
! if t3 = 0 goto runtimeError1 (integer)
ld [%fp+-16],%o0
set 0,%o1
cmp %o0,%o1
be runtimeError1
nop
! t4 := t3 + 0 (integer)
ld [%fp+-16],%o0
set 0,%o1
add %o0,%o1,%o1
st %o1,[%fp+-20]
! *t4 := 111
set 111,%o0
ld [%fp+-20],%o1
st %o0,[%o1]
! t4 := t3 + 4 (integer)
ld [%fp+-16],%o0
set 4,%o1
add %o0,%o1,%o1
st %o1,[%fp+-20]
! *t4 := 222.333
set float3,%o0
ld [%o0],%o0
ld [%fp+-20],%o1
st %o0,[%o1]
! t4 := t3 + 8 (integer)
ld [%fp+-16],%o0
set 8,%o1
add %o0,%o1,%o1
st %o1,[%fp+-20]
! *t4 := 0
set 0,%o0
ld [%fp+-20],%o1
st %o0,[%o1]
! t4 := t3 + 12 (integer)
ld [%fp+-16],%o0
set 12,%o1
add %o0,%o1,%o1
st %o1,[%fp+-20]
! *t4 := 444
set 444,%o0
ld [%fp+-20],%o1
st %o0,[%o1]
! t4 := t3 + 16 (integer)
ld [%fp+-16],%o0
set 16,%o1
add %o0,%o1,%o1
st %o1,[%fp+-20]
! *t4 := 555.666
set float4,%o0
ld [%o0],%o0
ld [%fp+-20],%o1
st %o0,[%o1]
! t2 := t1 + 20 (integer)
ld [%fp+-8],%o0
set 20,%o1
add %o0,%o1,%o1
st %o1,[%fp+-12]
! *t2 := t3
ld [%fp+-16],%o0
ld [%fp+-12],%o1
st %o0,[%o1]
! p := t1
ld [%fp+-8],%o0
st %o0,[%fp+-4]
! WRITE STMT...
! writeString str1
sethi %hi(str1),%o0
call printf
or %o0,%lo(str1),%o0
! if p = 0 goto runtimeError2 (integer)
ld [%fp+-4],%o0
set 0,%o1
cmp %o0,%o1
be runtimeError2
nop
! t5 := *p
ld [%fp+-4],%o0
ld [%o0],%o0
st %o0,[%fp+-24]
! writeInt t5
ld [%fp+-24],%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 str2
sethi %hi(str2),%o0
call printf
or %o0,%lo(str2),%o0
! if p = 0 goto runtimeError2 (integer)
ld [%fp+-4],%o0
set 0,%o1
cmp %o0,%o1
be runtimeError2
nop
! t6 := p + 4 (integer)
ld [%fp+-4],%o0
set 4,%o1
add %o0,%o1,%o1
st %o1,[%fp+-28]
! t7 := *t6
ld [%fp+-28],%o0
ld [%o0],%o0
st %o0,[%fp+-32]
! writeFloat t7
ld [%fp+-32],%f0
call writeFlt
nop
! 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
! if p = 0 goto runtimeError2 (integer)
ld [%fp+-4],%o0
set 0,%o1
cmp %o0,%o1
be runtimeError2
nop
! t8 := p + 8 (integer)
ld [%fp+-4],%o0
set 8,%o1
add %o0,%o1,%o1
st %o1,[%fp+-36]
! t9 := *t8
ld [%fp+-36],%o0
ld [%o0],%o0
st %o0,[%fp+-40]
! writeBoolean t9
ld [%fp+-40],%o0
call writeBool
nop
! 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
! if p = 0 goto runtimeError2 (integer)
ld [%fp+-4],%o0
set 0,%o1
cmp %o0,%o1
be runtimeError2
nop
! t10 := p + 12 (integer)
ld [%fp+-4],%o0
set 12,%o1
add %o0,%o1,%o1
st %o1,[%fp+-44]
! t11 := *t10
ld [%fp+-44],%o0
ld [%o0],%o0
st %o0,[%fp+-48]
! writeInt t11
ld [%fp+-48],%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 str5
sethi %hi(str5),%o0
call printf
or %o0,%lo(str5),%o0
! if p = 0 goto runtimeError2 (integer)
ld [%fp+-4],%o0
set 0,%o1
cmp %o0,%o1
be runtimeError2
nop
! t12 := p + 16 (integer)
ld [%fp+-4],%o0
set 16,%o1
add %o0,%o1,%o1
st %o1,[%fp+-52]
! t13 := *t12
ld [%fp+-52],%o0
ld [%o0],%o0
st %o0,[%fp+-56]
! writeFloat t13
ld [%fp+-56],%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
! if p = 0 goto runtimeError2 (integer)
ld [%fp+-4],%o0
set 0,%o1
cmp %o0,%o1
be runtimeError2
nop
! t14 := p + 20 (integer)
ld [%fp+-4],%o0
set 20,%o1
add %o0,%o1,%o1
st %o1,[%fp+-60]
! t15 := *t14
ld [%fp+-60],%o0
ld [%o0],%o0
st %o0,[%fp+-64]
! if t15 = 0 goto runtimeError2 (integer)
ld [%fp+-64],%o0
set 0,%o1
cmp %o0,%o1
be runtimeError2
nop
! t16 := *t15
ld [%fp+-64],%o0
ld [%o0],%o0
st %o0,[%fp+-68]
! writeInt t16
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 str7
sethi %hi(str7),%o0
call printf
or %o0,%lo(str7),%o0
! if p = 0 goto runtimeError2 (integer)
ld [%fp+-4],%o0
set 0,%o1
cmp %o0,%o1
be runtimeError2
nop
! t17 := p + 20 (integer)
ld [%fp+-4],%o0
set 20,%o1
add %o0,%o1,%o1
st %o1,[%fp+-72]
! t18 := *t17
ld [%fp+-72],%o0
ld [%o0],%o0
st %o0,[%fp+-76]
! if t18 = 0 goto runtimeError2 (integer)
ld [%fp+-76],%o0
set 0,%o1
cmp %o0,%o1
be runtimeError2
nop
! t19 := t18 + 4 (integer)
ld [%fp+-76],%o0
set 4,%o1
add %o0,%o1,%o1
st %o1,[%fp+-80]
! t20 := *t19
ld [%fp+-80],%o0
ld [%o0],%o0
st %o0,[%fp+-84]
! writeFloat t20
ld [%fp+-84],%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
! if p = 0 goto runtimeError2 (integer)
ld [%fp+-4],%o0
set 0,%o1
cmp %o0,%o1
be runtimeError2
nop
! t21 := p + 20 (integer)
ld [%fp+-4],%o0
set 20,%o1
add %o0,%o1,%o1
st %o1,[%fp+-88]
! t22 := *t21
ld [%fp+-88],%o0
ld [%o0],%o0
st %o0,[%fp+-92]
! if t22 = 0 goto runtimeError2 (integer)
ld [%fp+-92],%o0
set 0,%o1
cmp %o0,%o1
be runtimeError2
nop
! t23 := t22 + 8 (integer)
ld [%fp+-92],%o0
set 8,%o1
add %o0,%o1,%o1
st %o1,[%fp+-96]
! t24 := *t23
ld [%fp+-96],%o0
ld [%o0],%o0
st %o0,[%fp+-100]
! writeBoolean t24
ld [%fp+-100],%o0
call writeBool
nop
! 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
! if p = 0 goto runtimeError2 (integer)
ld [%fp+-4],%o0
set 0,%o1
cmp %o0,%o1
be runtimeError2
nop
! t25 := p + 20 (integer)
ld [%fp+-4],%o0
set 20,%o1
add %o0,%o1,%o1
st %o1,[%fp+-104]
! t26 := *t25
ld [%fp+-104],%o0
ld [%o0],%o0
st %o0,[%fp+-108]
! if t26 = 0 goto runtimeError2 (integer)
ld [%fp+-108],%o0
set 0,%o1
cmp %o0,%o1
be runtimeError2
nop
! t27 := t26 + 12 (integer)
ld [%fp+-108],%o0
set 12,%o1
add %o0,%o1,%o1
st %o1,[%fp+-112]
! t28 := *t27
ld [%fp+-112],%o0
ld [%o0],%o0
st %o0,[%fp+-116]
! writeInt t28
ld [%fp+-116],%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 str10
sethi %hi(str10),%o0
call printf
or %o0,%lo(str10),%o0
! if p = 0 goto runtimeError2 (integer)
ld [%fp+-4],%o0
set 0,%o1
cmp %o0,%o1
be runtimeError2
nop
! t29 := p + 20 (integer)
ld [%fp+-4],%o0
set 20,%o1
add %o0,%o1,%o1
st %o1,[%fp+-120]
! t30 := *t29
ld [%fp+-120],%o0
ld [%o0],%o0
st %o0,[%fp+-124]
! if t30 = 0 goto runtimeError2 (integer)
ld [%fp+-124],%o0
set 0,%o1
cmp %o0,%o1
be runtimeError2
nop
! t31 := t30 + 16 (integer)
ld [%fp+-124],%o0
set 16,%o1
add %o0,%o1,%o1
st %o1,[%fp+-128]
! t32 := *t31
ld [%fp+-128],%o0
ld [%o0],%o0
st %o0,[%fp+-132]
! writeFloat t32
ld [%fp+-132],%f0
call writeFlt
nop
! writeNewline
sethi %hi(strNL),%o0
call printf
or %o0,%lo(strNL),%o0
! MAIN EXIT...
! mainExit
ret
restore