//-------------------------------------------------------------- // demo1.c // // This very simple application program merely adds two // specified integers and prints out the resulting sum. // It is written using the C programming language, just // to illustrate the distinction between a "high-level" // language and a "low-level" language (like assembly). // This demo should be compared with 'demo2.s' which is // a "low-level" version of the very same computation. // // compile using: $ gcc demo1.c -o demo1 // // programmer: ALLAN CRUSE // written on: 27 AUG 2003 // revised on: 25 JAN 2005 -- to use sprintf() and write() //-------------------------------------------------------------- #include // needed for 'printf()' #define device_id 1 // standard output file int x = 4, y = 5; // initialized variables int z, len; // uninitialized variables char buf[80]; // uninitialized array int main() { z = x + y; // assignment statement // call to library-function len = sprintf( buf, "%d + %d = %d \n", x, y, z ); // system-call to OS kernel write( device_id, &buf, len ); }