Chapter 9
Chapter 9
Chapter 9
SYSTEM SERVICES
Introduction
1
02/03/2019
2
02/03/2019
System Calls
3
02/03/2019
Newline Character
In the context of output, a newline means move the
cursor to the start of the next line.
The many languages, including C, it is often noted as
“\n” as part of a string
Nothing is displayed for the newline, but the cursor is
moved to the start of the next line.
In Unix/Linux systems, the linefeed, abbreviated LF with
an ASCII value of 10 (or 0x0A), is used as the newline
character.
In Windows systems, the newline is carriage
return, abbreviated as CR with an ASCII value 13 (or
0x0D) followed by the LF.
Console Output
The system service to output characters to the console is
the system write (SYS_write).
Like a high-level language characters are written to
standard out (STDOUT) which is the console
The STDOUT is the default file descriptor for the console
The arguments for the write system service are as follows:
4
02/03/2019
5
02/03/2019
6
02/03/2019
7
02/03/2019
Console Input
The system service to read characters from the
console is the system read (SYS_read).
Like a high-level language, for the console,
characters are read from standard input (STDIN).
We will need to declare an appropriate amount of
space to store the characters being read
If we request 10 characters to read and the user types
more than 10, the additional characters will be lost
If the user types less than 10 characters, for example
5 characters, all five characters will be read plus the
newline (LF) for a total of six characters.
8
02/03/2019
Example
9
02/03/2019
10
02/03/2019
11
02/03/2019
12
02/03/2019
13
02/03/2019
After the system call, the rax register will contain the
return value.
If the file open operation fails, rax will contain a negative
value (i.e., < 0).
If the file open operation succeeds, rax contains the file
descriptor
File Open/Create
A file open/create operation will create a file
If the file does not exist, a new file will be created
If the file already exists, it will be erased and a new file created.
Since the file is being created, the access mode must include the
file permissions that will be set when the file is created.
14
02/03/2019
File Read
A file must be opened with the appropriate file access flags
before it can be read.
The arguments for the file read system service are as follows:
15
02/03/2019
File Write
The arguments for the file write system service are as
follows:
16
02/03/2019
17
02/03/2019
18
02/03/2019
19
02/03/2019
20
02/03/2019
21
02/03/2019
22