One of the problems I have with that book is that it treats assembly lanugage separately. If you wish to integrate your assembly language functions with C/C++, the standard in the 32-bit x86 world is to place the return value in eax. For example, a program that simply returns a value would be
Code:
.text
.globl main
main: pushl %ebp # save caller's base pointer
movl %esp, %ebp # establish our base pointer
movl $0, %eax # return 0 to caller
movl %ebp, %esp # restore stack pointer
popl %ebp # restore caller's base pointer
ret # back to caller
which is essentially equivalent to
Code:
int main() {
return 0;
}
You can assemble this with
Code:
as --gstabs -o doNothing.o doNothing.s
and link it with the necessary C libraries with
Code:
gcc -o doNothing doNothing.o
The --gstabs assembler option allows you to use symbols in gdb.
Using gcc for the linking phase instead of ld automatically links in the C libraries. If you use ld, you need to explicitly list all the libraries.
Bookmarks