# AddOne.s, example of interfacing C to assembly language # # paired with TryAddOne.c, which calls addone # # assemble by typing # # as --gstabs -o AddOne.o AddOne.s # # note that we do not have a .data segment here, and normally would not; # but we could do so, and if we wanted that .data segment to be visible # from the calling C program, we would have .globl lines for whatever # labels we have in that segment .text # need .globl to make addone visible to ld .globl addone addone: # will use EBX, and since the calling module might have a value # there, better save the latter on the stack push %ebx # at this point the old EBX is on the top of the stack, then the # return address, then the argument, so the latter is at ESP+8 movl 8(%esp), %ebx # would be MOV EBX, [ESP+8] in Intel syntax incl (%ebx) # need the (), since the argument was an address # restore value of EBX in the calling module pop %ebx ret