; File icassp2k.asm
; generated by the Basic DSP compiler Ver 0.10
; 1999/9/29, 18:20:31.31

; standard program header for the C31 DSK
	.start ".text", 0x809802 ; RAM block 0
	.start ".data", 0x809C00 ; RAM block 1
ten	.set	10	; const ten 10

length	.set	10	; const length 10

; start of the data section
	.data
y	.float	5	; var  y  float 5
y1	.float	17	; var ~y1 float 17
j	.word	0	; var  j  int
primes	.word	2,3,5,7,11	; var primes        int       2,3,5,7,11
signalsegment	; var signalsegment float(75)
	.loop	75
	.float	0
	.endloop
realarray	.float	0,1,2,3,4,5,6	; var realarray    float 0,1,2,3,4,5,6
scannedvalue	.float	0	; var scannedvalue float
mysubroutinesrda	.float	0, 0	; var mysubroutinesrda float 0, 0
mysub2srda	.float	0, 0	; var mysub2srda float 0, 0
rightlabel	.word	0	; var rightlabel int 0
rightsub	.word	0, 0	; var rightsub   int 0, 0

; start of the data address section
_pbase	.word	0x808000 ; memory mapped registers
_y	.word	y	; address of y
_j	.word	j	; address of j
_primes	.word	primes	; address of primes
_signalsegment	.word	signalsegment	; address of signalsegment
_realarray	.word	realarray	; address of realarray
_scannedvalue	.word	scannedvalue	; address of scannedvalue
_mysubroutinesrda	.word	mysubroutinesrda	; address of mysubroutinesrda
_mysub2srda	.word	mysub2srda	; address of mysub2srda
_rightlabel	.word	rightlabel	; address of rightlabel
_rightsub	.word	rightsub	; address of rightsub
_goodplace	.word	goodplace	; address of goodplace
_mysub2	.word	mysub2	; address of mysub2

_stack	.word stack	; address of stack
stack	.word $		; beginning of the stack
; end of the data section

; start of the program section
	.entry BEGIN
	.text
BEGIN	ldp	@.data     ; init the data page
	ldi	@stack, sp ; init the stack pointer
main	; :main
	ldi	@_y, AR1	; y=length
	ldf	length, R0
	stf	R0, *AR1

	ldi	@_y, AR1	; y*=1.5
	ldf	1.5, R0
	mpyf3	R0,*AR1, R0
	stf	R0, *AR1

	ldf	6, R4	; x0=6

	ldi	@_j, AR1	; j+=1
	ldi	1, R0
	addi3	R0, *AR1, R0
	sti	R0, *AR1

	ldf	R4, R0	; y(j)+=x0+y
	ldi	@_y, AR1
	ldf	*AR1, R1
	addf3	R1, R0, R0
	ldi	@_j, AR2
	ldi	*AR2, IR0
	addf3	R0, *+AR1(IR0), R0
	stf	R0, *+AR1(IR0)

	ldi	@_y, AR1	; x0!=y(1)
	ldi	1, IR0
	ldf	*+AR1(IR0), R0
	absf	R0, R0
	ldf	R0, R4

	ldi	@_realarray, R0	; @scannedvalue=@realarray
	sti	R0, @_scannedvalue

	ldi	@_scannedvalue, AR1	; scannedvalue += 5.6
	ldf	5.6, R0
	addf3	R0,*AR1, R0
	stf	R0, *AR1

	ldi	1, R1	; @scannedvalue+=1
	ldi	@_scannedvalue, R0
	addi	R1, R0
	sti	R0, @_scannedvalue

loopstart	; :loopstart
	ldf	R5, R0	; x0 += x1*x2
	ldf	R6, R1
	mpyf3	R1, R0, R0
	addf3	R0, R4, R0
	ldf	R0, R4

	br	loopstart	; goto loopstart

	ldf	R4, R0	; if x0>y thengoto loopstart
	ldi	@_y, AR1
	ldf	*AR1, R1
	cmpf	R1, R0
	bgt	loopstart

	push	ar0	; gosub mysubroutine
	ldi	@_mysubroutinesrda, ar0
	call	mysubroutine
	pop	ar0

goodplace	; ::goodplace
	ldi	@_goodplace, R0	; rightlabel = @goodplace
	ldi	@_rightlabel, AR1
	sti	R0, *AR1

	ldi	@_mysub2, R0	; rightsub(0) = @mysub2
	ldi	@_rightsub, AR1
	sti	R0, *AR1

	ldi	@_mysub2srda, R0	; rightsub(1) = @mysub2srda
	ldi	@_rightsub, AR1
	ldi	1, IR0
	sti	R0, *+AR1(IR0)

	ldi	@_rightsub, ar1	; gosub rightsub
	ldi	*ar1, r0	; first element is the subroutine address
	push	ar0
	ldi	*+ar1(1), ar0	; second element is the srda address
	callu	r0		; unconditional indirect call
	pop	ar0 

	ldi	@_rightlabel, ar1	; goto rightlabel
	ldi	*ar1, r0	; this element is the address
	bu	r0		; unconditional indirect branch

	br	main	; goto main

mysub2	; ::mysub2
	; fsrda(1)=fsrda(0)*x0
	ldf	*AR0, R0
	ldf	R4, R1
	mpyf3	R1, R0, R0
	ldi	1, IR0
	stf	R0, *+AR0(IR0)

	rets	; return

mysubroutine	; :mysubroutine
	; fsrda(1)=fsrda(0)+x0
	ldf	*AR0, R0
	ldf	R4, R1
	addf3	R1, R0, R0
	ldi	1, IR0
	stf	R0, *+AR0(IR0)

	rets	; return


; this program uses the xint0 interruption
	.start "xint0sect", 0x809FC5
	.sect  "xint0sect"
	br xint0

	.text
xint0	; :xint0
	ldf	2.5, R0	; x0+=2.5
	addf3	R0, R4, R4

	reti	; reti


; end of the program section
	.end
