From e6961a69421b3e93bff949ad8731c3eb8045608f Mon Sep 17 00:00:00 2001 From: Spiderpig86 Date: Sun, 5 Aug 2018 15:25:44 -0400 Subject: feat(mips.html.markdown): Added examples of using loops in MIPS --- mips.html.markdown | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/mips.html.markdown b/mips.html.markdown index 418761bf..27a11e2f 100644 --- a/mips.html.markdown +++ b/mips.html.markdown @@ -198,4 +198,34 @@ hello_world .asciiz "Hello World\n" # Declare a null terminated string done: # End of program +## LOOPS ## + _loops: + # The basic structure of loops is having an exit condition and a jump instruction to continue its execution + li $t0, 0 + while: + bgt $t0, 10, end_while # While $t0 is less than 10, keep iterating + addi $t0, $t0, 1 # Increment the value + j while # Jump back to the beginning of the loop + end_while: + + # 2D Matrix Traversal + # Assume that $a0 stores the address of an integer matrix which is 3 x 3 + li $t0, 0 # Counter for i + li $t1, 0 # Counter for j + matrix_row: + bgt $t0, 3, matrix_row_end + + matrix_col: + bgt $t1, 3, matrix_col_end + + # Do stuff + + addi $t1, $t1, 1 # Increment the col counter + matrix_col_end: + + # Do stuff + + addi $t0, $t0, 1 + matrix_row_end: + ``` -- cgit v1.2.3