Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # macro to end program
- .macro done
- li $v0,10
- syscall
- .end_macro
- # print int
- .macro print_int ($addr)
- li $v0, 1
- add $a0, $zero, $addr
- syscall
- .end_macro
- # print char
- .macro print_char ($addr)
- li $v0, 11
- add $a0, $zero, $addr
- syscall
- .end_macro
- # print string from data
- .macro print_str ($str)
- li $v0, 4
- la $a0, $str
- syscall
- .end_macro
- # print string from register
- .macro print_str_addr (%str)
- li $v0, 4
- la $a0, (%str)
- syscall
- .end_macro
- .macro read_char($str, $ind, $sv)
- la $s2, ($str)
- addu $s2,$s2,$ind # $a1 = &str[x]. assumes x is in $s0
- lbu $sv,($s2) # read the character
- .end_macro
- .macro strlen(%str, $addr)
- la $s0 (%str)
- loop:
- lb $s1 0($s0)
- beq $s1 $zero end
- addi $s0 $s0 1
- addi $addr $addr 1
- j loop
- end:
- addi $addr $addr -1
- .end_macro
- # read register and save in register
- .macro read_str($addr)
- li $v0, 8 # take in input
- la $a0, buffer # load byte space into address
- li $a1, 200 # allot the byte space for string
- move $t0, $a0 # save string to t0
- syscall
- .end_macro
- .macro set_char($addr, $chr, $offset)
- sb $chr, buffer($offset)
- .end_macro
- # generic looping mechanism
- # for ($t0, 1, 10, body)
- .macro for (%regIterator, %from, %to, %bodyMacroName)
- add %regIterator, $zero, %from
- Loop:
- %bodyMacroName ()
- add %regIterator, %regIterator, 1
- ble %regIterator, %to, Loop
- .end_macro
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement