Advertisement
Guest User

Untitled

a guest
Oct 18th, 2017
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.40 KB | None | 0 0
  1. #<------------------ MACRO DEFINITIONS ---------------------->#
  2. # Macro : print_str
  3. # Usage: print_str(<address of the string>)
  4. .macro print_str($arg)
  5. li $v0, 4 # System call code for print_str
  6. la $a0, $arg # Address of the string to print
  7. syscall # Print the string
  8. .end_macro
  9.  
  10. # Macro : print_int
  11. # Usage: print_int(<val>)
  12. .macro print_int($arg)
  13. li $v0, 1 # System call code for print_int
  14. li $a0, $arg # Integer to print
  15. syscall # Print the integer
  16. .end_macro
  17.  
  18. .macro read_int($reg)
  19. li $v0, 5
  20. syscall
  21. move $reg, $v0
  22. .end_macro
  23.  
  24. .macro print_reg_int($reg)
  25. li $v0, 1
  26. move $a0, $reg
  27. syscall
  28. .end_macro
  29.  
  30. .macro swap_hi_lo($temp1,$temp2)
  31. mthi $temp1 #Set address of $temp1 to address of value stored in Hi
  32. mtlo $temp2 #Set address of $temp2 to address of value stored in Lo
  33. move $t0, $temp1 #Move $temp1 to a temporary address for manipulation
  34. move $t1, $temp2 #Move $temp2 to a temporary address for manipulation
  35. mfhi $t1 #Swap value of Hi with our Lo value
  36. mflo $t0 #Swap value of Lo value with our Hi value
  37. syscall
  38. .end_macro
  39.  
  40. .macro print_hi_lo($strHi, $strEqual, $strComma, $strLo)
  41. li $v0, 4
  42. la $a0, $strHi #Address of the string to print
  43. syscall
  44. li $v0, 4
  45. la $a0, $strEqual #Address of the string to print
  46. syscall
  47. li $v0,1
  48. mfhi $t1
  49. mflo $t0
  50. add $a0,$t1,$zero
  51. syscall
  52. li $v0, 4
  53. la $a0, $strComma #Address of the string to print
  54. syscall
  55. li $v0, 4
  56. la $a0, $strLo
  57. syscall
  58. li $v0, 4
  59. la $a0, $strEqual
  60. syscall
  61. li $v0, 1
  62. add $a0, $t0,$zero
  63. syscall
  64. .end_macro
  65.  
  66. .macro lwi($reg,$ui,$li)
  67. lui $reg, $ui
  68. ori $reg, $reg, $li
  69. .end_macro
  70.  
  71. .macro push($reg)
  72. sub $sp,$sp,4
  73. sw $reg,0($sp)
  74. .end_macro
  75.  
  76. .macro pop($reg)
  77. lw $reg,0($sp)
  78. addi $sp,$sp,4
  79. .end_macro
  80.  
  81.  
  82. la $a0, 4
  83. li $v0, 4
  84. syscall
  85.  
  86. li $v0, 5
  87. syscall
  88. move $s0, $v0
  89. move $t1, $v0
  90. li $t0, 1
  91. loop:
  92. mul $t0, $t0, $s0
  93.  
  94. addi $s0, $s0, -1
  95. bgtz $s0, loop
  96.  
  97. li $v0, 1
  98. move $a0, $t0
  99. syscall
  100.  
  101. li $v0, 10
  102. syscall
  103.  
  104. .macro exit
  105. li $v0, 10
  106. syscall
  107. .end_macro
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement