Presentation is loading. Please wait.

Presentation is loading. Please wait.

Multi-modules programming

Similar presentations


Presentation on theme: "Multi-modules programming"— Presentation transcript:

1 Multi-modules programming

2 3. Interfacing with high-level languages

3 Interfacing with high-level languages
Passing parameters by value (Call by value) The values of data bytes are copied Wasteful and slow when data take up a lot of memory! From caller perspective, data are constant Passing parameters by reference (address/pointer) (Call by reference) The data address (and sometimes data size) is specified Ineffective when data take up less memory space additional 32 bits for address storage + need to read the pointer prior to data access Data may undergo changes Call by value or call by reference decision Belong to callee, not decided/discussed on call! Performance criterion: data size in bytes Is there any risk to exceed the available memory? Call by reference! Accessibility criterion: Do data need to be changed? Must data be constant? Call by value!

4 Interfacing with high-level languages
Calling conventions How do we pass parameters to subroutines? Which types of parameters can we pass? In what order? How many parameters? Any number of parameters? What resources are volatile (may be altered by the callee)? Where is the result stored? What cleanup actions are required after the call? Who is responsible to make them? Conventions Decided (and documented) by callee, not by caller! Commonly used: CDECL, STDCALL Less commonly used or obsolete: PASCAL, FORTRAN, SYSCALL, etc...

5 Interfacing with high-level languages
Calling conventions – C convention (CDECL) Specific to the C programming language How do we pass parameters to subroutines? By pushing them on the stack Which types of parameters can we pass? Any type, but extended at least to DWORD In what order? From right to the left, that is in the reverse order of declaration How many parameters? Any? Yes, in C is allowed functions with any parameters (ex: printf) What resources are volatile? EAX, ECX, EDX, Eflags (*just flags) Where is the result stored? EAX, EDX:EAX sau ST0 (FPU) What cleanup actions are required? Freeing up the arguments Who is responsible? The caller! Parameters Volatile resources Results Cleanup Storage Order Number Stack Reverse Any EAX, ECX, EDX, Flags* EAX / EDX:EAX / ST0 (FPU) Caller

6 Interfacing with high-level languages
Calling conventions – STDCALL convention Specific to Windows operating system Also called WINAPI Used by Windows system libraries Very similar to the CDECL convention Differences: A fixed number of parameters The cleanup is performed by callee Parameters Volatile resources Results Cleanup Storage Order Number Stack Reverse Fixed EAX, ECX, EDX, Flags* EAX / EDX:EAX / ST0 (FPU) Callee

7 Interfacing with high-level languages
Subroutine call Steps: Call code: call preparation and execution Entry code: procedure entry and preparation of execution Exit code: returning and freeing up out-of-date resources The actions depend by calling convention of called subroutine – but the steps remain the same! The steps are handled/implemented automatically in the code generated by compilers of high-level languages In assembly language, everything is our responsibility!

8 Interfacing with high-level languages
Subroutine call – call code Tasks: Save the volatile resources in use: push register Assure the compliance with constraints (aligned ESP, DF=0, ...) Prepare the arguments (stack/registers, by convention): mov/push Call execution: call call subroutine – if subroutine is statically linked call [subroutine] – if subroutine is dynamically linked (at link-time) call register or call [variable] – for run-time dynamic linking ASM subroutines used only from assembly language can avoid (for simplicity or efficiency) these tasks

9 Interfacing with high-level languages
Subroutine call – call code Example: call printf from asm to display digits from 0 to 9 import exit msvcrt.dll import printf msvcrt.dll extern exit, printf global start segment code use32 start: mov ecx, 10 xor eax, eax .next: push eax push ecx push dword format_string call [printf] add esp, 2*4 pop ecx pop eax inc eax loop .next push dword 0 call [exit] segment data use32 format_string db "%d", 10, 13, 0 If the call was made from C, the compiler would have generated by itself the call code! But the call is made from assembly, so the call code must be written by us! Save the volatile resources DF=0, stack is aligned (only DWORDs were pushed) Prepare the arguments for CDECL call Call execution Recover the volatile resources (the caller)

10 Comunicating with high level languages
Calling subroutines – call code Effect of the call code on the stack push eax push ecx push dword format_string call [printf] add esp, 2*4 Initial state ESP caller program data

