Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #<------------------ MACRO DEFINITIONS ---------------------->#
- # Macro : print_str
- # Usage: print_str(<address of the string>)
- .macro print_str($arg)
- li $v0, 4 # System call code for print_str
- la $a0, $arg # Address of the string to print
- syscall # Print the string
- .end_macro
- # Macro : print_int
- # Usage: print_int(<val>)
- .macro print_int($arg)
- li $v0, 1 # System call code for print_int
- li $a0, $arg # Integer to print
- syscall # Print the integer
- .end_macro
- .macro read_int($reg)
- li $v0, 5
- syscall
- move $reg, $v0
- .end_macro
- .macro print_reg_int($reg)
- li $v0, 1
- move $a0, $reg
- syscall
- .end_macro
- .macro swap_hi_lo($temp1,$temp2)
- mthi $temp1 #Set address of $temp1 to address of value stored in Hi
- mtlo $temp2 #Set address of $temp2 to address of value stored in Lo
- move $t0, $temp1 #Move $temp1 to a temporary address for manipulation
- move $t1, $temp2 #Move $temp2 to a temporary address for manipulation
- mfhi $t1 #Swap value of Hi with our Lo value
- mflo $t0 #Swap value of Lo value with our Hi value
- syscall
- .end_macro
- .macro print_hi_lo($strHi, $strEqual, $strComma, $strLo)
- li $v0, 4
- la $a0, $strHi #Address of the string to print
- syscall
- li $v0, 4
- la $a0, $strEqual #Address of the string to print
- syscall
- li $v0,1
- mfhi $t1
- mflo $t0
- add $a0,$t1,$zero
- syscall
- li $v0, 4
- la $a0, $strComma #Address of the string to print
- syscall
- li $v0, 4
- la $a0, $strLo
- syscall
- li $v0, 4
- la $a0, $strEqual
- syscall
- li $v0, 1
- add $a0, $t0,$zero
- syscall
- .end_macro
- .macro lwi($reg,$ui,$li)
- lui $reg, $ui
- ori $reg, $reg, $li
- .end_macro
- .macro push($reg)
- sub $sp,$sp,4
- sw $reg,0($sp)
- .end_macro
- .macro pop($reg)
- lw $reg,0($sp)
- addi $sp,$sp,4
- .end_macro
- la $a0, 4
- li $v0, 4
- syscall
- li $v0, 5
- syscall
- move $s0, $v0
- move $t1, $v0
- li $t0, 1
- loop:
- mul $t0, $t0, $s0
- addi $s0, $s0, -1
- bgtz $s0, loop
- li $v0, 1
- move $a0, $t0
- syscall
- li $v0, 10
- syscall
- .macro exit
- li $v0, 10
- syscall
- .end_macro
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement