Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS-401 Computer Architecture & Assembly Language Programming

Similar presentations


Presentation on theme: "CS-401 Computer Architecture & Assembly Language Programming"— Presentation transcript:

1 CS-401 Computer Architecture & Assembly Language Programming
Lecture-44 Interfacing with High Level Languages

2 Lets Revise the Last Lecture

3 Calling Conventions

4 Calling Conventions Naming conventions Parameter passing
Registers that must be preserved Registers used as scratch Registers which hold the return value Responsibility of clearing the parameters

5 C Vs PASCAL Naming Conventions
C PASCAL An underscore is Case sensitive Prep ended all uppercase name Case sensitive

6 C Vs PASCAL Naming Conventions
Parameter Passing C PASCAL Pushed in reverse Pushed in proper Order order

7 C Vs PASCAL Naming Conventions
Registers that must be preserved C PASCAL EBX, EDI, EBP, ESP, DS, ES and SS

8 C Vs PASCAL Naming Conventions
Registers used as scratch C PASCAL EAX, ECX, EDX, FS, GS, EFLAGS and all others

9 C Vs PASCAL Naming Conventions
Registers which hold the return value C PASCAL EAX (32 – bit value) EDX:EAX (64 – bit value)

10 C Vs PASCAL Naming Conventions
Responsibility of clearing parameters C PASCAL Caller Callee

11 Calling C from Assembly
Responsibility of clearing parameters int divide(int dividend, int divisor); push dword [mydivisor] Push dword [mydividend] Call_divide Add esp,8 ;EAX holds the answer

12 Swap in C void swap (int *p1, int *p2) { int temp = *p1; *p1 = *p2;
*p2 = temp; }

13 Calling Swap from Assembly
[section .text] extern_swap x:dd 4 y:dd 7 push dword y push dword x call_swap ; will only retain the ; specified registers add esp,8

14 Swap in Assembly [segment .text] global _swap _swap:
mov ecx,[esp+4] ;copy parameter p1 mov edx,[esp+8] ;copy parameter p2 mov eax,[ecx] ;copy *p1 into eax xchg eax,[edx] ;copy eax into *p2 mov [ecx],eax ;copy ecx into *p1 ret

15 OBJ file in win32

16 Swap In Assembly Language


Download ppt "CS-401 Computer Architecture & Assembly Language Programming"

Similar presentations


Ads by Google