Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2020
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ; save $1, $2, $3, and other used registers
  2.  
  3. ; load array in $1, load 0 in $1
  4. ; next instruction will go into a call to getheight
  5.  
  6. ; getheight($1, $2) -> $3
  7. ; $1 is the array
  8. ; $2 is the index of the current node we are at
  9. ; $3 is the register to return the height in
  10. ; set return point to end:
  11.  
  12. getheight:
  13.  ; if cur node is -1, load 0 into $3 and return
  14.  
  15.   ; save all other registers (not $1, $2, $3) used below
  16.  
  17.   ; read array and load index of left node into $2
  18.  ; call getheight
  19.  ; upon returning, $3 now has height of left, save left height in another reg
  20.  
  21.   ; read array and load index of right node into $2
  22.  ; call getheight
  23.  ; upon returning, $3 now has height of right, save right height in another reg
  24.  
  25.   ; compare left and right and save the bigger one in one of the reg
  26.  ; add 1 to it
  27.  
  28.   ; restore all other registers (not $1, $2, $3) saved above
  29.  ; return
  30.  
  31. end:
  32.  ; restore $1, $2, $3, and other used registers
  33.  ; return
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement