Calling a function that is embedded in the operating system is accomplished through a
special type of instruction sometimes called a “software interrupt.” The instruction itself
will be discussed in Section 15.3 (page 291), but it is easy to understand its use at this
point. The technique involves moving the arguments to specific registers, placing a special
code in the eax register, and then using the int $0x80 instruction to “call” a function in
the operating system. The operating system will perform the action specified by the code
in the eax register, using the arguments passed in the other registers. The values required
for reading from and writing to files are given in Table 7.2.
Code:
Table 7.2: Register set up for system calls to read or write.
system call eax ebx ecx edx
----------- --- --- --- ---
read 3 file descriptor pointer to place number of bytes
to store bytes to read
write 4 file descriptor pointer to first number of bytes
byte to write to write
Bookmarks