summaryrefslogtreecommitdiffhomepage
path: root/mips.html.markdown
diff options
context:
space:
mode:
authorSpiderpig86 <slim679975@gmail.com>2018-08-05 15:25:44 -0400
committerSpiderpig86 <slim679975@gmail.com>2018-08-05 15:25:44 -0400
commite6961a69421b3e93bff949ad8731c3eb8045608f (patch)
tree5f0b40b74c04ebcf0d7671a27766102ae169c22e /mips.html.markdown
parent81f9f0fec80b3c459937dd59be8384433251e3f8 (diff)
feat(mips.html.markdown): Added examples of using loops in MIPS
Diffstat (limited to 'mips.html.markdown')
-rw-r--r--mips.html.markdown30
1 files changed, 30 insertions, 0 deletions
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:
+
```