#-------------------------------------------
# Loops - For Loops
# Ported by: Noah Gergel
# Last updated: May 11 2020
#-------------------------------------------

.text

# This is our dumby function that the loop appears in.
foo:

    # Some before-the-loop code might appear here.
    # ...

    # Start of for loop.
    addi    t0, zero, 0     # i = 0
    bge     t0, t1, _joinPoint # If i >= n, our condition is false

_forLoop:
    mul     t3, t0, t0      # t3 <- i * i
    add     t2, t2, t3      # total = total + i * i

    # Could add in continue or break statements to the body of the loop.

_forLoopNext:
    # Now we increment i and loop.
    addi    t0, t0, 1       # i = i + 1
    blt     t0, t1, _forLoop # Checking if i < n.

_joinPoint:
    # Code after loop.
    # ...