powerpoint presentation · pdf filecomputer science 1 chapter 6 ... programs primarily for...

13
10/12/2013 1 INVITATION TO Computer Science 1 1 Chapter 6 An Introduction to System Software and Virtual Machines Objectives In this chapter, you will learn about: System software Assemblers and assembly language Operating systems Invitation to Computer Science, 6th Edition 2 Objectives After studying this chapter, students will be able to: Describe the main categories of system tasks Compare the virtual machine created for the user by system software with the naked machine Explain the benefits of writing system software in assembly language, rather than machine language Read and write short assembly language programs Describe how an assembler translates assembly language programs into machine instructions Invitation to Computer Science, 6th Edition 3 Objectives (continued) After studying this chapter, students will be able to: List five key tasks of an operating system, and explain what each is and why it is critical to modern systems Describe the different generations of operating systems, what the features of each generation were, and how each generation solved a drawback of the previous generation Invitation to Computer Science, 6th Edition 4 Introduction A bare or naked machine has no tools or programs to help the user Write instructions in binary Write data in binary Load instructions into memory one cell at a time Initiate program run Too difficult for humans to do We must build an interface to hide the details and make the computer easier to build Invitation to Computer Science, 6th Edition 5 Interface Von Neumann computer “Naked machine” Hardware without any helpful user-oriented features Extremely difficult for a human to work with An interface between the user and the hardware is needed to make a Von Neumann computer usable and people oriented ( like “dashboard” on a car ) Invitation to Computer Science, 6th Edition 6

Upload: vanquynh

Post on 13-Mar-2018

213 views

Category:

Documents


1 download

TRANSCRIPT

10/12/2013

1

INVITATION TO

Computer Science 1 1

Chapter 6

An Introduction to System Software and Virtual Machines

Objectives

In this chapter, you will learn about:

• System software

• Assemblers and assembly language

• Operating systems

Invitation to Computer Science, 6th Edition 2

Objectives

After studying this chapter, students will be able to:

• Describe the main categories of system tasks

• Compare the virtual machine created for the user by

system software with the naked machine

• Explain the benefits of writing system software in

assembly language, rather than machine language

• Read and write short assembly language programs

• Describe how an assembler translates assembly

language programs into machine instructions

Invitation to Computer Science, 6th Edition 3

Objectives (continued)

After studying this chapter, students will be able to:

• List five key tasks of an operating system, and explain

what each is and why it is critical to modern systems

• Describe the different generations of operating

systems, what the features of each generation were,

and how each generation solved a drawback of the

previous generation

Invitation to Computer Science, 6th Edition 4

Introduction

• A bare or naked machine has no tools or programs

to help the user

– Write instructions in binary

– Write data in binary

– Load instructions into memory one cell at a time

– Initiate program run

• Too difficult for humans to do

• We must build an interface to hide the details and

make the computer easier to build

Invitation to Computer Science, 6th Edition 5

Interface

• Von Neumann computer

– “Naked machine”

– Hardware without any helpful user-oriented features

– Extremely difficult for a human to work with

• An interface between the user and the hardware is

needed to make a Von Neumann computer usable

and people oriented ( like “dashboard” on a car )

Invitation to Computer Science, 6th Edition 6

10/12/2013

2

Interface

• Tasks of the interface – Hide details of the underlying hardware from the

user

– Present information in a way that does not require

in-depth knowledge of the internal structure of the

system

– Allow easy user access to the available resources

– Prevent accidental or intentional damage to

hardware, programs, and data

Invitation to Computer Science, 6th Edition 7

Software

• Application software

– programs primarily for users ( word processors,

spreadsheets, databases, presentation graphics, etc.)

• System software

– primarily used to run the computer (operating

system, device drivers, assemblers, compilers )

Invitation to Computer Science, 6th Edition 8

System Software

• System software is the intermediary between the

users and hardware

– Hides complex internal structure of the Von Neumann

architecture