11 Comunicating with high level languages
Calling subroutines – call code Effect of the call code on the stack push eax push ecx push dword format_string call [printf] add esp, 2*4 Saving volatile resources Saving volatile resources ESP Volatile resources caller program data Big addresses

12 Comunicating with high level languages
Calling subroutines – call code Effect of the call code on the stack push eax push ecx push dword format_string call [printf] add esp, 2*4 Saving volatile resources DF=0, the stack has only been used on DWORD Preparing arguments for the call CDECL (3) Preparing arguments for the call CDECL ESP Parameters Volatile resources caller program data Big addresses

13 Comunicating with high level languages
Calling subroutines – call code Effect of the call code on the stack push eax push ecx push dword format_string call [printf] add esp, 2*4 Saving volatile resources DF=0, the stack has only been used on DWORD Preparing arguments for the call CDECL Executing the call (4) Executing the call ESP Return address Parameters Volatile resources caller program data Big addresses

14 Comunicating with high level languages
Calling subroutines – entry code Tasks: Configuring a stack frame: taking ebp or esp into account? Preparing local variables of the function: sub esp, nr_bytes Saving a copy of the non-volatile resources that are modified: push register Any registers except the volatile ones Stack frame: data structure stored in the stack, of fixed dimension (for a given subroutine) and containing: The parameters prepared by the caller Return address (to the instruction that follows the call instruction) Copies of the non-volatile resources used by the subroutine Local variables Asm subroutines used only from asm can avoid this tasks (for simplicity or efficiency)

15 Comunicating with high level languages
Calling subroutines – entry code Example: entry code to the function CDECL chdir, generated by the C compiler ; disassembled with IDA - The Interactive Disassembler ; syntax corresponds to the MASM assembler ; int __cdecl chdir(const char *) chdir: mov edi, edi ; useless, but allows modification! push ebp mov ebp, esp sub esp, 118h mov eax, ___security_cookie xor eax, ebp mov [ebp+var_4], eax mov eax, [ebp+lpPathName] and [ebp+var_110], 0 push ebx or ebx, 0FFFFFFFFh push esi ;.... Configuring the stack frame Local variables Saving non-volatile registers The entry code has been automatically generated by the compiler!

16 Comunicating with high level languages
Calling subroutines – entry code Example: entry code to a function STDCALL written in asm by us factorial://in the caller C module we declare – extern int _stdcall factorial(int n) push ebp mov ebp, esp ; define a stack frame with EBP pivot/reference sub esp, ; allocate space on the stack for a temporary DWORD variable push ebx ; save ebx in order to restore it later mov eax, [ebp + 8] ; load the value of the argument from the stack frame cmp eax, ; test the termination condition (n < 2) jae .recursiv mov eax, ; return 1 when n < 2 jmp .gata .recursiv: push eax ; hold the value of n so that it is not lost in the recursive call dec eax push eax ; call factorial(n-1), push n-1 on the stack call factorial ; recursive call (STDCALL) mov [ebp - 4], eax ; save the value of factorial(n-1) in the temporary DWORD pop eax ; restore the value of n mov ebx, [ebp - 4] ; ebx <- factorial(n-1), taken from the temporary variable mul ebx ; compute (edx:)eax = (EAX=)n * (EBX=)factorial(n-1) .gata: pop ebx ; restore EBX to its initial value add esp, ; free the memory where the temporary variable was stored pop ebp ; restore ebp to its initial value ret ; STDCALL: return and free the memory where the parameters are stored Configuring the stack frame Local variables Saving non-volatile registers

17 Comunicating with high level languages
Calling subroutines – entry code Example: entry code to a function STDCALL written in asm – stackframe factorial: push ebp mov ebp, esp ; define a stack frame with EBP pivot/reference sub esp, ; allocate space on the stack for a temporary DWORD variable push ebx ; save ebx in order to restore it later mov eax, [ebp + 8] ; load the value of the argument from the stack frame cmp eax, ; test the termination condition (n < 2) jae .recursiv mov eax, ; return 1 when n < 2 jmp .gata .recursiv: push eax ; hold the value of n so that it is not lost in the recursive call dec eax push eax ; call factorial(n-1), push n-1 on the stack call factorial ; recursive call (STDCALL) mov [ebp - 4], eax ; save the value of factorial(n-1) in the temporary DWORD pop eax ; restore the value of n mov ebx, [ebp - 4] ; ebx <- factorial(n-1), taken from the temporary variable mul ebx ; compute (edx:)eax = (EAX=)n * (EBX=)factorial(n-1) .gata: pop ebx ; restore EBX to its initial value add esp, ; free the memory where the temporary variable was stored pop ebp ; restore ebp to its initial value ret ; STDCALL: return and free the memory where the parameters are stored Entry state ESP Return Address Parameters Volatile resources data Big addresses

