Advertisement
Guest User

Untitled

a guest
May 21st, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. lis $5 ; current height
  2. .word 0
  3. lis $3 ; the max
  4. .word 0
  5. lis $4
  6. .word 4
  7. lis $7
  8. .word -1
  9. lis $8
  10. .word 1
  11. lis $10
  12. .word 0
  13. lis $15
  14. .word getheight
  15.  
  16. add $12, $0, $1 ; set $12 to the starting memory location of the array
  17.  
  18. getheight: ; $10 is used to hold the desired array INDEX, $11-13 are used to hold
  19.  
  20. sw $31, -4($30) ; store current return address
  21. sub $30, $30, $4
  22. sw $12, -4($30) ; store current array memory location
  23. sub $30, $30, $4
  24.  
  25. add $5, $5, $8 ; update height
  26.  
  27. add $12, $12, $4 ; update array index to the left child
  28. lw $10, 0($12) ;
  29. beq $10, $7, leftDone ; if leftChild != -1, then recursively call
  30. mult $10, $4
  31. mflo $11
  32. add $12, $11, $1 ; update $12 to the memory address of the new node
  33. jalr $15 ; copies $ to program counter, copies previous program counter to $31
  34.  
  35. lw $12, 0($30)
  36. add $12, $12, $4 ; revert $12 back to the left child's memory location
  37.  
  38. leftDone:
  39. add $12, $12, $4 ;
  40. lw $10, 0($12) ;
  41. beq $10, $7, rightDone
  42. mult $10, $4
  43. mflo $11
  44. add $12, $11, $1 ; update $12 to the memory address of the new node
  45. jalr $15
  46.  
  47. rightDone:
  48. slt $16, $3, $5 ; updates maximum height
  49. bne $16, $8, done
  50. add $3, $5, $0
  51.  
  52. done:
  53. add $5, $5, $7 ; decrement the height
  54.  
  55. lw $12, 0($30)
  56. add $30, $30, $4
  57. lw $31, 0($30)
  58. add $30, $30, $4
  59.  
  60. jr $31
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement