Example of A System Call
Calling an operating system directly is generally impossible in the presence of protected memory. The OS runs at a more privileged level (kernel mode) than the user (user mode); a (software) interrupt is used to make requests to the operating system. This is rarely a feature in a higher-level language, and so wrapper functions for system calls are written using inline assembler.
The following C code are samples including a system call wrapper in AT&T assembler syntax with the GNU Assembler. They are normally written with the aid of macros; the full code is included for clarity.
The format of basic inline assembly is very much straightforward. Its basic form is
asm("assembly code");Example:
asm("movl %ecx, %eax"); /* moves the contents of ecx to eax */OR
__asm__("movb %bh, (%eax)"); /* moves the byte from bh to the memory pointed by eax */Both asm
and __asm__
are valid. __asm__
can be used if the keyword asm
conflicts with something in your program.
Read more about this topic: Inline Assembler
Famous quotes containing the words system and/or call:
“A religion so cheerless, a philosophy so sorrowful, could never have succeeded with the masses of mankind if presented only as a system of metaphysics. Buddhism owed its success to its catholic spirit and its beautiful morality.”
—W. Winwood Reade (18381875)
“The mode of founding a college is, commonly, to get up a subscription of dollars and cents, and then, following blindly the principles of a division of labor to its extreme,a principle which should never be followed but with circumspection,to call in a contractor who makes this a subject of speculation,... and for these oversights successive generations have to pay.”
—Henry David Thoreau (18171862)