18 Comunicating with high level languages
Calling subroutines – entry code Example: entry code to a function STDCALL written in asm – stackframe factorial: push ebp mov ebp, esp ; define a stack frame with EBP pivot/reference sub esp, ; allocate space on the stack for a temporary DWORD variable push ebx ; save ebx in order to restore it later mov eax, [ebp + 8] ; load the value of the argument from the stack frame cmp eax, ; test the termination condition (n < 2) jae .recursiv mov eax, ; return 1 when n < 2 jmp .gata .recursiv: push eax ; hold the value of n so that it is not lost in the recursive call dec eax push eax ; call factorial(n-1), push n-1 on the stack call factorial ; recursive call (STDCALL) mov [ebp - 4], eax ; save the value of factorial(n-1) in the temporary DWORD pop eax ; restore the value of n mov ebx, [ebp - 4] ; ebx <- factorial(n-1), taken from the temporary variable mul ebx ; compute (edx:)eax = (EAX=)n * (EBX=)factorial(n-1) .gata: pop ebx ; restore EBX to its initial value add esp, ; free the memory where the temporary variable was stored pop ebp ; restore ebp to its initial value ret ; STDCALL: return and free the memory where the parameters are stored Configuring the stack frame (1) Configuring the stack frame ESP, EBP caller EBP Return Address Parameters Volatile resources data High addresses

19 Comunicating with high level languages
Calling subroutines – entry code Example: entry code to a function STDCALL written in asm – stackframe factorial: push ebp mov ebp, esp ; define a stack frame with EBP pivot/reference sub esp, ; allocate space on the stack for a temporary DWORD variable push ebx ; save ebx in order to restore it later mov eax, [ebp + 8] ; load the value of the argument from the stack frame cmp eax, ; test the termination condition (n < 2) jae .recursiv mov eax, ; return 1 when n < 2 jmp .gata .recursiv: push eax ; stores the value of n for not being lost in the recursive call dec eax push eax ; call factorial(n-1), push n-1 on the stack call factorial ; recursive call (STDCALL) mov [ebp - 4], eax ; save the value of factorial(n-1) in the temporary DWORD pop eax ; restore the value of n mov ebx, [ebp - 4] ; ebx <- factorial(n-1), taken from the temporary variable mul ebx ; compute (edx:)eax = (EAX=)n * (EBX=)factorial(n-1) .gata: pop ebx ; restore EBX to its initial value add esp, ; free the memory where the temporary variable was stored pop ebp ; restore ebp to its initial value ret ; STDCALL: return and free the memory where the parameters are stored Configuring the stack frame Local variables (2) Local variables ESP Local variables EBP caller EBP Return Address Parameters Volatile resources data Big addresses

20 Comunicating with high level languages
Calling subroutines – entry code Example: entry code to a function STDCALL written in asm – stackframe factorial: push ebp mov ebp, esp ; define a stack frame with EBP pivot/reference sub esp, ; allocate space on the stack for a temporary DWORD variable push ebx ; save ebx in order to restore it later mov eax, [ebp + 8] ; load the value of the argument from the stack frame cmp eax, ; test the termination condition (n < 2) jae .recursiv mov eax, ; return 1 when n < 2 jmp .gata .recursiv: push eax ; stores the value of n for not being lost in the recursive call dec eax push eax ; call factorial(n-1), push n-1 on the stack call factorial ; recursive call (STDCALL) mov [ebp - 4], eax ; save the value of factorial(n-1) in the temporary DWORD pop eax ; restore the value of n mov ebx, [ebp - 4] ; ebx <- factorial(n-1), taken from the temporary variable mul ebx ; compute (edx:)eax = (EAX=)n * (EBX=)factorial(n-1) .gata: pop ebx ; restore EBX to its initial value add esp, ; free the memory where the temporary variable was stored pop ebp ; restore ebp to its initial value ret ; STDCALL: return and free the memory where the parameters are stored Stack frame configuration Local variables Saving Non-volatile registers (3) Saving Non-volatile registers ESP Non-volatile registers Local variables EBP caller EBP Return Address Parameters Volatile resources data High addresses

