Guest User

Untitled

a guest
Dec 11th, 2018
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.88 KB | None | 0 0
  1. #include <iregdef.h>
  2. .data
  3. .align 2
  4. .globl Test
  5. Test:
  6. .word 1
  7. .word 3
  8. .word 5
  9. .word 7
  10. .word 9
  11. .word 8
  12. .word 6
  13. .word 4
  14. .word 2
  15. .word 0
  16. TextA: .asciiz "Lab, Question 1\n"
  17. TextB: .asciiz "LThe max is %d\n"
  18. TextC: .asciiz "Done\n"
  19. .text
  20. .align 2
  21. .globl FindMax
  22. .ent FindMax
  23. FindMax:
  24. subu sp,sp,8 #Reserve a new 8 byte stack frame
  25. sw s0,0(sp) #save value of s0 on the stacj
  26. sw s1, 4(sp) #save value of s1 on the stack
  27. sw s2, 8(sp) # Save value of s2 on the stack
  28. sw t1, 12(sp) # Save value of t1 on the stack
  29. sw t2, 16(sp) # Save value of t2 on the stack
  30. addi s0, zero, 9
  31. add s1, zero, zero
  32. lw v0, 0(a0)
  33. for:
  34. srl s2, s1, 2
  35. slt s2, s2, s0
  36. beq s2, zero, endfor
  37. addi s1, s1, 4
  38. add t1, s1, a0
  39. lw t2, 0(t1)
  40. slt s2, v0, t2
  41. beq s2, zero, for
  42. nop
  43. lw v0, 0(t1)
  44. b for
  45. nop
  46.  
  47. endfor:
  48. lw t2, 16(sp) # Restore old value of t2
  49. lw t1, 12(sp) # Restore old value of t1
  50. lw s2, 8(sp) # Restore old value of s2
  51. lw s1, 4(sp) #restore old vlue of s1
  52. lw s0, 0(sp) #Restore old value of s0
  53. addu sp, sp, 8 #Jump back to calling routine
  54. jr ra # Jump back to calling routine
  55. .end FindMax
  56.  
  57. .text
  58. .align 2
  59. .globl start
  60. .ent start
  61. start:
  62. subu sp,sp,32 #Reserve a new 32 byte stack frame
  63. sw ra, 20(sp) #Save old value of retunr address
  64. sw fp, 16(sp) #Save old value of frame pointer
  65. addu fp, sp, 28 #Set up new frame pointer
  66. la a0, TextA #Load address to welcome text
  67. jal printf #Call printf to print welcome text
  68. la a0, Test #Load address to vector
  69. jal FindMax #Call FindMax subroutin
  70. la a0, TextB #Load address to result text
  71. move a1, v0 #Movee result to second register
  72. jal printf #Call printf to print result text
  73. la a0, TextC #Load address to goodbye text
  74. jal printf #Call printf to print goodbye text
  75. lw fp, 16(sp) #Restore old frame pointer
  76. lw ra, 20(sp) #restor old return address
  77. addu sp, sp, 32 #Pop stack frame
  78. j _exit #jump to exit routine
  79. .end start
Add Comment
Please, Sign In to add comment