Search a binary tree in MIPS, really need assistance, -


i need search binary tree in mips term project. code have so. had grad student type don't know how is, far :

text    .globl __start __start:  la $a0, tree li $a1, 0 jal search  jal print_path  li $v0, 10 syscall    store_path: mul $t0, $a1 4 sw $a0, path($t0) addi $t0, $t0, 4 sw $a0, path($t0) jr $ra   print_path: li $t0, 0 mul $t1, $t0, 4 lw $a0, path($t1)    next:   li $v0,4     syscall addi $t0, $t0, 1 #i++ mul $t1, $t0, 4 lw $a0, path($t1) beqz $a0, done move $t1, $a0 la $a0, arrow li $v0, 4 syscall move $a0, $t1 b next  done:   la $a0, endl li $v0, 4 syscall jr $ra   #---------------------------------------- code need goes here.  search: j store_path   jr $ra     #---------------------------------------- /code          .data  path: .space 40  tree:   .word name0, node1, node2, 0 node1:  .word name1, node3, node4, 0 node2:  .word name2, node5, node6, 0 node3:  .word name3, node7, 0, 0 node4:  .word name4, node8, node9, 0 node5:  .word name5, 0, 0, 0 node6:  .word name6, node10, node11, 0 node7:  .word name7, 0, 0, 0 node8:  .word name8, 0, 0, 0 node9:  .word name9, node12, node13, 0 node10: .word name10, 0, 0, 0 node11: .word name11, 0, 0, 0 node12: .word name12, node14, node15, 0 node13: .word name13, 0, 0, 0 node14: .word name14, 0, 0, 1 node15: .word name15, node16, node17, 0 node16: .word name16, 0, 0, 0 node17: .word name17, 0, 0, 0    name0: .asciiz "apple" name1: .asciiz "orange" name2: .asciiz "banana" name3: .asciiz "pear" name4: .asciiz "plum" name5: .asciiz "peach" name6: .asciiz "nectarine" name7: .asciiz "pineapple" name8: .asciiz "grapefruit" name9: .asciiz "grape" name10: .asciiz "melon" name11: .asciiz "avacado" name12: .asciiz "star" name13: .asciiz "mange" name14: .asciiz "passion" name15: .asciiz "cantaloupe" name16: .asciiz "watermelon" name17: .asciiz "apricot"   endl: .asciiz "\n" arrow: .asciiz "-->" 

he gave pseudo code try , work :

     call store_path     if(value == 1)  //not sure value i'm guessing ether $a0 or $a1      return 1        if(left tree exists)      if(search(left tree, depth+1)     return 1     if(right tree exists)    return search(right tree, depth +1)    return 0 

hes never taught how return or if statements. know jal , jr $ra work return not sure how return 1, or or return search , thing i've been able if statement stuff far break statements last time got marked wrong him. asked him , said in book, don't have because costs $800, out of print, when class started , cannot afford that.

could help? have no idea need do, suck @ mips.


Comments

Popular posts from this blog

php - Why I am getting the Error "Commands out of sync; you can't run this command now" -

linux - Does gcc have any options to add version info in ELF binary file? -

java - Are there any classes that implement javax.persistence.Parameter<T>? -