COA CH 3
COA CH 3
2
I. Memory
There are two type of memory unit
1. Primary memory
2. Secondary memory
Primary memory
RAM - Random Access Memory, the data are stored in RAM, it can only store when power is ON. The memory
Megabyte(MB) = 220
memory.
If ROM memory is erased the entire system will crashed.
Secondary memory
External memory are called secondary memory. Eg – hard disk , pen drive, CD etc
instruction.
The major operations performed by the ALU are addition, subtraction,
After processing, the output is returned back to storage unit for further
The control unit determines the sequence in which computer programs and instructions are
executed.
Things like processing of programs stored in the main memory, interpretation of the instructions
and issuing of signals for other units of the computer to execute them.
The task of the control unit is to execute programs by repeatedly:
Execute it by issuing the appropriate signals to the ALU, memory, and I/O subsystems.
device.
The input are in the form of human understandable format, then it convert to system
Output unit sends processed results to the outside world. Examples: Display screens 8
Control unit; instruction fetch, decode, and execution
9
Control unit; instruction fetch, decode, and execution
Once the data are loaded into main memory (RAM) by the operating system.
1. Fetch
The first step the CPU carries out is to fetch some data and instructions (program) from main
memory then store them in its own internal temporary memory areas. These memory areas are called
“registers”.
This is called the 'fetch' part of the cycle.
For this to happen, the CPU makes use of a vital hardware path called the 'address bus'.
The CPU places the address of the next item to be fetched on to the address bus.
Data from this address then moves from main memory into the CPU by travelling along another
The CPU is designed to understand a specific set of commands. These are called
The CPU decodes the instruction and prepares various areas within the chip in
The instruction sets is the part of the processor that is visible to the
opcode.
Source operand reference: The operation may involve one or more source
operands, that is, operands that are inputs for the operation.
Result operand reference: The operation may produce a result.
Next instruction reference: This tells the processor where to fetch the next
being executed.
I/O device: The instruction must specify the I/O module and device for the
operation. 15
Instruction sets and types (data manipulation, control, I/O)
Instruction Representation
The instruction is divided into fields, corresponding to the constituent
elements of the instruction.
A simple example of an instruction format is shown below
18
Instruction sets and types (data manipulation, control, I/O)
Advantages and Disadvantages
Stack
Disadvantages: A stack can't be randomly accessed This makes it hard to generate eficient code.
Accumulator
Disadvantages: The accumulator is only temporary storage so memory traffic is the highest for this
approach.
GPR
Advantages: Makes code generation easy. Data can be stored for long periods in registers.
Data storage: Movement of data into or out of register and or memory locations.
Logic (Boolean) instructions operate on the bits of a word as bits rather than as numbers;
I/O instructions are needed to transfer programs and data into memory and the results of
Test instructions are used to test the value of a data word or the status of a computation. 20
Assembly/machine language programming
Each personal computer has a microprocessor that manages the computer's arithmetical,
like getting input from keyboard, displaying information on screen and performing
various other jobs.
These set of instructions are called 'machine language instructions'.
Low Level languages are further divided in to Machine language and Assembly language.
21
Assembly/machine language programming
Low Level Languages
The term low level means closeness to the way in which the machine has been built.
Low level languages are machine oriented and require extensive knowledge of
computer hardware and its configuration.
Machine Language
Machine Language is the only language that is directly understood by the
computer.
It does not needs any translator program.
We also call it machine code and it is written as strings of 1’s (one) and 0’s (zero).
It is efficient for the computer but very inefficient for programmers.
It is considered to the first generation language.
It is also difficult to debug the program written in this language.
22
Assembly/machine language programming
Advantages of Machine Language
The only advantage is that program of machine language run very fast because no
translation program is required for the CPU.
Disadvantages of Machine Language
It is very difficult to program in machine language. The programmer has to know
details of hardware to write program.
The programmer has to remember a lot of codes to write a program which results in
program errors.
It is difficult to debug the program.
23
Assembly/machine language programming
Assembly Language
It is the first step to improve the programming structure.
The computer should handle numbers and letter.
Therefore some combination of letters can be used to substitute for
number of machine codes.
The set of symbols and letters forms the Assembly Language and a
translator program is required to translate the Assembly Language to
machine language.
This translator program is called `Assembler’.
It is considered to be a second-generation language.
24
Assembly/machine language programming
Assembly Language Elements
I. LABEL: If a label is present, the assembler defines the label as equivalent to the address into
which the first byte of the object code generated for that instruction will be loaded.
II. MNEMONIC: The mnemonic is the name of the operation or function of the assembly
language statement.
III. OPERAND(S): An assembly language statement includes zero or more operands.
Each operand identifies an immediate value, a register value, or a memory location.
IV. COMMENT: All assembly languages allow the placement of comments in the program.
A comment can either occur at the right-hand end of an assembly statement or can occupy an
entire text line.
25
Assembly/machine language programming
Advantages of Assembly Language
The symbolic programming of Assembly Language is easier to understand
and saves a lot of time and effort of the programmer.
It is easier to correct errors and modify program instructions.
Assembly Language has the same efficiency of execution as the machine
level language. Because this is one-to-one translator between assembly
language program and its corresponding machine language program.
Disadvantages of Assembly Language
One of the major disadvantages is that assembly language is machine
dependent.
A program written for one computer might not run in other computers with
different hardware configuration.
26
Assembly/machine language programming
HIGH LEVEL LANGUAGES
In higher level language you have to know only the instructions in English
words and logic of the problem irrespective of the type of computer you are
using.
Higher level languages are simple languages that use English and
mathematical symbols like +, -, %, / etc. for its program construction.
Higher level language has to be converted to machine language for the
computer to understand.
Higher level languages are problem-oriented languages because the
instructions are suitable for solving a particular problem.
E.g. COBOL (Common Business Oriented Language), FORTRAN (Formula
Translation) and BASIC (Beginners All-purpose Symbolic Instruction Code),
27
Assembly/machine language programming
Advantages of High Level Languages
Higher level languages have a major advantage over machine and assembly
languages that higher level languages are easy to learn and use.
It is because that they are similar to the languages used by us in our day to
day life.
28
Instruction formats
A computer will usually have a variety of instruction code formats.
It is the function of the control unit within the CPU to interpret each
instruction code and provide the necessary control functions needed to
process the instruction.
The bits of the instruction are divided into groups called fields.
The most common fields found in instruction formats are:
1. Mode field: Specifies the way the effective address is determined
2. Operation code: Specifies the operations to be performed.
3. Address field: Designates a memory address or a processor register
29
Instruction formats
Most computers fall into one of 3 types of CPU organizations:
i. Single accumulator organization
ii. General register organization
iii. Stack organization
Instruction operation types
Three Address Instructions: Two Address Instructions:
ADD R1, A, Bie., R1 M[A] + M[B] MOV R1, A ie., R1 M[A]
ADD R2, C, D i.e., R2 M[C] + M[D] ADD R1, B i.e., R1 R1 + M[B]
MUL X, R1, R2 i.e., M[X] R1 * R2 MOV R2, C ie., R2 M[C]
It is assumed that the computer has two ADD R2, D i.e., R2 R2 + M[D]
processor registers, R1, and R2. MUL R1, R2 i.e., R1 R1 * R2
The symbol M[A] denotes the operand at MOV X, R1 i.e., M[X] R1
memory address symbolized by A.
30
Instruction formats
Instruction operation types
Zero Address Instructions:
One Address Instructions: (TOS stands for top of stack)
LOAD A i.e., AC M[A] PUSH A i.e., TOS A
ADD B i.e., AC AC + M[B] PUSH B i.e., TOS B
STORE T i.e., M[T] AC ADD i.e., TOS ( A + B )
LOAD C i.e., AC M[C] PUSH C i.e., TOS C
ADD D i.e., AC AC + M[D] PUCH D i.e., TOS D
MUL T i.e., AC AC * M[T] ADD i.e., TOS ( C + D )
STORE X i.e., M[X] AC MUL i.e., TOS ( C + D ) * ( A + B )
All operations are done between the AC POP X i.e., M[X] TOS
register and a memory operand. A stock organized computer does not use an
T is the address of a temporary memory address field for the instructions ADD and MUL.
location required for storing the The PUSH and POP instructions, however, need an
intermediate result. address field to specify the operand that
communicates with the stack.
31
Addressing modes
An operation field of an instruction specifies the operation to be performed.
This operation must be executed on some data stored in computer register or
memory.
The way the operand is chosen data during the program execution are referred as
Addressing modes
The most common addressing techniques:
We Use The Following Notation
A = contents of an address field in the instruction
R = contents of an address field in the instruction that refers to a register
EA = actual (effective) address of the location containing the referenced
operand
(X) = contents of memory location X or register X
32
Addressing modes
The most common addressing techniques:
Algorithm: EA = A
Algorithm: operand = A The address field of the instruction contains the
The operand is contained within the effective address of the operand
instruction itself No calculations are required
Data is a constant at run time Address is a constant at run time but data itself can be
Advantage: No additional memory changed during program execution
references are required after the Advantage: One additional memory access is required
fetch of the instruction itself to fetch the operand
Disadvantage: Size of the operand Disadvantage: Address range limited by the width of
the field that contains the address reference
(thus its range of values) is limited
33
Addressing modes
The most common addressing techniques:
Algorithm: EA = ( A )
The address field in the instruction specifies a memory location which contains
the address of the data
Two memory accesses are required
» The first to fetch the effective address
» The second to fetch the operand itself
Advantage: Range of effective addresses is equal to 2n, where n is the width of
the memory data word i.e, large address space.
Disadvantage: instruction execution requires two memory references to fetch the
operand
34
Addressing modes
The most common addressing techniques:
D. Register-based addressing modes E. Register-Indirect addressing modes
Registers
Memory
Algorithm: EA = R Register
Register addressing: like direct, but
address field specifies a register Algorithm: EA = ( R )
location Register indirect: like indirect, but address field
No memory reference specifies a register that contains the effective address
Faster access to data, smaller address advantages: Large address space
fields in the instruction word disadvantage: extra memory reference
35
Addressing modes
The most common addressing techniques:
Memory
Register
Algorithm: EA = A + (R)
Two address fields in the instruction are used
» One is an explicit address reference
» The other is a register reference
» EA = A + (R) 36
Addressing modes
The most common addressing techniques:
37
Addressing modes
The most common addressing techniques:
G. STACK: Instruction
Implicit
Top of stack register
40
I/O and interrupts
The mechanism by which other system modules may interrupt the normal
processing of the CPU.
These devices are 1-10 orders of magnitude slower than the CPU
CPU can waste vast amounts of processing cycles waiting for these slow
devices to perform their tasks
Interrupts let the CPU execute its normal instruction sequence and pause to
service the external devices only when they signal (the interrupts) that they are
ready for the CPU’s attention.
The processor and the O/S are responsible for recognizing an interrupt,
suspending the user program, servicing the interrupt, and then resuming the
user program
41
I/O and interrupts
Transfer of control via interrupts
42
I/O and interrupts
Transfer of control via interrupts
Interrupts are processed in an interrupt cycle within the overall instruction
cycle
At the end of an instruction cycle (operand storage step), check to see if any
interrupts are pending
If there aren’t any, proceed with the next instruction
If there are
» Suspend execution of the program and save its “state”
» Jump to the interrupt service routine(ISR) and resume the “normal”
instruction cycle
» When the ISR is completed, restore the state of the program and resume
its operation 43
I/O and interrupts
Multiple Interrupts
A typical system can support several to several dozen interrupts
How should the system respond if more than 1 interrupt occurs at the same time?
» Systems prioritize the various interrupts
» At the start of the interrupt cycle, the highest priority pending interrupt will be
serviced
» Remaining interrupt requests will be serviced in turn
What if an interrupt occurs while an ISR is being executed (a result of a previous
interrupt)
» Ignore the second interrupt (by disabling interrupts) until the ISR completes -- e.g.,
MC68HC11 microcontroller
» Recognize and service the interrupt only if it has a higher priority than the one
currently being serviced -- e.g., 8085
44
I/O and interrupts
Transfer of control with multiple interrupts
45