Chapter 4

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

Example of Multitasking 1

A process is a program with its execution state. Can be Running, Runnable, or Blocked for I/O. Assume application programs A and B initiated. If A is executing when time slice expires, timer interrupts and SCHEDULER is entered and registers are saved. OS then selects B, restores its register values, then uses return-from-interrupt to resume B. This event sequence is called a context switch.

Compiler Optimizations

Assembly-language program generated by compiler may not be efficient in size or execution time An optimizing compiler applies techniques to enhance performance or reduce code size Example: Much execution time is spent in loops Optimize performance by using registers to hold value of loop index and other variables Use Load/Store instructions before/after loop

The Compiler

Assembly-language programming requires knowledge of machine-specific details. Programming in a high-level language (like C) reduces need for machine-specific knowledge. Program in high-level language must be translated into assembly language for machine. The compiler performs this translation. The assembler processes compiler output file. Just as in assembly language, use multiple files to partition a program in high-level language. Must declare external subroutines & variables. Enables checking of data types across all files. Assembler invoked for each output file, then linker combines object files (with any libraries). Compiler automates various tedious tasks, such as managing stack frames for subroutines.

Separate Processing of Object Files

Can partition one program into multiple files. Can also use subroutines defined by others. Let assembler process each file separately, making list of unknown external names. Object file augmented with list of names and list of instructions with external references. Programmer must also export names from an object file that could be used with other files.

The Linker

Combines object files into object program. Constructs map of full program in memory using length information in each object file. Map determines addresses of all names. External names matched with exported names. Instructions referring to external names are finalized with addresses determined by map. Unmatched names are reported as errors.

Two-Pass Assembler

Consider forward branch to label in program Offset cannot be found without target address Let assembler make two passes over program 1st pass: generate all machine instructions, and enter labels/addresses into symbol table Some instructions incomplete but sizes known 2nd pass: calculate unknown branch offsets using address information in symbol table

The Operating System

Coordinates all activities in a computer system. Comprises essential memory-resident routines and utility programs stored on magnetic disk that to be loaded to memory when needed. Manages processing, memory, I/O resources. Interprets user commands, allocates storage, transfers information, handles I/O operations. Loader discussed previously is part of OS. Used by OS to execute application programs.

Use of Interrupts in Operating Systems

Interrupts used extensively by OS for I/O operations. Also enable OS to assign execution priorities, switch between programs, coordinate I/O, etc. Service routines for I/O devices are part of OS. I/O requests made through library routines that raise software interrupt to enter OS. OS initiates I/O activity while program waits. Hardware interrupts signal completion to OS.

Example of Multitasking

Multitasking requires various OS capabilities. OS uses hardware timer for time slicing when managing execution of multiple programs. Each program runs for a short period, τ , called a time slice. Then another program runs for its time slice, and so on . Enables fair allocation of processor usage. OS must also support I/O requests to enable concurrent computation and I/O activity. Consider organization of OS software with initialization, scheduler, I/O routines, drivers.

Example of Multitasking 2

Now A calls I/O routine by raising software interrupt which calls OSSERVICES. OSSERVICES calls IOINIT, then KBDINIT in device driver. IOINIT: a general routine responsible for starting I/O operations Device interrupts are enabled for transfer. IOINIT then returns to OSSERVICES . SCHEDULER routine in OS then selects B. Keyboard interrupt invokes IODATA routine which polls devices to find interrupt source. Then, IODATA calls the appropriate device driver to service the request (e.g. KBDDATA, which will transfer one character of data) A made Runnable, OS lets B resume execution. After later context switch, A executes again.

The Boot-strapping Process

OS for general-purpose computer is large All parts, including memory-resident, initially on disk. At power-up, processor fetches instructions initially from permanent memory to read disk. Progressively larger programs transfer OS into memory in preparation for user commands.

Programs Using Multiple Languages

Once assembler generates an object file,original source language is less relevant. Linker combines object files & library routines for source programs written in any language. Machine-specific calling conventions define register usage and stack frames. Routines written in assembly language can call high-level language routines, and vice-versa.

The Debugger

Programming errors, or bugs, can cause an object program to produce incorrect results. The debugger enables the programmer to identify such errors at execution time. Execution can be stopped at points of interest. At such points, debugger accepts commands to display contents of registers or memory. Execution resumed until next point of interest.

The Assembly Process

Source program created using text editor. Written to file on disk for later processing. Assembler translates source file to object code. Recognizes mnemonics for OP codes. Interprets addressing modes for operands. Recognizes directives that define constants and allocate space in memory for data. Labels and names placed in symbol table.

Libraries

Subroutines that are useful in one program are often useful in other programs. Separate file assembly and linking enables reuse of source files with these subroutines. Alternatively, generate object files once and use archiver to collect them into a library file. Library includes name information to aid in resolving references from calling program.

Trace Mode

The debugger can use trace mode interrupts Service routine invoked after each instruction to enable user to inspect registers/memory. Trace mode disabled within debugger, then re-enabled upon return from interrupt.

Managing Execution of Programs

User enters command, loader transfers code and data in object file to memory to execute. To read data file on disk, request made to OS. OS and I/O activity occur while program waits. Program waits again after sending to printer. Computer resources not being used efficiently when I/O devices and processor are idle. Start execution of other application programs before initial program terminates. Concurrent processing for computation and I/O requests can result whenever possible. OS manages activity for efficient utilization. Called multiprogramming or multitasking.

Loading/Executing Object Programs

User input identifies object file on disk . Object file has information on starting location in memory and length of program. Loader transfers object program from disk to memory and branches to starting address. At program termination, loader recovers space in memory and awaits next command.

Loader

invoked when user types command or clicks on icon in graphical user interface

Breakpoints

involve placing software-interrupt instruction (aka traps) in program to enter debugger Old instruction restored to resume execution

Boot-strapping

process loads memory-resident part, enabling OS to assume control over resources

Running

program being executed

Blocked

program is not ready to resume execution for some reason (e.g. waiting I/O)

Runnable

program ready but waiting to be selected for execution


Set pelajaran terkait

Earth Science - Earth Layers, Magnetism & Plate Tectonics

View Set

MIS 111 Exam 3, MIS 111 Exam 3, MIS 111 Exam 3, MIS 111 Exam 3, MIS 111 Exam 3, MIS 111 Exam 3, MIS 111 Exam 3, MIS 111 Exam 3, MIS 111 Exam 3, MIS 111 Exam 3, MIS 111 Exam 3, MIS 111 Exam 3, Mis 111 exam 3, MIS 111 Exam 3, MIS 111 Exam 3, MIS 111 Ex...

View Set

Determine Meaning: Words and Phrases

View Set

CH 1 LEARNSMART BIOLOGICAL TRANSITIONS

View Set

8th Earth Science Ch 10 Sect. 1, 2, & 3 and Ch 8 Sect 1

View Set