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
/
array2.out.bak
< prev
next >
Wrap
Text File
|
2006-03-05
|
7KB
|
366 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
str3: .asciz "Should print -7654..."
str2: .asciz "Should print -7654..."
str1: .asciz "Should print -7654..."
.align 8
! MAIN...
! mainEntry
.global main
main: save %sp,-144,%sp
set display0,%o0
st %fp,[%o0]
! VAR INITIALIZATION...
! a := 0
set 0,%o0
st %o0,[%fp+-4]
! VAR INITIALIZATION...
! i := 0
set 0,%o0
st %o0,[%fp+-8]
! ASSIGNMENT STMT...
! t1 := 0
set 0,%o0
st %o0,[%fp+-12]
! if 100 <= 0 goto runtimeError5 (integer)
set 100,%o0
set 0,%o1
cmp %o0,%o1
ble runtimeError5
nop
! t1 := t1 + 100 (integer)
ld [%fp+-12],%o0
set 100,%o1
add %o0,%o1,%o1
st %o1,[%fp+-12]
! t2 := - 7654 (integer)
set 7654,%o0
neg %o0,%o1
st %o1,[%fp+-16]
! t3 := t1 * 4 (integer)
ld [%fp+-12],%o0
set 4,%o1
smul %o0,%o1,%o1
st %o1,[%fp+-20]
! t3 := t3 + 4 (integer)
ld [%fp+-20],%o0
set 4,%o1
add %o0,%o1,%o1
st %o1,[%fp+-20]
! t3 := alloc (t3)
set 1,%o0
ld [%fp+-20],%o1
call calloc
nop
st %o0,[%fp+-20]
! if t3 = 0 goto runtimeError1 (integer)
ld [%fp+-20],%o0
set 0,%o1
cmp %o0,%o1
be runtimeError1
nop
! t4 := t3
ld [%fp+-20],%o0
st %o0,[%fp+-24]
! *t3 := t1
ld [%fp+-12],%o0
ld [%fp+-20],%o1
st %o0,[%o1]
! t5 := 100
set 100,%o0
st %o0,[%fp+-28]
! Label_1:
Label_1:
! t3 := t3 + 4 (integer)
ld [%fp+-20],%o0
set 4,%o1
add %o0,%o1,%o1
st %o1,[%fp+-20]
! *t3 := t2
ld [%fp+-16],%o0
ld [%fp+-20],%o1
st %o0,[%o1]
! t5 := t5 - 1 (integer)
ld [%fp+-28],%o0
set 1,%o1
sub %o0,%o1,%o1
st %o1,[%fp+-28]
! if t5 > 0 goto Label_1 (integer)
ld [%fp+-28],%o0
set 0,%o1
cmp %o0,%o1
bg Label_1
nop
! a := t4
ld [%fp+-24],%o0
st %o0,[%fp+-4]
! WRITE STMT...
! writeString str1
sethi %hi(str1),%o0
call printf
or %o0,%lo(str1),%o0
! if a = 0 goto runtimeError2 (integer)
ld [%fp+-4],%o0
set 0,%o1
cmp %o0,%o1
be runtimeError2
nop
! if 0 < 0 goto runtimeError4 (integer)
set 0,%o0
set 0,%o1
cmp %o0,%o1
bl runtimeError4
nop
! t6 := *a
ld [%fp+-4],%o0
ld [%o0],%o0
st %o0,[%fp+-32]
! if 0 >= t6 goto runtimeError4 (integer)
set 0,%o0
ld [%fp+-32],%o1
cmp %o0,%o1
bge runtimeError4
nop
! t6 := 0 * 4 (integer)
set 0,%o0
set 4,%o1
smul %o0,%o1,%o1
st %o1,[%fp+-32]
! t6 := t6 + 4 (integer)
ld [%fp+-32],%o0
set 4,%o1
add %o0,%o1,%o1
st %o1,[%fp+-32]
! t6 := a + t6 (integer)
ld [%fp+-4],%o0
ld [%fp+-32],%o1
add %o0,%o1,%o1
st %o1,[%fp+-32]
! t7 := *t6
ld [%fp+-32],%o0
ld [%o0],%o0
st %o0,[%fp+-36]
! writeInt t7
ld [%fp+-36],%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 a = 0 goto runtimeError2 (integer)
ld [%fp+-4],%o0
set 0,%o1
cmp %o0,%o1
be runtimeError2
nop
! if 50 < 0 goto runtimeError4 (integer)
set 50,%o0
set 0,%o1
cmp %o0,%o1
bl runtimeError4
nop
! t8 := *a
ld [%fp+-4],%o0
ld [%o0],%o0
st %o0,[%fp+-40]
! if 50 >= t8 goto runtimeError4 (integer)
set 50,%o0
ld [%fp+-40],%o1
cmp %o0,%o1
bge runtimeError4
nop
! t8 := 50 * 4 (integer)
set 50,%o0
set 4,%o1
smul %o0,%o1,%o1
st %o1,[%fp+-40]
! t8 := t8 + 4 (integer)
ld [%fp+-40],%o0
set 4,%o1
add %o0,%o1,%o1
st %o1,[%fp+-40]
! t8 := a + t8 (integer)
ld [%fp+-4],%o0
ld [%fp+-40],%o1
add %o0,%o1,%o1
st %o1,[%fp+-40]
! t9 := *t8
ld [%fp+-40],%o0
ld [%o0],%o0
st %o0,[%fp+-44]
! writeInt t9
ld [%fp+-44],%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
! if a = 0 goto runtimeError2 (integer)
ld [%fp+-4],%o0
set 0,%o1
cmp %o0,%o1
be runtimeError2
nop
! if 99 < 0 goto runtimeError4 (integer)
set 99,%o0
set 0,%o1
cmp %o0,%o1
bl runtimeError4
nop
! t10 := *a
ld [%fp+-4],%o0
ld [%o0],%o0
st %o0,[%fp+-48]
! if 99 >= t10 goto runtimeError4 (integer)
set 99,%o0
ld [%fp+-48],%o1
cmp %o0,%o1
bge runtimeError4
nop
! t10 := 99 * 4 (integer)
set 99,%o0
set 4,%o1
smul %o0,%o1,%o1
st %o1,[%fp+-48]
! t10 := t10 + 4 (integer)
ld [%fp+-48],%o0
set 4,%o1
add %o0,%o1,%o1
st %o1,[%fp+-48]
! t10 := a + t10 (integer)
ld [%fp+-4],%o0
ld [%fp+-48],%o1
add %o0,%o1,%o1
st %o1,[%fp+-48]
! t11 := *t10
ld [%fp+-48],%o0
ld [%o0],%o0
st %o0,[%fp+-52]
! writeInt t11
ld [%fp+-52],%o1
sethi %hi(strInt),%o0
call printf
or %o0,%lo(strInt),%o0
! writeNewline
sethi %hi(strNL),%o0
call printf
or %o0,%lo(strNL),%o0
! MAIN EXIT...
! mainExit
ret
restore