Browse Source

added mips cheatsheet

Marius Schwarz 5 years ago
parent
commit
b9d98a1f6a
1 changed files with 50 additions and 0 deletions
  1. 50 0
      cheatsheets/embedded/mips_asm.md

+ 50 - 0
cheatsheets/embedded/mips_asm.md

@@ -0,0 +1,50 @@
+# Mips Assembly Basics
+
+## Registers
+
+* $v0       -> Return value
+* $v0       -> Syscall number
+* $a0-$a3   -> Arguments
+* $sp       -> Stack pointer
+* $gp       -> Global pointer
+* $fp       -> Frame pointer
+* $ra       -> Return addr. in a subroutine call
+* $pc       -> Process counter
+
+
+## Instruction Reference
+
+```
+# Loading and Storing
+
+la $reg, 0xdeadbeef     ; load address
+li $reg, 5              ; load integer
+lw $reg, 0xdeadbeef     ; load word
+lb $reg, 0xAA           ; load byte
+sw $reg, <mem>          ; store word from $reg into <mem-address>
+
+# Maths
+add $t2, $t0, $t1       ; $t2 = $t0 + $t1
+sub $t2, $t0, $t1       ; $t2 = $t0 - $t1
+mul $t2, $t0, $t1       ; $t2 = $t0 * $t1
+div $t2, $t0, $t1       ; $t2 = $t0 / $t1 (Might not be
+
+
+# Branching
+
+beq $t0, $t1, $reg_eq   ; branches to $reg_qa if $t0 == $t1
+bne $t0, $t1, $reg_eq   ; branches to $reg_qa if $t0 != $t1
+ble $s0, $s1, $target   ; branches to $targe if $s0 < $s1
+
+b <branch_target>       ; unconditional branch
+j <label>               ; jump to <label>
+jal <label>             ; call subroutine @ <label> (jump-and-link)
+jarl $t9                ; calls the subroutine from register
+jr                      ; jump return
+
+move $v0, $s2           ; move $s2 into $v0
+
+
+lw $ra, ($sp)           ; dereferences $sp and stores it in $ra
+
+```