Advertisement
Guest User

Untitled

a guest
May 29th, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.48 KB | None | 0 0
  1. _declspec(naked) void
  2. insertNode(struct tNode* root, struct tNode* newNode,unsigned int data)
  3. {
  4. __asm{
  5. mov eax, dword ptr[esp+4] //Register EAX holds pointer to Root Node
  6. mov ebx, dword ptr[esp+8] //Register EBX holds pointer to new Node to be inserted
  7. mov ecx, dword ptr[esp+12] //Register ECX holds data to be stored in new node
  8. cmp eax, 0 //Check if the root node is null
  9. je ROOT_IS_NULL
  10. //If the root node is not null, then check if data is greater than and equal or less than
  11. mov edx, [eax] //Move the data in the root to register EDX
  12. cmp ecx, edx //Compare the data to be stored with the root's data
  13. jge GREATER_THAN_OR_EQUAL
  14. cmp ecx, edx
  15. jl LESS_THAN
  16. GREATER_THAN_OR_EQUAL:
  17. //If it's greater than or equal, then select the right child and call function until a null is reached
  18. mov edx, dword ptr[eax+8]
  19. push ecx
  20. push ebx
  21. push edx
  22. CALL insertNode
  23. pop edx
  24. pop ebx
  25. pop ecx
  26. ret
  27. LESS_THAN:
  28. //If it's less than, then select the left child and call function until a null is reached
  29. mov edx, dword ptr[eax+4]
  30. push ecx
  31. push ebx
  32. push edx
  33. CALL insertNode
  34. pop edx
  35. pop ebx
  36. pop ecx
  37. ret
  38. ROOT_IS_NULL:
  39. //If the root is null, than set
  40. mov dword ptr[ebx], ecx //Store the data into the new node to be inserted
  41. mov dword ptr[ebx+4], 0
  42. mov dword ptr[ebx+8], 0
  43. mov ecx, dword ptr[ebx+4]
  44. mov dword ptr[eax+4], ecx
  45. mov ecx, dword ptr[ebx+8]
  46. mov dword ptr[eax+8], ecx
  47. mov dword ptr[eax], ebx
  48. ret
  49. }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement