Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; save $1, $2, $3, and other used registers
- ; load array in $1, load 0 in $1
- ; next instruction will go into a call to getheight
- ; getheight($1, $2) -> $3
- ; $1 is the array
- ; $2 is the index of the current node we are at
- ; $3 is the register to return the height in
- ; set return point to end:
- getheight:
- ; if cur node is -1, load 0 into $3 and return
- ; save all other registers (not $1, $2, $3) used below
- ; read array and load index of left node into $2
- ; call getheight
- ; upon returning, $3 now has height of left, save left height in another reg
- ; read array and load index of right node into $2
- ; call getheight
- ; upon returning, $3 now has height of right, save right height in another reg
- ; compare left and right and save the bigger one in one of the reg
- ; add 1 to it
- ; restore all other registers (not $1, $2, $3) saved above
- ; return
- end:
- ; restore $1, $2, $3, and other used registers
- ; return
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement