6

Possible Duplicate:
C/C++ function definitions without assembly

hi again, I want to know how printf works internally...by internally I mean what underlying system calls/ISRs etc mechanism is used...and not about the variable argument list...

Reason:I am using FASM but there is little there for console i/o, I know I can use printf available from the c library(I don't know how but that's a different point)

thanks.

Community
  • 1
  • 1
rsjethani
  • 2,179
  • 6
  • 24
  • 30

1 Answers1

7

The write(2) system call is used with the file descriptor set to STDOUT (its value is 1).

To invoke a system call from assembly, the eax register has to hold the id of the system call (I think the particular number of write() is 3) and the rest of the registers (ebx, ecx, ...) have to contain the arguments. Then doing an int 80h will switch the control from your process to the kernel routine that handles system calls.

The above is platform-specific, but virtually all Unix-like operating systems work like that.

Blagovest Buyukliev
  • 42,498
  • 14
  • 94
  • 130
  • System call [implementation](http://en.wikipedia.org/wiki/System_call#Typical_implementations) can also be architecture specific. CISC architectures such as x86 support additional techniques such as SYSCALL/SYSENTER or SYSRET/SYSEXIT "fast" control transfer instructions designed to quickly transfer control without the overhead of an interrupt. – jschmier Nov 09 '10 at 22:35