typedef struct TreeNode { struct TreeNode *left; struct TreeNode *right; long val; } TreeNode; Each TreeNode stores a val and two pointers (left, right) to its children, which are themselves TreeNode structs. Address OxO (NULL) indicates the child is empty. Recall that the C syntax t->val is equivalent to (*t).val. Disassembled Mystery Code. Alice remembers the mystery function's signature: long mystery (TreeNode* t) { } Alice recovered and disassembled the machine code for mystery and its caller, callmystery. 0x401106 : 0x40113c : 0x40113c subq $0x8,%rsp 0x401140 call 0x401145 addq 0x401149 ret $0x0,%eax %rdi,%rdi 0x401106 movą 0x40110b testq 0x40110e je 0x401110 pushq 0x401111 pushq 0x401112 subq 0x401116 movq 0x401119 movq 0x40111d movq 0x401120 call 0x401125 addq 0x401128 movq 0x40112c call 0x401131 addq %rbp,%rax 0x401134 addq $0x8,%rsp 0x401138 popq %rbx 0x401139 popq %rbp 0x40113a ret 40113a %rbp %rbx $0x8,%rsp %rdi,%rbx 0x10 (%rdi), %rbp (%rdi), %rdi 401106 %rax,%rbp 0x8(%rbx), %rdi 401106 401106 $0x8,%rsp
Types of Linked List
A sequence of data elements connected through links is called a linked list (LL). The elements of a linked list are nodes containing data and a reference to the next node in the list. In a linked list, the elements are stored in a non-contiguous manner and the linear order in maintained by means of a pointer associated with each node in the list which is used to point to the subsequent node in the list.
Linked List
When a set of items is organized sequentially, it is termed as list. Linked list is a list whose order is given by links from one item to the next. It contains a link to the structure containing the next item so we can say that it is a completely different way to represent a list. In linked list, each structure of the list is known as node and it consists of two fields (one for containing the item and other one is for containing the next item address).
Please answer the following with the reference;
1a. What is the purpose of the movq 0x10 (%rdi), rbp instruction here (at the C level or higher)? How does this relate to the earlier call to pushq rbp?
1b. Alice just remembered that the original C code had the following structure! Using what you now know about mystery, fill in the blanks with C code.
long mystery ( TreeNode* t){
If ( ) {
return ;
}
return
}
Step by step
Solved in 3 steps