• Virtual Machine/Virtual Environment

– The set of services and resources created by the

software and seen by the user

Invitation to Computer Science, 6th Edition 9

System Software

• System software is a collection of programs to

– manage resources of the computer

– serve as intermediary between user and hardware

• System software creates a virtual machine (or

virtual environment) that user sees

Invitation to Computer Science, 6th Edition 10

System Software (continued)

• Operating system: central system software

– Communicates with users

– Starts up other system software and applications as

needed

• Graphical user interface (GUI), often pronounced

“gooey”

– visual interface to operating system (or other system

software/applications)

• I/O systems: communicate with various devices

Invitation to Computer Science, 6th Edition 11

Types of System Software

• System software is a collection of many different

programs

• Operating system

– Controls the overall operation of the computer

– Communicates with the user

– Determines what the user wants

– Activates system programs, applications packages, or

user programs to carry out user requests

Invitation to Computer Science, 6th Edition 12

10/12/2013

3

Types of System Software

• User interface

– Graphical user interface (GUI) provides graphical

control of the capabilities and services of the

computer

• Language services

– Assemblers, compilers, and interpreters

– Allow you to write programs in a high-level, user-

oriented language, and then execute them

Invitation to Computer Science, 6th Edition 13

Types of System Software

• Memory managers

– Allocate and retrieve memory space

• Information managers

– Handle the organization, storage, and retrieval of

information on mass storage devices

• I/O systems

– Allow the use of different types of input and output

devices

Invitation to Computer Science, 6th Edition 14

Types of System Software

• Scheduler

– Keeps a list of programs ready to run and selects the

one that will execute next

• Utilities – Collections of library routines that provide services

either to user or other system routines

Invitation to Computer Science, 6th Edition 15

System Software (continued)

• Language services: support high level languages

• Memory managers: allocate memory to programs

• Information managers: organize mass storage

• Scheduler: manage programs waiting to run

• Utilities: tools, including program libraries

Invitation to Computer Science, 6th Edition 16

System Software (continued)

Naked machine:

1. Write program in binary

2. Load instructions one-by-

one into memory

3. Insert start into memory

address 0 and push “go”

button

4. Read results from

memory one-by-one, in

binary

Virtual machine:

1. Write program using text

editor in high-level

language

2. Save program to folder

3. Use translator to convert

to binary

4. Use scheduler to load

and run

5. Use I/O system to print

results

Invitation to Computer Science, 6th Edition 17

What’s the Problem with Machine

Language?

• Written from machine’s view

• Complicated, difficult to understand

• Program is written, loaded, debugged in binary - no

English-like words

• Allows only numeric memory addresses

• Difficult to read and change

• Difficult to create data

Invitation to Computer Science, 6th Edition 18

10/12/2013

4

Assembly Language

• Assembly language

– Designed to overcome shortcomings of machine

languages

– Create a more productive, user-oriented

environment

– Earlier termed second-generation languages

– Now viewed as low-level programming languages

Invitation to Computer Science, 6th Edition 19

Assembly Language

• Second-generation language

• Uses mnemonics to represent machine language

opcodes

• Uses symbolic memory addresses

• Provides data generation operations

• Format:

label: opcode address --comment

Invitation to Computer Science, 6th Edition 20

Assemblers and Assembly Language

• Assembly language

– Instructions map one-to-one to machine language

– Symbolic op codes (not binary)

– Symbolic addresses for instructions and data

– Pseudo-ops for data generation and more (data in

human-friendly terms)

• Assembly = a low-level programming language

• Java, C, C++, VB, Python = high-level

programming languages

Invitation to Computer Science, 6th Edition 21 Invitation to Computer Science, 6th Edition 22

Assemblers and Assembly Language

• Source program – An assembly language program

• Object program – A machine language program

• Assembler – Translates source program into an object program

Assembly language process:

• Source program, in assembly language

• Translated by the assembler to

• Object program, in machine language

• Loader places in memory