21 Comunicating with high level languages
Calling subroutines – entry code Example: entry code to a function STDCALL written in asm – stackframe factorial: push ebp mov ebp, esp ; define a stack frame with EBP pivot/reference sub esp, ; allocate space on the stack for a temporary DWORD variable push ebx ; save ebx in order to restore it later mov eax, [ebp + 8] ; load the value of the argument from the stack frame cmp eax, ; test the termination condition (n < 2) jae .recursiv mov eax, ; return 1 when n < 2 jmp .gata .recursiv: push eax ; hold the value of n so that it is not lost in the recursive call dec eax push eax ; call factorial(n-1), push n-1 on the stack call factorial ; recursive call (STDCALL) mov [ebp - 4], eax ; save the value of factorial(n-1) in the temporary DWORD pop eax ; restore the value of n mov ebx, [ebp - 4] ; ebx <- factorial(n-1), taken from the temporary variable mul ebx ; compute (edx:)eax = (EAX=)n * (EBX=)factorial(n-1) .gata: pop ebx ; restore EBX to its initial value add esp, ; free the memory where the temporary variable was stored pop ebp ; restore ebp to its initial value ret ; STDCALL: return and free the memory where the parameters are stored Stack evolution to recursive call ESP Non-volatile registers Local variables EBP caller EBP Return address Parameters Volatile resourcces Non-volatile registers Local variables EBP caller EBP Return Address Parameters Volatile resources data Big addresses

22 Comunicating with high level languages
Calling subroutines – exit code Tasks: Restore altered non-volatile resource Release the local variables of the function Deallocating the stack frame Returning from the function and releasing arguments CDECL: Calling subroutine: ret Calling procedure: add esp, size_of_arguments STDCALL: ret size_of_arguments Except for the volatile resources and direct results of the function, the status of the program after these steps must reflect the initial, pre-call state!

23 Comunicating with high level languages
Calling subroutines – exit code Example: exit code from a STDCALL asm function (recursive call) - stackframe ESP factorial: push ebp mov ebp, esp ; define a stack frame with EBP pivot/reference sub esp, ; allocate space on the stack for a temporary DWORD variable push ebx ; save ebx in order to restore it later mov eax, [ebp + 8] ; load the value of the argument from the stack frame cmp eax, ; test the termination condition (n < 2) jae .recursiv mov eax, ; return 1 when n < 2 jmp .gata .recursiv: push eax ; hold the value of n so that it is not lost in the recursive call dec eax push eax ; call factorial(n-1), push n-1 on the stack call factorial ; recursive call (STDCALL) mov [ebp - 4], eax ; save the value of factorial(n-1) in the temporary DWORD pop eax ; restore the value of n mov ebx, [ebp - 4] ; ebx <- factorial(n-1), taken from the temporary variable mul ebx ; compute (edx:)eax = (EAX=)n * (EBX=)factorial(n-1) .gata: pop ebx ; restore EBX to its initial value add esp, ; free the memory where the temporary variable was stored pop ebp ; restore ebp to its initial value ret ; STDCALL: return and free the memory where the parameters are stored Non-volatile registers Local variables EBP caller EBP Return address Parameters Volatile resources Non-volatile registers Local variables EBP caller EBP Return address Parameters Volatile resources data High addresses Non-volatile registers Freeing local variables Deallocating stackframe Return and deallocating params

24 Interfacing with high-level languages
Calling subroutines – exit code Example: exit code from a STDCALL asm function (recursive call) - stackframe factorial: push ebp mov ebp, esp ; define a stack frame with EBP pivot/reference sub esp, ; allocate space on the stack for a temporary DWORD variable push ebx ; save ebx in order to restore it later mov eax, [ebp + 8] ; load the value of the argument from the stack frame cmp eax, ; test the termination condition (n < 2) jae .recursiv mov eax, ; return 1 when n < 2 jmp .gata .recursiv: push eax ; hold the value of n so that it is not lost in the recursive call dec eax push eax ; call factorial(n-1), push n-1 on the stack call factorial ; recursive call (STDCALL) mov [ebp - 4], eax ; save the value of factorial(n-1) in the temporary DWORD pop eax ; restore the value of n mov ebx, [ebp - 4] ; ebx <- factorial(n-1), taken from the temporary variable mul ebx ; compute (edx:)eax = (EAX=)n * (EBX=)factorial(n-1) .gata: pop ebx ; restore EBX to its initial value add esp, ; free the memory where the temporary variable was stored pop ebp ; restore ebp to its initial value ret ; STDCALL: return and free the memory where the parameters are stored ESP Local variables EBP Caller EBP Return address Parameters Volatile resources Non-volatile registers Local variables EBP caller EBP Return address Parameters Volatile resources data High addresses Non-volatile registers

