;;	mysine function and a main program for testing
;;	Minas Spetsakis, Oct. 2022

	ORG 64
ARG1:	DF 0.52360			;; -> 0.5
ARG2:	DF 0.78540			;; -> 0.70711

	fld     f10, ARG1(x0)   ; Put arg in f10
	jal	ra, mysine
	ecall   x0, f10, 1
        ebreak  x0, x0, 0

;;	x5:	i
;;	x6:	imax (10)
;;	f3:	(double) i
;;	f4:	(double) i+1
;;	f5:	(double) i*(i+1)


mysine:
	addi    x6, x0, 10 ; imax = 10
	addi    x5, x0, 2        ; i=2
	fsgnj.d	f1, f10, f10
	fsgnj.d	f2, f10, f10

forloop:
        fcvt.d.l f3, x5
	addi	x5, x5, 1
	fcvt.d.l f4, x5
	fmul.d	f0, f10, f10
	fmul.d	f5, f3, f4
	fdiv.d	f0, f0, f5
	fsgnjn.d	f5, f0, f0
	fmul.d	f2, f2, f5
	fadd.d	f1, f1, f2
	addi	x5, x5, 1
	blt	x5, x6, forloop
	fsgnj.d	f10, f1, f1
	jalr	x0, 0(ra)

	ebreak	x0, x0, 0