• Hardware runs

Invitation to Computer Science, 6th Edition 23 Invitation to Computer Science, 6th Edition 24

10/12/2013

5

Assemblers and Assembly Language

(continued)

Example Assembly language:

NEXTSTEP: LOAD X -- Put X into reg. R

label: opcode address field -- comment

• Label is optional name for this instruction’s location

• Op code mnemonic and address field translate to

machine language

• Comments are ignored by assembler, just for

human use

Invitation to Computer Science, 6th Edition 25 Invitation to Computer Science, 6th Edition 26

Assemblers and Assembly Language

(continued)

Advantages over machine code:

• Clarity, readability, and maintainability

• Can be placed at different locations in memory

• Pseudo-op: commands in the program directed to

the assembler, not converted to machine

instructions

– .BEGIN and .END to mark where instructions are

– .DATA to mark memory location as holding data:

COUNTER: .DATA 0

X: .DATA 12

Invitation to Computer Science, 6th Edition 27

Examples of Assembly Language

Instructions

• Assembly language translation

LOAD ONE --Put a 1 into register R.

STORE X --Store the constant 1 into X

:

INCREMENT X --Add 1 to Value in memory

location X

:

I: .DATA 0 --The index value. Initially it is 0

ONE: .DATA 1 --The constant 1.

Invitation to Computer Science, 6th Edition 28

Examples of Assembly Language

Instructions

• Assigns name to address where data is stored

• Converts data value to proper binary representation

• Example:

FIVE: .DATA +5

NEGSEVEN: .DATA -7

LOAD FIVE

ADD NEGSEVEN

• Arithmetic expression

A = B + C – 7

(Assume that B and C have already been assigned values)

Invitation to Computer Science, 6th Edition 29

Examples of Assembly Language

Instructions • Assembly language translation

.BEGIN

LOAD B --Put the value B into register R.

ADD C --R now holds the sum (B + C).

SUBTRACT SEVEN --R now holds the expression (B + C - 7).

STORE A --Store the result into A.

: -- Data should be placed after the HALT

A: .DATA 0

B: .DATA 0

C: .DATA 0

SEVEN: .DATA 7 --The constant 7

.END

Invitation to Computer Science, 6th Edition 30

10/12/2013

6

Invitation to Computer Science, 6th Edition 31

Assemblers and Assembly Language

Simple examples:

x = y + 3

input a and b

while a > b do

print a

a = a – 2

LOAD Y

ADD THREE

STORE X

… -- Data comes after .END

X: .DATA 0 -- X is initially 0

Y: .DATA 5 – Y is initially 5

THREE: .DATA 3 –The constant 3

IN A

IN B

LOOP1: LOAD A A: .DATA 0

COMPARE B B: .DATA 0

JUMPLT LOOP1END TWO: .DATA 2

JUMPEQ LOOP1END

OUT A

LOAD A

SUBTRACT TWO

STORE A

JUMP LOOP1

LOOP1END: …

Invitation to Computer Science, 6th Edition 32

Example – Summing Numbers

• 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 values and stop

Invitation to Computer Science, 6th Edition 33 Invitation to Computer Science, 6th Edition 34

35

Assemblers and Assembly Language

Translation and loading:

• Assembler translates to machine language

– Convert symbolic op codes to binary equivalents

– Convert symbolic labels to memory addresses

– Perform pseudo-op actions

– Write object file containing machine instructions

• Loader gets program ready to run

– Places instructions in memory

– Triggers the hardware to run the program

Invitation to Computer Science, 6th Edition 36

10/12/2013

7

Assemblers and Assembly Language

Converting symbolic op codes to binary ones

• Assembler maintains a table

• Assembler looks up symbolic op codes in the

table and substitutes the binary analogue

• Use binary search to optimize table lookups

37

Assemblers and Assembly Language

Converting symbolic labels to memory addresses

• Assembler needs two passes

– looks over assembly code two times

• First pass:

