Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

assembly Language The cleanup using the STDCALL Calling Convention involves remo

ID: 3905782 • Letter: A

Question

assembly Language

The cleanup using the STDCALL Calling Convention involves removal of all the used local variables and other parameters from the stack It is done using an integer value; equal to the number of bytes used by the procedure; appended to the RET statement. After the RET returns to the address of calling procedure; this integer value is added to the value of EBP that cleanup the stack. The following code segment illustrates it: MyProc PROC push ebp mov ebp,esp; assign the stack location to ; EBP mov ebx,[ebp+8]; first parameter stored at ; location ebp+8 sub ebx.lebpt4): second parameter stored at location ebp+4 pop ebp ret 8; 4-bytes for each parameter MyProc ENDP Here note that the storage of EBP does not add bytes onto the integer value.

Explanation / Answer

In the body of the subroutine we can see the use of the base pointer. Both parameters and local variables are located at constant offsets from the base pointer for the duration of the subroutines execution. In particular, we notice that since parameters were placed onto the stack before the subroutine was called, they are always located below the base pointer (i.e. at higher addresses) on the stack. The first parameter to the subroutine can always be found at memory location [EBP+8], the second at [EBP+4] . Similarly, since local variables are allocated after the base pointer is set, they always reside above the base pointer (i.e. at lower addresses) on the stack. This conventional use of the base pointer allows us to quickly identify the use of local variables and parameters within a function body.