summaryrefslogtreecommitdiffhomepage
path: root/mips.html.markdown
diff options
context:
space:
mode:
authorBoris Verkhovskiy <boris.verk@gmail.com>2024-04-04 04:26:14 -0700
committerGitHub <noreply@github.com>2024-04-04 04:26:14 -0700
commit4d59048f0df8441e5ad2c2c440e8d54b0e9c11b6 (patch)
treefa2dbdd40da35b3c27f928f1112ea43193a7482e /mips.html.markdown
parentb38d4437120e700646a45dff68b7c4ff3f7109c0 (diff)
parent327001f58739489b41f6b1f7bbc8be900847b381 (diff)
Merge branch 'master' into patch-2
Diffstat (limited to 'mips.html.markdown')
-rw-r--r--mips.html.markdown16
1 files changed, 9 insertions, 7 deletions
diff --git a/mips.html.markdown b/mips.html.markdown
index 33d4f87c..3add0c5b 100644
--- a/mips.html.markdown
+++ b/mips.html.markdown
@@ -111,7 +111,7 @@ gateways and routers.
sub $t2, $t0, $t1 # $t2 = $t0 - $t1
mul $t2, $t0, $t1 # $t2 = $t0 * $t1
div $t2, $t0, $t1 # $t2 = $t0 / $t1 (Might not be
- # supported in some versons of MARS)
+ # supported in some versions of MARS)
div $t0, $t1 # Performs $t0 / $t1. Get the
# quotient using 'mflo' and
# remainder using 'mfhi'
@@ -162,7 +162,7 @@ gateways and routers.
blt $t0, $t1, t0_gt_t1 # Branches when $t0 < $t1
ble $t0, $t1, t0_gte_t1 # Branches when $t0 <= $t1
bltz $t0, t0_lt0 # Branches when $t0 < 0
- slt $s0, $t0, $t1 # Instruction that sends a signal
+ slt $s0, $t0, $t1 # "Set on Less Than"
# when $t0 < $t1 with result in $s0
# (1 for true)
@@ -186,6 +186,7 @@ gateways and routers.
# else
# max = c;
# else
+ # if (b > c)
# max = b;
# else
# max = c;
@@ -193,7 +194,7 @@ gateways and routers.
# Let $s0 = a, $s1 = b, $s2 = c, $v0 = return register
ble $s0, $s1, a_LTE_b # if(a <= b) branch(a_LTE_b)
ble $s0, $s2, max_C # if(a > b && a <=c) branch(max_C)
- move $v0, $s1 # else [a > b && a > c] max = a
+ move $v0, $s0 # else [a > b && a > c] max = a
j done # Jump to the end of the program
a_LTE_b: # Label for when a <= b
@@ -212,8 +213,9 @@ gateways and routers.
# instruction to continue its execution
li $t0, 0
while:
- bgt $t0, 10, end_while # While $t0 is less than 10,
+ bgt $t0, 9, end_while # While $t0 is less than 10,
# keep iterating
+ #actual loop content would go here
addi $t0, $t0, 1 # Increment the value
j while # Jump back to the beginning of
# the loop
@@ -242,7 +244,7 @@ gateways and routers.
## FUNCTIONS ##
_functions:
# Functions are callable procedures that can accept arguments and return
- values all denoted with labels, like above
+ # values all denoted with labels, like above
main: # Programs begin with main func
jal return_1 # jal will store the current PC in $ra
@@ -293,7 +295,7 @@ gateways and routers.
fact_done:
lw $s0, ($sp)
- lw $ra, ($sp) # Restore the PC
+ lw $ra, 4($sp) # Restore the PC
addi $sp, $sp, 8
jr $ra
@@ -357,7 +359,7 @@ gateways and routers.
li $t1, 5 # Length of the list
loop:
- bgt $t0, $t1, end_loop
+ bge $t0, $t1, end_loop
lw $a0, ($s0)
li $v0, 1