– Keep a count of how many instructions from the

start

– Collect symbolic labels and add to symbol table

along with location counter

Invitation to Computer Science, 6th Edition 38

Invitation to Computer Science, 6th Edition 39 40

Assemblers and Assembly Language

(continued)

• Second pass:

– Look up and replace op codes

– Substitute label references with location from symbol

table

– Set up .DATA pseudo-ops with location and binary value

– Write instructions to object file

Invitation to Computer Science, 6th Edition 41 42

10/12/2013

8

Invitation to Computer Science, 6th Edition 43

Translation and Loading

• The object program becomes the input to another piece of

software – the loader

• The loader reads instructions from the object file and stores

them in memory for execution

• To do this it reads and address and stores the machine

instruction into the specified memory address.

• After the instructions are loaded into memory, the loader

places the address of the first instruction (0 in our example)

into the program counter (PC) .

• The computer fetches, decodes and executes the program

starting with the instruction, whose address is in the PC.

Invitation to Computer Science, 6th Edition 44

Operating Systems

• What is an operating system?

– A library of programs that make a computer

• Easier to user for the user

• Use resources more efficiently

– It can also be viewed as:

• A Government – making policy and rules

• An Environment – in which users write and run programs

• A Resource allocator

• A Security guard

• A Traffic cop

• A Wizard – providing “illusions”

Invitation to Computer Science, 6th Edition 45

Purpose of an Operating System

• The primary purposes of an Operating

System are:

• Ease of use for the user

• Efficient use of the system resources

• Operating system

– Waits for requests and activates other system

programs to service these requests

• System commands

– Used to translate, load, and run programs

Invitation to Computer Science, 6th Edition 46

Operating Systems

• System commands:

- user instructions about what the computer should do

Invitation to Computer Science, 6th Edition 47

Operating Systems (continued)

• User interface: user communicates with operating

system

• Operating system as receptionist and dispatcher

• User command system software scheduled and

runrepeat

• Text-based:

– System commands typed at a prompt in a terminal

– Command language must be learned

• GUI-based:

– System commands by visual/mouse interface

Invitation to Computer Science, 6th Edition 48

10/12/2013

9

GUIs

Invitation to Computer Science, 6th Edition 49

Example of a Graphical User Interface

Invitation to Computer Science, 6th Edition 50

51

Operating Systems

• System security and protection: permit only

authorized access to resources

• Operating system as security guard

• Access protected by usernames and passwords

– Superusers have more privileges

– Encrypt data to increase security

• Folders and files have authorization lists:

– read a file, add new information to a file, change

existing information, delete a file

Invitation to Computer Science, 6th Edition 52

Invitation to Computer Science, 6th Edition 53

Operating Systems (continued)

• Efficient allocation of resources: keep CPU busy

and all programs making progress

• Operating system as traffic cop

• Multiple programs active at one time

• Every program is in one of three states:

– Running: program currently using the CPU

– Waiting: programs waiting for I/O operations to

complete

– Ready: programs ready for a turn on CPU

• Keep a queue of ready programs and share

Invitation to Computer Science, 6th Edition 54

10/12/2013

10

Operating Systems (continued)

Example of sharing CPU: Waiting Ready Running

B A

C

A makes I/O request Waiting Ready Running

A C B

A finishes with I/O Waiting Ready Running

C B

A

Invitation to Computer Science, 6th Edition 55

Operating Systems

• Safe use of resources: ensure that computer

doesn’t get stuck in deadlock

• Multiple programs requesting access to resources

• Deadlock occurs when all programs have some

resources, and are waiting for resources held by

others

• Deadlock prevention: if you can’t get all resources,

release all you have and try again later

• Deadlock recovery: if no acknowledgement, send

message again

Invitation to Computer Science, 6th Edition 56

Summary of OS Responsibilities

• Major responsibilities of operating systems

– User interface management (a receptionist)

– Control of access to system and files (a security

guard)

– Program scheduling and activation (a dispatcher)

