Ad Code

program in C to call this assembly routine.

The program given below is written in assembly language. Write a program in C to call this assembly
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


#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;
}
Reactions

Post a Comment

0 Comments