Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- lis $5 ; current height
- .word 0
- lis $3 ; the max
- .word 0
- lis $4
- .word 4
- lis $7
- .word -1
- lis $8
- .word 1
- lis $10
- .word 0
- lis $15
- .word getheight
- add $12, $0, $1 ; set $12 to the starting memory location of the array
- getheight: ; $10 is used to hold the desired array INDEX, $11-13 are used to hold
- sw $31, -4($30) ; store current return address
- sub $30, $30, $4
- sw $12, -4($30) ; store current array memory location
- sub $30, $30, $4
- add $5, $5, $8 ; update height
- add $12, $12, $4 ; update array index to the left child
- lw $10, 0($12) ;
- beq $10, $7, leftDone ; if leftChild != -1, then recursively call
- mult $10, $4
- mflo $11
- add $12, $11, $1 ; update $12 to the memory address of the new node
- jalr $15 ; copies $ to program counter, copies previous program counter to $31
- lw $12, 0($30)
- add $12, $12, $4 ; revert $12 back to the left child's memory location
- leftDone:
- add $12, $12, $4 ;
- lw $10, 0($12) ;
- beq $10, $7, rightDone
- mult $10, $4
- mflo $11
- add $12, $11, $1 ; update $12 to the memory address of the new node
- jalr $15
- rightDone:
- slt $16, $3, $5 ; updates maximum height
- bne $16, $8, done
- add $3, $5, $0
- done:
- add $5, $5, $7 ; decrement the height
- lw $12, 0($30)
- add $30, $30, $4
- lw $31, 0($30)
- add $30, $30, $4
- jr $31
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement