Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- _declspec(naked) void
- insertNode(struct tNode* root, struct tNode* newNode,unsigned int data)
- {
- __asm{
- mov eax, dword ptr[esp+4] //Register EAX holds pointer to Root Node
- mov ebx, dword ptr[esp+8] //Register EBX holds pointer to new Node to be inserted
- mov ecx, dword ptr[esp+12] //Register ECX holds data to be stored in new node
- cmp eax, 0 //Check if the root node is null
- je ROOT_IS_NULL
- //If the root node is not null, then check if data is greater than and equal or less than
- mov edx, [eax] //Move the data in the root to register EDX
- cmp ecx, edx //Compare the data to be stored with the root's data
- jge GREATER_THAN_OR_EQUAL
- cmp ecx, edx
- jl LESS_THAN
- GREATER_THAN_OR_EQUAL:
- //If it's greater than or equal, then select the right child and call function until a null is reached
- mov edx, dword ptr[eax+8]
- push ecx
- push ebx
- push edx
- CALL insertNode
- pop edx
- pop ebx
- pop ecx
- ret
- LESS_THAN:
- //If it's less than, then select the left child and call function until a null is reached
- mov edx, dword ptr[eax+4]
- push ecx
- push ebx
- push edx
- CALL insertNode
- pop edx
- pop ebx
- pop ecx
- ret
- ROOT_IS_NULL:
- //If the root is null, than set
- mov dword ptr[ebx], ecx //Store the data into the new node to be inserted
- mov dword ptr[ebx+4], 0
- mov dword ptr[ebx+8], 0
- mov ecx, dword ptr[ebx+4]
- mov dword ptr[eax+4], ecx
- mov ecx, dword ptr[ebx+8]
- mov dword ptr[eax+8], ecx
- mov dword ptr[eax], ebx
- ret
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement