Operating the earliest automobiles was a complicated task: a driver would have to know all about the intricate details of the engine; how to set the throttle and the choke; how to crank the engine; and how to use the clutch and the gear shift levers to change speeds.
Operating the earliest computers was also a complicated task: a user would have to know all about the intricate details of the processor, how to convert data and instructions into sequences of 0-bits and 1-bits, and how to read the output as sequences of 0-bits and 1-bits.
Modern automobiles are much simpler to use and modern computers are also much simpler to use: we say they are user-friendly. A driver interfaces with the automobile through the dashboard. A user interfaces with the computer through the system software.
(6.2) - System Software
(6.2.1) - The Virtual Machine: System software manages the resources of a computer and makes them more accessible. It acts as an intermediary between the machine hardware and the user. Users interact with the machine through a virtual machine interface: they see a virtual machine or virtual environment instead of the actual machine itself (Fig. 6.1).
(6.2.2) - Types of System Software:
(6.3.1) - Assembly Language: Machine language is complicated and hard to use:
Figure 6.4 illustrates the process of assembly language programming: the programmer writes a source program in assembly language; the source program is sent through the assembler to create an object program in machine language; and then the object program is loaded into memory and executed by the hardware to create the output.
The advantages of writing in assembly language are: using symbolic operation codes in place of numeric codes; using symbolic memory addresses in place of numeric addresses; and pseudo-operations to provide useful services like generating data. Each instruction in assembly language has a format like:
| label: | op code mnemonic | address field | --comment |
|---|
The comment field is ignored by the assembler: it can be used to write an explanation of what the instruction is doing or just left blank. The label field is only necessary when some other instruction refers to this instruction or data item. Figure 6.5 shows the instruction set for a typical assembly language (the figure is identical to Figure 5.19):
| Binary Opcode | Operation | Meaning |
|---|---|---|
| 0000 | LOAD X | CON(X) --> R |
| 0001 | STORE X | R --> CON(X) |
| 0010 | CLEAR X | 0 --> CON(X) |
| 0011 | ADD X | R + CON(X) --> R |
| 0100 | INCREMENT X | CON(X) + 1 --> CON(X) |
| 0101 | SUBTRACT X | R - CON(X) --> R |
| 0110 | DECREMENT X | CON(X) - 1 --> CON(X) |
| 0111 | COMPARE X | if CON(X) > R then set GT to 1, else 0 if CON(X) = R then set EQ to 1, else 0 if CON(X) < R then set LT to 1, else 0 |
| 1000 | JUMP X | Jump to location X |
| 1001 | JUMPGT X | Jump to location X if GT = 1 |
| 1010 | JUMPEQ X | Jump to location X if EQ = 1 |
| 1011 | JUMPLT X | Jump to location X if LT = 1 |
| 1100 | JUMPNEQ X | Jump to location X if EQ = 0 |
| 1101 | IN X | Input an integer into location X |
| 1110 | OUT X | Output an integer from location X |
| 1111 | HALT | Stop program execution |
As an example, the assembly-language code to calculate A = B + C - 7 is:
| LOAD | B | -- Register R = B | |
| ADD | C | -- R = B + C | |
| SUBTRACT | SEVEN | -- R = B + C - 7 | |
| STORE | A | -- A = B + C - 7 | |
| . | |||
|---|---|---|---|
| . | |||
| . | |||
| HALT | --Don't run into the data | ||
| A: | .DATA | 0 | |
| B: | .DATA | 0 | |
| C: | .DATA | 0 | |
| SEVEN: | .DATA | 7 | -- The constant 7 |
.DATA is a pseudo-op to generate a data item.
(6.3.2) - Examples of Assembly Language Code: The following pseudocode uses a conditional operation to print the larger of two values, x and y:
| Get the value of x | |
| Get the value of y | |
| If x | > y then |
| Print the value of x | |
| Else | |
| Print the value of y | |
This pseudocode can be written in assembly language as follows:
| .BEGIN | -- Marks the start of the program | ||
| IN | X | -- Input X | |
| IN | Y | -- Input Y | |
| LOAD | Y | -- Load Y into register R | |
| COMPARE | X | -- Compare X to Y | |
| JUMPGT | PRINTX | -- Jump if X > Y | |
| OUT | Y | -- Didn't jump so print Y | |
| JUMP | DONE | -- and go to end | |
| PRINTX: | OUT | X | -- X > Y so print X |
| DONE: | HALT | -- Stop | |
| X: | .DATA | 0 | |
| Y: | .DATA | 0 | |
| .END | -- Marks the end of the program |
The next example uses a loop to solve the following problem: Read in a sequence of non-negative numbers, one number at a time, and compute a running sum. When you encounter a negative number, print out the sum of the non-negative numbers and stop.
The pseudocode is:
| Step 1: | Set the value of Sum to 0 | |
|---|---|---|
| Step 2: | Get the value of the first number, N | |
| Step 3: | While | N is non-negative, execute steps 4 and 5 |
| Step 4: | Add the value of N to Sum | |
| Step 5: | Get the value of the next number, N | |
| Step 6: | End of the loop | |
| Step 7: | Print out Sum | |
| Step 8: | Stop | |
The assembly language code is:
| .BEGIN | |||
| CLEAR | SUM | ||
| AGAIN: | IN | N | -- Start of loop |
| LOAD | ZERO | -- Test sign of N | |
| COMPARE | N | ||
| JUMPLT | NEG | ||
| LOAD | SUM | -- N non-negative so add it to SUM | |
| ADD | N | ||
| STORE | SUM | ||
| JUMP | AGAIN | -- and repeat the loop again | |
| NEG: | OUT | SUM | -- N < 0 so print SUM |
| HALT | -- and stop | ||
| SUM: | .DATA | 0 | -- Running sum goes here |
| N: | .DATA | 0 | -- Input values go here |
| ZERO: | .DATA | 0 | -- The constant 0 |
| .END |
(6.3.3) - Translation and Loading: Before the running-sum program in the previous section can be executed it must be translated by the assembler into machine language and then loaded into memory by the loader.
Translating from one language to another can be quite a difficult task if the vocabulary, grammar, and syntax of the two languages differ greatly. Since assembly language is so close to machine language the assembler is a relatively simple piece of system software. The assembler must:
| Symbolic Opcode | Binary Opcode |
|---|---|
| ADD | 0011 |
| CLEAR | 0010 |
| COMPARE | 0111 |
| DECREMENT | 0110 |
| HALT | 1111 |
| IN | 1101 |
| INCREMENT | 0100 |
| JUMP | 1000 |
| JUMPEQ | 1010 |
| JUMPGT | 1001 |
| JUMPLT | 1011 |
| JUMPNEQ | 1100 |
| LOAD | 0000 |
| OUT | 1110 |
| STORE | 0001 |
| SUBTRACT | 0101 |
Converting symbolic addresses to binary requires two passes over the source code: during the first pass the assembler builds a symbol table containing each label with its corresponding binary address and during the second pass the assembler looks up entries in the symbol table to get the appropriate addresses.
As an example we consider the running sum program in section 6.3.2. During Pass 1, the assembler reads in the assembly language while maintaining a location counter:
| ASSEMBLY LANGUAGE | LOCATION | ||
|---|---|---|---|
| .BEGIN | |||
| CLEAR | SUM | 0 | |
| AGAIN: | IN | N | 1 |
| LOAD | ZERO | 2 | |
| COMPARE | N | 3 | |
| JUMPLT | NEG | 4 | |
| LOAD | SUM | 5 | |
| ADD | N | 6 | |
| STORE | SUM | 7 | |
| JUMP | AGAIN | 8 | |
| NEG: | OUT | SUM | 9 |
| HALT | 10 | ||
| SUM: | .DATA | 0 | 11 |
| N: | .DATA | 0 | 12 |
| ZERO: | .DATA | 0 | 13 |
| .END | |||
Also, during Pass 1, the assembler builds the Symbol Table for the program containing each label with its location:
| Symbol | Location | |
|---|---|---|
| Decimal | Binary | |
| AGAIN | 1 | 0001 |
| NEG | 9 | 1001 |
| SUM | 11 | 1011 |
| N | 12 | 1100 |
| ZERO | 13 | 1101 |
The assembler might alphabetize the Symbol Table so Pass 2 can use the binary search algorithm:
| Symbol | Location | |
|---|---|---|
| Decimal | Binary | |
| AGAIN | 1 | 0001 |
| N | 12 | 1100 |
| NEG | 9 | 1001 |
| SUM | 11 | 1011 |
| ZERO | 13 | 1101 |
Pass 2 of the assembler runs through the assembly language again and generates the binary machine language program using the Opcode Table to generate the binary opcode of each instruction and the Symbol Table to generate the binary address of each instruction.
Figures 6.11 and 6.12 show flowcharts for the two passes of the assembler.
The loader reads the object file, stores the machine-language instructions and data in the appropriate places of the RAM, and then sets the PC to the address of the first instruction in the program.
(6.4) - Operating Systems
A user issues a system command to tell the computer to perform some service like translate a program, load a program, run a program, etc. A system command might be a line of text typed into a terminal or it might be a menu item or icon selected by a mouse. The operating system is the software that examines the command and activates other system programs to perform the desired service.
(6.4.1) - Functions of an Operating System: The User Interface: The operating system (OS) runs in the processor whenever there is no other piece of user or system software running in the processor: it waits for the user to input a command (via the keyboard, the mouse, or some other input device.) When a legal command is received, the OS activates and schedules the appropriate software to process the command. Examples of OS commands are:
System Security and Protection: The OS must prevent unauthorized users from using the machine so a person is not allowed to use the machine until he/she logs on with an authorized username and password.
The OS must also prevent authorized users from performing unauthorized actions so different users are given different privileges with respect to each file: e.g., several users may be able to read the file but only a few are given permission to write to the file.
Efficient Allocation of Resources: The typical I/O operation might require several milliseconds to execute so the OS tries to keep the processor busy performing other useful tasks. It maintains three classes of programs:
The Safe Use of Resources: The OS should prevent deadlock. As an example of deadlock suppose a system has one tape drive and one printer and two programs, A and B, make the following requests:
| Program A | Program B |
|---|---|
| Step 1: Reserve the tape drive | Step 1: Reserve the printer |
| Step 2: Reserve the printer | Step 2: Reserve the tape drive |
| Step 3: Print a tape file | Step 3: Print a tape file |
| Step 4: Release the printer and tape drive. | Step 4: Release the printer and tape drive. |
If Program A reserves the tape drive and Program B reserves the printer then each program will wait forever for the other program to release the second resource it wants to reserve.
(6.4.2) - Historical Overview: The earliest computers had no operating systems: each programmer would waste much computer time standing by the machine trying to debug a program.
In the mid-fifties batch operating systems became available: to debug a program a programmer would insert print statements around places in the code where bugs were suspected and submit a batch job on a deck of cards with job control language cards as well as code and data cards (see Figure 6.19) Machine usage was much better since programmers would examine their printouts off-line to find the bugs.
In the mid-sixties multiprogramming operating systems became available: memory holds many user programs at one time so if one program needs to wait for an I/O operation the processor can execute other programs. To make sure a user program doesn't clobber any other program or the OS, each user program is given an upper bound and a lower bound on the memory addresses it can access. To make sure a user program can't change its bounds or do other illegal actions, the instruction set has certain privileged op codes that only the OS can execute.
In the seventies time-sharing systems became popular: the central computer would be coupled to a number of terminals so several users could submit jobs and interact with them simultaneously (Figure 6.20).
As personal computers became faster and cheaper during the eighties they replaced the "dumb" terminals of the time-sharing systems. Since each PC could also compute as well as handle the functions of a terminal, the central computer of the time-sharing system became less and less important. There is still a need for centralized servers so local area networks (LANs) are now the norm (Figure 6.21).
A network operating system creates the virtual environment one sees today (Figure 6.22).