The program given below is written in assembly language. Write a program in C to call this assembly
routine.
routine.
[section .text]
global swap
swap: mov ecx,[esp+4] ; copy parameter p1 to ecx
mov edx,[esp+8] ; copy parameter p2 to edx
mov eax,[ecx] ; copy *p1 into eax
xchg eax,[edx] ; exchange eax with *p2
mov [ecx],eax ; copy eax into *p1
ret ; return from this function
global swap
swap: mov ecx,[esp+4] ; copy parameter p1 to ecx
mov edx,[esp+8] ; copy parameter p2 to edx
mov eax,[ecx] ; copy *p1 into eax
xchg eax,[edx] ; exchange eax with *p2
mov [ecx],eax ; copy eax into *p1
ret ; return from this function
#include <stdio.h>
void swap( int* p1, int* p2 );
int main()
{
int a = 10, b = 20;
printf( "a=%d b=%d\n", a, b );
swap(&a, &b );
printf( "a=%d b=%d\n", a, b );
system( "PAUSE" );
return 0;
}
void swap( int* p1, int* p2 );
int main()
{
int a = 10, b = 20;
printf( "a=%d b=%d\n", a, b );
swap(&a, &b );
printf( "a=%d b=%d\n", a, b );
system( "PAUSE" );
return 0;
}
0 Comments
Please add nice comments or answer ....