l13 comp func

20
Computer Function Th e basic operation performed by a computer is  program execution. The p ro gram is not hin g bu t set of ins tr uct io ns store d in memory. CPU does the processing by executing each instructions specified in the program. Inst ru ct ion pro cessi ng co nsi st of two steps: 1. Rea ding (fe tching) ins tructi on from memo ry by CP U 2. Execut ion of each f etche d i nst ruc ti on Pro gram exec ut ion con si sts o f re peatin g t he process of instruction fetch and instruction executio n.

Upload: domainname9

Post on 08-Apr-2018

236 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: L13 Comp Func

8/6/2019 L13 Comp Func

http://slidepdf.com/reader/full/l13-comp-func 1/20

Computer Function

� The basic operation performed by a computer is

 program execution.

� The program is nothing but set of instructions storedin memory. CPU does the processing by executing

each instructions specified in the program.

� Instruction processing consist of two steps:

1. Reading (fetching) instruction from memory by CPU

2. Execution of each fetched instruction

� Program execution consists of repeating the process

of instruction fetch and instruction execution.

Page 2: L13 Comp Func

8/6/2019 L13 Comp Func

http://slidepdf.com/reader/full/l13-comp-func 2/20

Basic Instruction Cycle

Instruction Cycle� The processing required for a single instruction is called an

instruction cycle.� It consists of two steps:

Fetch cycle Execute cycle

� Program execution halts only if the machine is turned off, or 

some unrecoverable error occurs or because of some program

instruction halts the computer.

Page 3: L13 Comp Func

8/6/2019 L13 Comp Func

http://slidepdf.com/reader/full/l13-comp-func 3/20

The Fetch Cycle & Execute Cycle

� CPU fetches an instruction from memory, a register 

called Program Counter (PC) is used to hold the

address of next instruction to fetch.

� CPU increments the PC after each instruction fetch,unless told otherwise.

� The fetched instruction is loaded into a register in

CPU known as Instruction Register (IR).

� CPU interprets the instruction and performs the

required action.

Page 4: L13 Comp Func

8/6/2019 L13 Comp Func

http://slidepdf.com/reader/full/l13-comp-func 4/20

The actions may involve four steps:

� CPU-memory

Data transfer between CPU and main memory.

� CPU-I/O

Data transfer to or from outside world by transferring

 between CPU and I/O module.

� Data processing

Some arithmetic or logical operation on data.

� Control

An instruction may specify alteration of sequence of 

execution, e.g. jump

Page 5: L13 Comp Func

8/6/2019 L13 Comp Func

http://slidepdf.com/reader/full/l13-comp-func 5/20

Example of Program Execution

Page 6: L13 Comp Func

8/6/2019 L13 Comp Func

http://slidepdf.com/reader/full/l13-comp-func 6/20

� Execution cycle for a particular instruction

may involve more than one reference tomemory or it may specify an I/P operation.

� So a detailed state diagram of instruction is

as follows.

Page 7: L13 Comp Func

8/6/2019 L13 Comp Func

http://slidepdf.com/reader/full/l13-comp-func 7/20

Page 8: L13 Comp Func

8/6/2019 L13 Comp Func

http://slidepdf.com/reader/full/l13-comp-func 8/20

� I nstruction Address Calculation (iac): Determines address of 

next instruction to be executed.

� I nstruction Fetch (if): Read instruction from memorylocation into CPU.

� I nstruction Operation Decoding (iod): Determines the type

of operation to be performed and operands to be used.

� Operand Address Calculation (oac): Determines the addressof operand (operand may be referenced from memory or 

available via I/O) .

� Operand Fetch (of): Fetches the operand from memory or 

reads it from I/O.

�  Data Operation (do): Performs the operation indicated in

instruction.

� Operand Store (os): write the result into memory or to I/O.

Page 9: L13 Comp Func

8/6/2019 L13 Comp Func

http://slidepdf.com/reader/full/l13-comp-func 9/20

Interrupts

� A signal informing a program that an event has occurred.

� All computers provide a mechanism by which other modules may

interrupt the normal processing of CPU.

� List of common classes of interrupts are :

1. Program: Generated by some condition that occurs

 because of an instruction execution. E.g. arithmetic

overflow, division by zero, reference outside a user¶s

allowed memory space.

2. Timer: Generated by timer within the processor.

3. I/O: Generated by I/O controller 

4. Hardware failure: Generated by a failure such as power 

failure or memory parity error.

Page 10: L13 Comp Func

8/6/2019 L13 Comp Func

http://slidepdf.com/reader/full/l13-comp-func 10/20

� Interrupts are provided primarily to improve processing

efficiency.� From the point of view of user program, an interrupt is just

an interruption of normal sequence of execution.

� If the CPU is idle, interrupt is served.

� When interrupt processing is completed, execution resumes.

� The processor and the operating system are responsible for 

suspending the user program and then resuming it at the same

 point.

Page 11: L13 Comp Func

8/6/2019 L13 Comp Func

http://slidepdf.com/reader/full/l13-comp-func 11/20

Interrupt Cycle

� Added to instruction cycle

� Processor checks for interrupt

   Indicated by presence of an interrupt signal

� If no interrupt, fetch next instruction

� If interrupt pending:

   Suspend execution of current program.

   Save context. i.e. save the address of next instruction

to be executed (in current program) and any other data

relevant to processor¶s current activity.   Set PC to start address of interrupt handler routine

   Process interrupt

   Restore context and continue interrupted program

Page 12: L13 Comp Func

8/6/2019 L13 Comp Func

http://slidepdf.com/reader/full/l13-comp-func 12/20

Page 13: L13 Comp Func

8/6/2019 L13 Comp Func

http://slidepdf.com/reader/full/l13-comp-func 13/20

Page 14: L13 Comp Func

8/6/2019 L13 Comp Func

http://slidepdf.com/reader/full/l13-comp-func 14/20

Page 15: L13 Comp Func

8/6/2019 L13 Comp Func

http://slidepdf.com/reader/full/l13-comp-func 15/20

Multiple interrupts

� How to handle multiple (more than one) interrupt.� E.g. if a program receives data from a communication line

and prints the result. The printer will generate interrupt

every time it completes a print operation. The

communication line controller will generate interrupt every

time a unit of data arrives.

� Here it is possible for a communication interrupt to occur 

while a printer interrupt is being processed.

� There are 2 ways to handle them.

Page 16: L13 Comp Func

8/6/2019 L13 Comp Func

http://slidepdf.com/reader/full/l13-comp-func 16/20

Page 17: L13 Comp Func

8/6/2019 L13 Comp Func

http://slidepdf.com/reader/full/l13-comp-func 17/20

Page 18: L13 Comp Func

8/6/2019 L13 Comp Func

http://slidepdf.com/reader/full/l13-comp-func 18/20

Page 19: L13 Comp Func

8/6/2019 L13 Comp Func

http://slidepdf.com/reader/full/l13-comp-func 19/20

Example of multiple interrupts (considering priorities):

We have a system with 3 I/O devices: a printer, a disk, and a

communication line, with priorities of 2, 4, 5 respectively.

At t=0, user program begins.

At t=10, a printer interrupt occurs

At t=15, a communications interrupt occurs

At t=25, a disk interrupt occurs

Transfer of control occurs in a manner as shown in next figure.

Page 20: L13 Comp Func

8/6/2019 L13 Comp Func

http://slidepdf.com/reader/full/l13-comp-func 20/20