diff options
author | Spiderpig86 <slim679975@gmail.com> | 2018-08-07 21:48:42 -0400 |
---|---|---|
committer | Spiderpig86 <slim679975@gmail.com> | 2018-08-07 21:48:42 -0400 |
commit | ffff6d9bb31efd2b47bedc9ee07cd68b50c12f47 (patch) | |
tree | 2c4c276c4e1783ccc54980b7d79d7f17f54fa648 /mips.html.markdown | |
parent | 9d908ebb4a0b1dd52084333581c3021b8916eace (diff) |
feat(mips.html.markdown): Added examples of macros
Diffstat (limited to 'mips.html.markdown')
-rw-r--r-- | mips.html.markdown | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/mips.html.markdown b/mips.html.markdown index 9b176842..e56c9fce 100644 --- a/mips.html.markdown +++ b/mips.html.markdown @@ -287,5 +287,47 @@ hello_world .asciiz "Hello World\n" # Declare a null terminated string jr $ra +## MACROS ## + _macros: + # Macros are extremly useful for substituting repeated code blocks with a + # single label for better readability + # These are in no means substitutes for functions + # These must be declared before it is used + + # Macro for printing new lines (since these can be very repetitive) + .macro println() + la $a0, newline # New line string stored here + li $v0, 4 + syscall + .end_macro + + println() # Assembler will copy that block of + # code here before running + + # Parameters can be passed in through macros. + # These are denoted by a '%' sign with any name you choose + .macro print_int(%num) + li $v0, 1 + lw $a0, %num + syscall + .end_macro + + li $t0, 1 + print_int($t0) + + # We can also pass in immediates for macros + .macro immediates(%a, %b) + add $t0, %a, %b + .end_macro + + immediates(3, 5) + + # Along with passing in labels + .macro print(%string) + la $a0, %string + li $v0, 4 + syscall + .end_macro + print(hello_world) ``` |