UMBC CMSC 313 -- Sample Program Previous | Next

Sample Program

Before

Suppose we have a simple program that has main( ) and one other function, func( ).
#include <stdio.h>

int func( int a, int b, int c );

int main( void )
{

  int x = 1;
  int y = 2;
  int z = 3;
  int w;

  w = func( x, y, z );
  printf( "%d\n", w );

  return 0;

}

int func( int a, int b, int c )
{
  return a + b + c;
}

  

After

We are going to convert this program, so that func( ) is a subprogram that is written in assembly language. That means the C version of func( ) has to come out of the C source code and its prototype changed to show that it is contained in an external file.
#include <stdio.h>

extern int func( int a, int b, int c );

int main( void )
{

  int x = 1;
  int y = 2;
  int z = 3;
  int w;

  w = func( x, y, z );

  printf( "%d\n", w );

  return 0;

}

/* We can simply comment out this function and for our
   purposes, it is gone. */
/*
int func( int a, int b, int c )
{
  return a + b + c;
}
*/
  


©2005, Gary L. Burt

Previous | Next