CS-401 Computer Architecture & Assembly Language Programming Lecture-44 Interfacing with High Level Languages
Lets Revise the Last Lecture
Calling Conventions
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
C Vs PASCAL Naming Conventions C PASCAL An underscore is Case sensitive Prep ended all uppercase name Case sensitive
C Vs PASCAL Naming Conventions Parameter Passing C PASCAL Pushed in reverse Pushed in proper Order order
C Vs PASCAL Naming Conventions Registers that must be preserved C PASCAL EBX, EDI, EBP, ESP, DS, ES and SS
C Vs PASCAL Naming Conventions Registers used as scratch C PASCAL EAX, ECX, EDX, FS, GS, EFLAGS and all others
C Vs PASCAL Naming Conventions Registers which hold the return value C PASCAL EAX (32 – bit value) EDX:EAX (64 – bit value)
C Vs PASCAL Naming Conventions Responsibility of clearing parameters C PASCAL Caller Callee
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
Swap in C void swap (int *p1, int *p2) { int temp = *p1; *p1 = *p2; *p2 = temp; }
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
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
OBJ file in win32
Swap In Assembly Language