
# MIPS assembly program with text and data segment and SPIM i/o
	.text                   # begin of code
	.align  2               # align on word boundary
	.globl  main            # main is global and can be accessed from other files
main:
	li     $t0,0            # clear $t0 - i=0
        li     $t2,0            # clear sum
loop:
	mul    $t1,$t0,$t0      # i * i
        addu   $t2,$t2,$t1      # calculate new sum
        addi   $t0,$t0,1        # i = i + 1
        ble    $t0,100,loop     # if i<=100 return to loop

	la     $a0,str          # address of string to print in $a0
        li     $v0,4            # system call code for print_str SPIM i/o call
        syscall
       
	move   $a0,$t2          # pseudoinstr: move result to $a0
        li     $v0,1            # system call code for print_int
        syscall
	
        jr       $ra            # end of program, return to system

	.data                   # put this to data segment
str:                            # string for printing
	.asciiz   "The sum from 0 .. 100 is "
	

