Posted By

oronm on 07/05/11


Tagged


Versions (?)

BinTreeShow


 / Published in: Assembler
 

  1. TITLE Show
  2. .386
  3. .model flat
  4. include BinTree.inc
  5. extern NodeDWORD:Near
  6. ; BinTreeShow(node)
  7. ; node - Poiner to binary tree
  8. ; The elements are shown in order on screen
  9. .code
  10. BinTreeShow Proc
  11. node=8
  12. push ebp
  13. mov ebp,esp
  14. push esi ;save registers
  15.  
  16. mov esi,node[ebp] ;Pointer to tree
  17.  
  18. cmp esi,0 ;do nothing if empty tree
  19. je Done
  20.  
  21. push BinTreeLeft[esi] ;Show left subtree
  22. call BinTreeShow
  23.  
  24. push esi
  25. call NodeDWORD
  26.  
  27. push BinTreeRight[esi] ;Show right subtree
  28. call BinTreeShow
  29. Done:
  30. pop esi
  31. pop ebp
  32. ret 4
  33. BinTreeShow Endp
  34.  
  35. end TITLE Show
  36. .386
  37. .model flat
  38. include BinTree.inc
  39.  
  40. extern D2Str10:Near
  41. extern StrLen:Near,WriteStr:Near
  42. ; BinTreeShow(node)
  43. ; node - Poiner to binary tree
  44. ; The elements are shown in order on screen
  45. .data
  46. crlf BYTE 13,10
  47. .code
  48. BinTreeShow Proc
  49. node=8
  50. Tmp=-20
  51. locals=-20
  52. push ebp
  53. mov ebp,esp
  54. add esp,locals ;make place for local string
  55. push esi ;save registers
  56.  
  57. mov esi,node[ebp] ;Pointer to tree
  58.  
  59. cmp esi,0 ;do nothing if empty tree
  60. je Done
  61.  
  62. push BinTreeLeft[esi] ;Show left subtree
  63. call BinTreeShow
  64.  
  65. lea eax,Tmp[ebp] ;Convert current node value to string
  66. push eax
  67. push BinTreeValue[esi]
  68. call D2Str10
  69.  
  70. lea eax,Tmp[ebp] ;Show the resulting string
  71. push eax
  72. call StrLen
  73.  
  74. push eax ;Add CR/LF after string
  75. lea eax,Tmp[ebp]
  76. push eax
  77. call WriteStr
  78. push 2
  79. push OFFSET crlf
  80. call WriteStr
  81.  
  82. push BinTreeRight[esi] ;Show right subtree
  83. call BinTreeShow
  84. Done:
  85. pop esi
  86. sub esp,locals
  87. pop ebp
  88. ret 4
  89. BinTreeShow Endp
  90.  
  91. end

Report this snippet  

You need to login to post a comment.