– Efficient resource allocation (an efficiency

expert)

– Deadlock detection and error detection (a traffic

officer)

Invitation to Computer Science, 6th Edition 57

Operating Systems

Historical development of operating systems

• First generation: (1945–1955)

• Nearly “naked computer”

– No operating systems

– Assemblers and loaders were almost the only system

software provided

– Programmer hand-loaded programs

Invitation to Computer Science, 6th Edition 58

Operating Systems

• Second generation: (1955–1965)

• Batch operating system

– Programmers gave programs to operators

– Operators collects a “batch” of programs

• Used I/O computer to translate programs to tape

• Ran programs as a group

• Used I/O computer to translate output to text/paper

– Job control language: instructions to OS

– Ran collections of input programs one after the other

– Command language -specifying the operation

Invitation to Computer Science, 6th Edition 59

10/12/2013

11

Operating Systems

• Third-generation operating systems(1965–1985)

• Multiprogrammed operating systems

– Time sharing systems

– Permitted multiple user programs to run at once

– User operation codes: could be included in any user

program

– Privileged operation codes: use restricted to the

operating system or other system software (eg. HALT

instruction) ( Why can’t users execute this on a multiuser

system?)

Invitation to Computer Science, 6th Edition 62

Operating Systems (continued)

• Third generation:

• Multiprogrammed operating systems

– Switch between programs when I/O happens

– Computer security now required!

• Privileged operations only available to administrator

• Bound memory a program can legitimately access

Invitation to Computer Science, 6th Edition 63

Operating Systems (continued)

• Time-sharing system (also third generation)

– Multiprogrammed, but users are on system

interactively

– Users need illusion of sole access

– Allocate run time in time slices. Each program runs

until I/O OR time runs out

Invitation to Computer Science, 6th Edition 64

Invitation to Computer Science, 6th Edition 65

Operating Systems (continued)

• Fourth generation: ( 1985- present)

• Network operating system

– Operating system supports all the same local services

– Also supports services that access resources that are

available over a network • Shared printer

• Servers: e-mail, data, web

• Connections to Internet

– Real-time operating system or embedded system are

special-purpose computers in other equipment

– Distributed environment - computing done remotely in

the office, laboratory, classroom, and factory

Invitation to Computer Science, 6th Edition 66

10/12/2013

12

Operating Systems

• Fourth Generation (1985-Present)

– Real-time operating system

• Manages resources of embedded computers that are

controlling ongoing physical processes

• Guarantees that it can service important requests

within a fixed amount of time

– Virtual environment

• treats resources physically residing on the computer in

the same way as resources available through the

computer’s network

Invitation to Computer Science, 6th Edition 67 Invitation to Computer Science, 6th Edition 68

Invitation to Computer Science, 6th Edition 69

Operating Systems (continued)

• Fifth generation, the near future

– Multimedia interfaces (integrate images, speech,

video seamlessly)

– Parallel processing system, to perform multimedia

and to permit larger scale tasks

– Distributed computing environment, users don’t

know where resources are stored

• Cloud computing

Invitation to Computer Science, 6th Edition 70

Invitation to Computer Science, 6th Edition 71

10/12/2013

13

Summary

• System software creates a virtual machine that is

easy for users to use

• Assemblers and loaders are system software:

translate human-friendly programs to machine

language

• Assembly language uses symbolic names,

symbolic op codes, and pseudo-ops to describe

algorithms

• Assembler translates source programs to object

files; loader places object instructions in memory

Invitation to Computer Science, 6th Edition 73

Summary (continued)

• Operating systems communicate with users

through text or GUI actions

• The operating system includes key tasks such as:

the user interface, system security, scheduling of

programs, allocating resources and system safety

• Operating systems developed through four

generations of improvements, each adding new

features and improving efficiency

• Future operating systems: parallel, distributed, and

multimedia, with resources stored remotely

Invitation to Computer Science, 6th Edition 74