25 Interfacing with high-level languages
Calling subroutines – exit code Example: exit code from a STDCALL asm function (recursive call) - stackframe factorial: push ebp mov ebp, esp ; define a stack frame with EBP pivot/reference sub esp, ; allocate space on the stack for a temporary DWORD variable push ebx ; save ebx in order to restore it later mov eax, [ebp + 8] ; load the value of the argument from the stack frame cmp eax, ; test the termination condition (n < 2) jae .recursiv mov eax, ; return 1 when n < 2 jmp .gata .recursiv: push eax ; hold the value of n so that it is not lost in the recursive call dec eax push eax ; call factorial(n-1), push n-1 on the stack call factorial ; recursive call (STDCALL) mov [ebp - 4], eax ; save the value of factorial(n-1) in the temporary DWORD pop eax ; restore the value of n mov ebx, [ebp - 4] ; ebx <- factorial(n-1), taken from the temporary variable mul ebx ; compute (edx:)eax = (EAX=)n * (EBX=)factorial(n-1) .gata: pop ebx ; restore EBX to its initial value add esp, ; free the memory where the temporary variable was stored pop ebp ; restore ebp to its initial value ret ; STDCALL: return and free the memory where the parameters are stored ESP, EBP Caller EBP Return address Parameters Volatile resources Non-volatile registers Local variables EBP caller EBP Return address Parameters Volatile resources data High addresses (2) Freeing local variables

26 Interfacing with High Level Languages
Calling subprograms – exit code Example: asm exit code from a STDCALL function (recursive call) - stackframe factorial: push ebp mov ebp, esp ; define a stackframe with EBP as pivot/reference sub esp, ; reserve space on the stack for a temporary DWORD variable push ebx ; save EBX so we can restore its value mov eax, [ebp + 8] ; load the value of the argument from the stackframe cmp eax, ; check the terminating condition (n < 2) jae .recursive mov eax, ; return 1 when n < 2 jmp .finish .recursive: push eax ; retain the value of n so we don’t misplace it in the recursive call dec eax push eax ; call factorial(n-1), save on the stack the value of n-1 call factorial ; recursive call (STDCALL) mov [ebp - 4], eax ; save in the temporary DWORD variable the value of factorial(n-1) pop eax ; restore the value of n mov ebx, [ebp - 4] ; ebx <- factorial(n-1), taken from the temporary DWORD variable mul ebx ; compute (edx:)eax = (EAX=)n * (EBX=)factorial(n-1) .finish: pop ebx ; restore EBX to its initial value add esp, ; free the memory occupied by the temporary variable pop ebp ; restore EBP to its initial value ret ; STDCALL: return and free the reserved memory ESP Return address Parameters Volatile resources Non-volatile registers Local variables EBP caller EBP Return address Parameters Volatile resources data High addresses (3) Deallocating stackframe

27 Interfacing with High Level Languages
Calling subprograms – exit code Example: asm exit code from a STDCALL function (recursive call) - stackframe factorial: push ebp mov ebp, esp ; define a stackframe with EBP as pivot/reference sub esp, ; reserve space on the stack for a temporary DWORD variable push ebx ; save EBX so we can restore its value mov eax, [ebp + 8] ; load the value of the argument from the stackframe cmp eax, ; check the terminating condition (n < 2) jae .recursive mov eax, ; return 1 when n < 2 jmp .finish .recursive: push eax ; retain the value of n so we don’t misplace it in the recursive call dec eax push eax ; call factorial(n-1), save on the stack the value of n-1 call factorial ; recursive call (STDCALL) mov [ebp - 4], eax ; save in the temporary DWORD variable the value of factorial(n-1) pop eax ; restore the value of n mov ebx, [ebp - 4] ; ebx <- factorial(n-1), taken from the temporary DWORD variable mul ebx ; compute (edx:)eax = (EAX=)n * (EBX=)factorial(n-1) .finish: pop ebx ; restore EBX to its initial value add esp, ; free the memory occupied by the temporary variable pop ebp ; restore EBP to its initial value ret ; STDCALL: return and free the reserved memory ESP Volatile resources Non-volatile registers Local variables EBP caller EBP Return address Parameters Volatile resources data High addresses (4) Return and deallocating params

