00401000 funrune 00401020 push ebp 00401021 mov ebP·eap Copy.taek point.. - Poin
ID: 3852911 • Letter: 0
Question
00401000 funrune 00401020 push ebp 00401021 mov ebP·eap Copy.taek point.. - Pointer for thie funoton 1t eeterences both paramstors and leesi varlables 00401023 push eK 2017 06-CS 3843 Computer Organisation-Recitation Practice 00401024 mOVax eax lebp+s 00401028 movax ecx, [ebp +0ch1 0040102C add 00401028 mov [ebp-41, ax 00402031 mov mov ax, [ebp-4 00401034 mov esp, ebp : (5 pts) On the next page, show the state of the stack at this point, prior to the pop instruction and show the current esp 00401036 pop ebp 00401037 retn (3 pts) Description of Function what does it do?Explanation / Answer
I will try to explain each line of the program here -
Note: Since the value of memory contents of ebp location is not given, it is difficult to fill the table.
push ebp
mov ebp, esp
- The above 2 statements helps in establishing new stack frame within
the callee, while preserving the stack frame of the caller.
Stack frame allows consistent access to to passed parameters and local variables using
fixed offsets relative to EBP anywhere in the function,
while ESP is free to continue being modified as needed in the program.
Here we preserve the ebp contents to stack and copy the contents of stack pointer
to ebp.
push ecx - This is pushing the value of ecx to stack.
mov eax,[ebp+8] - EBP is most often used as the stack frame pointer in functions
Since we have stackpointer value in ebp, we are trying to access
8th location from the EBP and move the value to eax register.
mov ecx, [ebp+0ch] - Similar to the above instruction, we are copying 12th location contents from
the base address stored in EBP to ecx register
add eax, ecx - add the contents of eax and ecx ans store the result in eax.
mov [ebp-4],ax - move the contents of the ax register to the location which is 2 locations below the EBP.
mov ax, [ebp-4] - this instruction copies [ebp-4] contents to ax register.
the above 2 instructions make sure the contents of ax and [ebp-4] are same.
move esp,ebp - make the stack pointer point to the ebp contents. Here we are passing the control to the callee function by loading
esp register.
pop ebp - we are trying to retrieve the contents of ebp which was earlier pushed to stack.
retn - with this instruction, the control will be passed to callee function.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.