わかりましたので、アセンブリでバイナリ ツリーの高さを再帰的に計算しようとしていますが、正しい数値を取得するのに苦労しています。私のコードは現在、ツリーを調べており、それ以上何もしていません。なぜなら、そこから得られたのは左右の葉の数を数えることだけだったからです。誰かがこれで私を助けてくれますか? 私のコードは完全に間違っていますか、それとも高さを計算するためにいくつかの行を追加するだけでよいですか? どんな助けでも大歓迎です。
ps: コメントは気にしないでください。コメントはイタリア語です。
EDIT:英語のコメントで改善されたコードの種類
.data
radice:.word 17, node1, node2
node1:.word 5, node3, 0
node2:.word 8, node4, node5
node3:.word 1, node6, node7
node4:.word 2, 0, 0
node5:.word 3, 0, node8
node6:.word 5, 0, 0
node7:.word 12, 0, node9
node8:.word 6, 0, 0
node9:.word 2, 0, 0
.text
main:
la $s0, radice #first node
jal recursive
recursive:
addi $sp, $sp, -8 #making space in the stack
sw $ra, 0($sp) #save ra
beqz $s0, null #Does this node exist?
sw $s0, 4($sp) #If it does, save it in the stack
lw $s1, 0($s0) ####Display wich node is currently being examined#####
li $t9, 0 #Control
li $a3, 0 #Left height
li $a2, 0 #Right height
j left #Examine left child of this node
null:
beq $t9, 1, nullL #If this control is set to 1, this was a left child
li $a2, 0 #Right height is 0
lw $ra, 0($sp) #load ra from stack
addi $sp, $sp, 8 #clear stack
jr $ra #jump to ra
nullL:
li $a3, 0 #Left height is 0
la $s0, 4($sp) #load father address from stack
lw $s2, 0($s0) ####Display who is the father####
lw $ra, 0($sp) #load ra
addi $sp, $sp, 8 #clear stack
jr $ra #jump to ra
left:
li $t9, 1 #set control to 1
lw $s0, 4($s0) #load left child of this node
jal recursive #start recursion
right:
lw $s0, 8($s0) #load right child of this node
jal recursive # start recursion
j right #Don't know if this will be useful