Multiprogramming in 8086 Microprocessor

You might also like

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 40

SRI RAMAKRISHNA INSTITUTE OF TECHNOLOGY, COIMBATORE-10

(Approved by AICTE, New Delhi – Affiliated to Anna University, Chennai)

Department of Electronics and Communication Engineering

Introduction to
Multiprogramming
COURSE COORDINATOR
Ms.S.Dhivya,
AP/ECE,
Sri Ramakrishna Institute of Technology, CBE-10.
Process
• Unit of Programming system
• It performs an independent task.
• Based on execution of process, it can be
classified as
– Uniprogramming
– Multiprogramming
Uniprogramming
• Processes are executed in a serial fashion.
• Only one process is stored in the memory at a
time.
• Next process is not loaded for execution until
the current process is terminated.
• Processor working under this mode is to
collect data from two independent data
acquisition devices.
Multiprogramming
• Code for two or more processes is in memory
at the same time and is executed in a time
multiplexed fashion.
• Multiprogrammed single CPU system will
execute several processes simultaneously.
System Throughput
• Performance of the system is often measured
by the number of jobs finished in a period of
time.
• This is referred to as system Throughput.
System performance of a single
CPU system
Uniprogramming and
Multiprogramming Activity
Uniprogramming Activity
Uniprogramming Activity
• Process 1 begins and continues until I/O is
needed(Point A), then I/O is initiated and the
processing continues in parallel with I/O until
the processing needs the input data. It must
wait until the I/O is completed(Point B).
• When I/O is finished(Point C), the processing is
resumed.
• At the end of process 1, process 2 can begin and
its operation is the same as that of process 1.
Multiprogramming Activity
Multiprogramming Activity
• Instead of CPU being idle while it is waiting for
process 1 I/O, here process 2 can begin and
can utilize the CPU until it needs to wait for
I/O.
• At that time, if process 1 has finished its I/O
operation, it can resume its use of the CPU.
• Thus the overall processing time of the CPU
can be significantly reduced.
Process Management
• In a single processor Uniprogramming System,
two or more processes reside in the memory
and share the CPU, but the CPU can execute
only one of the processes at a time.
Process Management
• In a simple multiprogramming System, there
are three states that the processor can be in,
with each process being in exactly one of
these states at any given time. The states are
– Running
– Blocked
– Ready
Process States
• Running- Process is currently being executed by the CPU

• Blocked- Execution of the program cannot be continued as it


waiting for an event to occur.(eg. Waiting for completion of I/O
operation.)

• Ready- Execution of the Program can be resumed at any time.


(I/O process finished and to continue the process)
Process States and State Changes
Time Sharing Systems
• Time sharing systems are regulated by
programmable external timing devices known
as real time clocks.
• In this system, time is measured from the
beginning of the running state and the real
time clock sends an interrupt when the
allotted time is used.
Ready Queue
• Implementation of the ready queue depends
on the scheduling policy.
• FIFO policy will gives equal priority to all the
process.
• Here, processes are added to the bottom of
the queue and taken from the top.
• The first and last element pointer indicates the
process at the top and bottom of the queue
respectively.

• The last element pointer is needed so that


new processes can be added to the queue
without having to search for the entire queue.
Ready Queue
• When CPU switches from one running process to
another, it is necessary to monitor
– Save the machine status of the running process in the
process control block.
– Update the remainder of the PCB.
– Get the ID of the next process to run from the first element
pointer
– Delete the process that has just entered the running process.
– Change the status of the deleted process from the ready list
to running and restore the machine status of this process.
Contd.
• A process that is currently in the system can
be added to the ready list by
– Storing its process ID into fqp of the current last
element and into the last element pointer.
– Clearing the fqp in its process table entry.
– Updating its process control block.
Semaphore Operations
• In Multiprogramming systems, processes are
allowed to share common software and data
resources as well as hardware resources.
• A common resource may be accessed and
updated by only one process at a time and
other process must wait until the one
currently using the shared resource is finished
with it.
Example
• A Personnel file is shared by two processes
• Process 1 performs insertion, deletion and
changes.
• Process 2 puts the file in alphabetical order
according to last names.
• If accessed sequentially, first updating by
process 1 and then sorting by process 2 or vice
versa.
Contd.,
• If both processes were allowed to access the
file at the same time, the results would be
unpredictable and almost certainly incorrect.
• The solution of this problem is to allow one
process at a time to enter into critical section
of code( that section of code that accesses the
serially usable resource)
Mutual Exclusion
• Preventing one or more processes from
simultaneously accessing their critical sections
for accessing a shared resource.
• One way to attain mutual exclusion is to use
flags to indicate when the shared resource is
already in use.
Mutual Exclusion
• Let us consider the possibility of only one flag
• If there is only one flag and FLAG=1 indicates
that the resource is free and FLAG=0 indicates
it is busy, then two processes that access the
resource might be implemented in the
following way.
Example
• When FLAG=1, the following sequence occurs,

– The TEST instruction in process 1 is executed.


– A switch is made to process 2 before the JZ
instruction in process 1 is executed.
– The TEST instruction in process 2 is executed.
• At this point, both processes are free to enter
their critical sections of code.
• To avoid mutual exclusion, two flags can be
employed, one for process 1 and one for
process 2.
Mutual Blocking
• Before either process can enter its critical
section, it would first clear its flag to indicate
its intention and then repeatedly test the flag
associated with the other process until it
becomes 1.
• This problem can be overcome by the use of
third flag that indicates which process has the
highest priority.
XCHG instruction
• When using an 8086, a simple solution is
provided by XCHG instruction.
• The required access control can be obtained
by using a single flag and structuring the
processes as indicated.
Code using XCHG
Explanation
• If FLAG=1 when the XCHG instruction is executed,
FLAG is cleared and AL is set to 1.
• Even if the system switches processes after the XCHG
instruction, the new process cannot enter its critical
section because FLAG has already been cleared.
• This is mainly attributed to the capability of loading
and setting an operand with a single
instruction(XCHG), and can be applied to any number
of processes.
Semaphore
• A flag used to reserve a shared resource is
called a semaphore.
• The operations of requesting and releasing the
resource are commonly known as the ‘P’ and
‘V’ semaphore operators.
P and V operators
• P operator can be used easily with instructions
like MOV, XCHG, TEST and JZ instructions.
• V operator can be used with MOV instruction.
• When one process is in critical section, the
other processes that are presently competing
for the same resource will be idling in the wait
loops associated with their P operators.
Shortcomings
• In the above scenario, the significant amount
of CPU time will be wasted.
• To better utilize the CPU time, the P operator
could be modified as follows.
P operator can be modified as
Contd.,
• If the semaphore is cleared, instead of
repeating the wait loop, the monitor changes
the state of the current process to blocked
and switches a ready process to running.
V operator can be modified as
Contd.,
• Sets the Semaphore to 1.
• Allows the monitor to move those processes
which were blocked because the shared
resource was unavailable from the blocked list
to the ready list.
• The first of these processes that resumes its
execution will be able to enter its critical
section.
References
• https://
www.javatpoint.com/multiprogramming-oper
ating-system
• https://shareok.org/bitstream/handle/11244/
34776/Thesis-1981RP189s.pdf
?sequence=1 &isAllowed=y
• https://www.researchgate.net/publication/35
2901182_A_Study_Between_Intel_8085_and_
Intel_8086

You might also like