28 Interfacing with High Level Languages
Calling subprograms – exit code Example: asm exit code from a STDCALL function (recursive call) - stackframe factorial: push ebp mov ebp, esp ; define a stackframe with EBP as pivot/reference sub esp, ; reserve space on the stack for a temporary DWORD variable push ebx ; save EBX so we can restore its value mov eax, [ebp + 8] ; load the value of the argument from the stackframe cmp eax, ; check the terminating condition (n < 2) jae .recursive mov eax, ; return 1 when n < 2 jmp .finish .recursive: push eax ; retain the value of n so we don’t misplace it in the recursive call dec eax push eax ; call factorial(n-1), save on the stack the value of n-1 call factorial ; recursive call (STDCALL) mov [ebp - 4], eax ; save in the temporary DWORD variable the value of factorial(n-1) pop eax ; restore the value of n mov ebx, [ebp - 4] ; ebx <- factorial(n-1), taken from the temporary DWORD variable mul ebx ; compute (edx:)eax = (EAX=)n * (EBX=)factorial(n-1) .finish: pop ebx ; restore EBX to its initial value add esp, ; free the memory occupied by the temporary variable pop ebp ; restore EBP to its initial value ret ; STDCALL: return and free the reserved memory Volatile resources ESP Non-volatile registers Local variables EBP caller EBP Return address Parameters Volatile resources data High addresses

29 Interfacing with High Level Languages
Calling subprograms – exit code Example: asm exit code from a STDCALL function (recursive call) - stackframe factorial: push ebp mov ebp, esp ; define a stackframe with EBP as pivot/reference sub esp, ; reserve space on the stack for a temporary DWORD variable push ebx ; save EBX so we can restore its value mov eax, [ebp + 8] ; load the value of the argument from the stackframe cmp eax, ; check the terminating condition (n < 2) jae .recursive mov eax, ; return 1 when n < 2 jmp .finish .recursive: push eax ; retain the value of n so we don’t misplace it in the recursive call dec eax push eax ; call factorial(n-1), save on the stack the value of n-1 call factorial ; recursive call (STDCALL) mov [ebp - 4], eax ; save in the temporary DWORD variable the value of factorial(n-1) pop eax ; restore the value of n mov ebx, [ebp - 4] ; ebx <- factorial(n-1), taken from the temporary DWORD variable mul ebx ; compute (edx:)eax = (EAX=)n * (EBX=)factorial(n-1) .finish: pop ebx ; restore EBX to its initial value add esp, ; free the memory occupied by the temporary variable pop ebp ; restore EBP to its initial value ret ; STDCALL: return and free the reserved memory ESP Non-volatile registers Local variables EBP caller EBP Return address Parameters Volatile resources data High addresses

30 Interfacing with High Level Languages
Calling subprograms – exit code Example: asm exit code from a STDCALL function (recursive call) - stackframe factorial: push ebp mov ebp, esp ; define a stackframe with EBP as pivot/reference sub esp, 4 ; reserve space on the stack for a temporary DWORD variable push ebx ; save EBX so we can restore its value mov eax, [ebp + 8] ; load the value of the argument from the stackframe cmp eax, ; check the terminating condition (n < 2) jae .recursive mov eax, ; return 1 when n < 2 jmp .finish .recursive: push eax ; retain the value of n so we don’t loose it in the recursive call dec eax push eax ; call factorial(n-1), save on the stack the value of n-1 call factorial ; recursive call (STDCALL) mov [ebp - 4], eax ; save in the temporary variable the value of factorial(n-1) pop eax ; restore the value of n mov ebx, [ebp - 4] ; ebx <- factorial(n-1), taken from the temporary DWORD var mul ebx ; compute (edx:)eax = (EAX=)n * (EBX=)factorial(n-1) .finish: pop ebx ; restore EBX to its initial value add esp, ; free the memory occupied by the temporary variable pop ebp ; restore EBP to its initial value ret ; STDCALL: return and free the reserved memory ESP Volatile resources Caller’s program data High addresses


Download ppt "Multi-modules programming"

Similar presentations


Ads by Google