Question: Consider the recursion example distributed on Feb. 2 0 : TITLE Tree demo with traversal USE hawk.h USE stdio.h ; displacements into the
Consider the recursion example distributed on Feb. :
TITLE "Tree demo with traversal"
USE "hawk.h
USE "stdio.h
; displacements into the record structure of a tree node
LEFT ; children
RIGHT
VALUE ; integer value of this node
NODESIZE
; tool for statically construct tree nodes
MACRO TREENODE left,right,value
W left
W right
W value
ENDMAC
; a tree to traverse
N: TREENODE NULL,NULL,
N: TREENODE NNULL,
N: TREENODE NN
N: TREENODE NULL,NULL,
N: TREENODE NN
N: TREENODE NULL,NULL,
ROOT N
SUBTITLE "traverse recursive tree traversal"
; traverse root does an inorder traversal, printing each node's value
; AR for traverse
RETAD
NODE
ARSIZE
TRAVERSE:
; expects: r root tree or subtree to traverse
STORES RR
STORE RRNODE ; node parameter
ADDSI RARSIZE
TESTR R
BZS TRAVQT ; if node null
LOAD RRLEFT ; parameter
JSR RTRAVERSE ; traverse nodeleft
LOAD RRNODEARSIZE
LOAD RRVALUE ; parameter
LIS R ; parameter
LIL RPUTDEC
JSRS RR ; putdec nodevalue,
LOAD RRNODEARSIZE
LOAD RRRIGHT ; parameter
JSR RTRAVERSE ; traverse noderight
TRAVQT: ;
ADDSI RARSIZE
LOADS PCR
SUBTITLE "main program"
INT MAIN
S MAIN
; AR for main
RETAD
ARSIZE
MAIN:
STORES RR
ADDSI RARSIZE
LEA RROOT ; param
JSR RTRAVERSE ; call traverse root
ADDSI RARSIZE
LOADS PCR
END
The code LOAD RRRIGHT could have been replaced with
A LIL RRIGHT
LOADS RR
B LEA RRIGHT
LOADS RR
C LEA RRRIGHT
D ADDSI RRIGHT
LOADS RR
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
