//---------------------------------------------------------------- // linkdemo.s // // This program is intended to be linked with a separately // assembled object-file ('myplus.o') which implements the // function whose prototype (using C/C++ syntax) would be: // // int myplus( int num1, int num2 ); // // assemble using: $ gcc linkdemo.s myplus.o -o linkdemo // // programmer: ALLAN CRUSE // written on: 09 OCT 2003 //---------------------------------------------------------------- .data x: .int 7 y: .int 8 fmt: .asciz "\n%d plus %d equals %d \n\n" .text main: # call the external function 'myplus()' with the values # of variables 'x' and 'y' as the function's arguments; # the computed function-value will be returned in %eax. pushl y # setup argument #2 pushl x # setup argument #1 call myplus # call the external function addl $8, %esp # discard the two arguments # ok, now print a report that shows the results, using # the 'printf()' function from the standard C library, # and the format-string we have defined in our '.data' # section above. pushl %eax # setup argument #4 pushl y # setup argument #3 pushl x # setup argument #2 pushl $fmt # setup argument #1 call printf # call to C library addl $16, %esp # discard the four arguments ret # return control to the shell .globl main # make entry-point visible