		.text
		.align  2
		.globl  _start

_start:
		addi a0, zero, 20
		jal ra, squares		
		nop
		nop
		nop
		add s0, zero, zero
		addi s1, zero, 20
		nop
		nop
loop_load:
		addi s0, s0, 1
		nop
		nop
		slli t0, s0, 2
		nop
		nop
		lw s2, 16(t0)
		nop
		blt s0, s1, loop_load
		nop
		nop
		nop
infty_loop:
	jal zero, infty_loop
	nop
	nop
	nop


squares:
	add s0, zero, zero
	add  s1, zero, a0
	sw ra, 16(x0)
	nop
loop:
	addi s0, s0, 1
	nop
	nop
	add a0, zero, s0
	add a1, zero, s0
	nop
	nop
	jal ra, fast_multiply
	nop
	nop
	nop
	slli t0, s0, 2
	nop
	nop
	sw a0, 16(t0)
	blt s0, s1, loop
exit:
	lw ra, 16(x0)
	nop
	nop
	jalr x0, ra, 4
	nop
	nop
	nop
	

fast_multiply:
   add  t0, zero, zero      # to keep track of result
   
next_digit:
   andi t1, a1, 1           # is rightmost bit 1?
   srai a1, a1, 1
   nop
   nop
   
   beq  t1, zero, skip      # if right most bit 0, don't add
   nop
   nop
   nop

   add  t0, t0, a0
skip:
   slli a0, a0, 1           # double first argument
   bne  a1, zero, next_digit
   nop
   nop
   nop
   add  a0, zero, t0        # move accum result to a0
   jalr x0, ra, 8
   nop
   nop
   nop




		.end _start
		.size _start, .-_start
