0% found this document useful (0 votes)
117 views45 pages

COA CH 3

Uploaded by

Bifa Hirpo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
117 views45 pages

COA CH 3

Uploaded by

Bifa Hirpo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 45

Chapter-3: Assembly level machine organization

 Basic organization of the von Neumann machine


 Von-Neumann proposed his computer architecture design in 1945 which was later known as
Von-Neumann Architecture.
 It consisted of a Control Unit, Arithmetic, and Logical Memory Unit (ALU), Registers and
Inputs/Outputs.
 Von Neumann architecture is based on the stored-program computer concept, where
instruction data and program data are stored in the same memory.
 This design is still used in most computers produced today.
 General Architecture of von Neumann Machine
 Memory;
 Arithmetic Logic Unit;
 Control Unit;
 Input/output 1
Basic organization of the von Neumann machine

2
I. Memory
 There are two type of memory unit

1. Primary memory
2. Secondary memory
 Primary memory

 Internal memory are called primary memory. Eg – RAM,ROM.

 In primary memory size is small and fast memory.

 RAM - Random Access Memory, the data are stored in RAM, it can only store when power is ON. The memory

will be erased when the system is OFF.


 Measurements about RAM Size & Speed - Memory sizes:

 Kilobyte (KB) = 210

 Megabyte(MB) = 220

 Gigabyte (GB)= 230 3


I. Memory
 ROM – Read Only Memory, system boot up files are stored in ROM, we can’t use this

memory.
 If ROM memory is erased the entire system will crashed.

 Primary memory is a volatile memory.

 Secondary memory

 External memory are called secondary memory. Eg – hard disk , pen drive, CD etc

 Secondary memory is permanent memory lager size and low cost.

 It is a non volatile memory.

 Memory access time (read from/ write to memory)

 50-75 nanoseconds (1 nsec. = 0.000000001 sec.) 4


II. Arithmetic/Logic Unit
 Arithmetic Logical Unit performs the actual processing of data and

instruction.
 The major operations performed by the ALU are addition, subtraction,

multiplication, division, logic and comparison.


 Data is transferred to ALU from storage unit when required.

 After processing, the output is returned back to storage unit for further

processing or getting stored.


 It is the heart of the computer. 5
II. Arithmetic/Logic Unit
 The ALU (Arithmetic/Logic Unit) performs

 Mathematical operations (+, -, x, /, …)

 Logic operations (=, <, >, and, or, not, ...)

 ALU Consists of:

 Circuits to do the arithmetic/logic operations.

 Registers (fast storage units) to store intermediate computational results.

 Bus that connects the two.


6
III. Control unit:
 The Control Unit, which acts like the supervisor seeing whether things are done in proper fashion.

 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:

 Fetch from memory the next instruction to be executed.

 Decode it, that is, determine what is to be done.

 Execute it by issuing the appropriate signals to the ALU, memory, and I/O subsystems.

 Continues until the HALT instruction


7
IV. Input/output device
 A computer must receive both data and program statements to function properly and be

able to solve problems.


 The method of feeding data and programs to a computer is accomplished by an input

device.
 The input are in the form of human understandable format, then it convert to system

format that is 0 and 1.


 Computer input devices read data from a source, such as magnetic disks, and translate that

data into electronic impulses for transfer into the CPU.


 Some typical input devices are a keyboard, a mouse, or a scanner.

 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.

 The CPU is now ready to do some work.

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

hardware path called the 'data bus'. 10


Control unit; instruction fetch, decode, and execution
2. Decode
 The next step is for the CPU to make sense of the instruction it has just fetched.

 This process is called 'decode'.

 The CPU is designed to understand a specific set of commands. These are called

the 'instruction set' of the CPU.


 Each make of CPU has a different instruction set.

 The CPU decodes the instruction and prepares various areas within the chip in

readiness of the next step.


11
Control unit; instruction fetch, decode, and execution
3. Execute
 This is the part of the cycle when data processing actually

takes place. The instruction is carried out upon the data


(executed).
 The result of this processing is stored in yet another register.

 Once the execute stage is complete, the CPU sets itself up to

begin another cycle once more. 12


Instruction sets and types (data manipulation, control, I/O)
 The operation of the processor is determined by the instructions it

executes, referred to as machine instructions or computer instructions.


 The collection of different instructions that the processor can execute is

referred to as the processor’s instruction set.


 Instruction sets:- the interface between compilers and the machine.

 The instruction sets is the part of the processor that is visible to the

programmer or compiler writer.


 The instruction sets serves as the boundary between software and hardware.
13
Instruction sets and types (data manipulation, control, I/O)
 Elements of a Machine Instruction

 Operation code: Specifies the operation to be performed (e.g., ADD, I/O).

 The operation is specified by a binary code, known as the operation code, or

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

instruction after the execution of this instruction is complete. 14


Instruction sets and types (data manipulation, control, I/O)
 Source and result operands can be in one of four areas:

 Main or virtual memory: As with next instruction references, the main or

virtual memory address must be supplied.


 Processor register: With rare exceptions, a processor contains one or more

registers that may be referenced by machine instructions.


 Immediate: The value of the operand is contained in a field in the instruction

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

 Opcodes are represented by abbreviations, called mnemonics, that indicate


the operation. Common examples include
 ADD Add  DIV Divide
 SUB Subtract  LOAD Load data from memory
 MUL Multiply  STOR Store data to memory
16
Instruction sets and types (data manipulation, control, I/O)
 The 3 most common types of Instruction sets are:

1. Stack - The operands are implicitly on top of the stack.

2. Accumulator - One operand is implicitly the accumulator.

3. General Purpose Register (GPR) - All operands are


explicitly mentioned, they are either registers or
memory locations.
17
Instruction sets and types (data manipulation, control, I/O)
 Lets look at the assembly code of A = B + C; in all 3 architectures:

18
Instruction sets and types (data manipulation, control, I/O)
 Advantages and Disadvantages

 Stack

 Advantages: Simple Model of expression evaluation (reverse polish). Short instructions.

 Disadvantages: A stack can't be randomly accessed This makes it hard to generate eficient code.

 Accumulator

 Advantages: Short instructions.

 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.

 Disadvantages: All operands must be named leading to longer instructions. 19


Instruction sets and types (data manipulation, control, I/O)
 Instruction Types
 Data processing: Arithmetic and logic instructions

 Arithmetic instructions provide computational capabilities for processing numeric data.

 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;

 Data movement: I/O instructions

 I/O instructions are needed to transfer programs and data into memory and the results of

computations back out to the user.


 Control: Test and branch instructions

 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,

logical and control activities.


 Each family of processors has its own set of instructions for handling various operations

like getting input from keyboard, displaying information on screen and performing
various other jobs.
 These set of instructions are called 'machine language instructions'.

 There are two major types of programming languages.

 These are Low Level Languages and High Level Languages.

 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:

A. Immediate Mode B. Direct mode Memory


Instruction

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:

C. Indirect Mode Memory

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:

F. Displacement or address relative addressing

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:

F. Displacement or address relative addressing


 Relative addressing:
» A is added to the program counter contents to cause a branch operation in fetching the
next instruction
 Base-register addressing:
» A is a displacement added to the contents of the referenced “base register” to form the
EA
» Used by programmers and O/S to identify the start of user areas, segments, etc. and
provide accesses within them
 Indexing:
» Indexing is used within programs for accessing data structures.

37
Addressing modes
 The most common addressing techniques:

G. STACK: Instruction

Implicit
Top of stack register

Algorithm: EA = top of stack


 A stack is a linear array of locations.
 Items are appended to the top of the stack so that, at any given time, the block is
partially filled.
 The machine instructions need not include a memory reference but implicitly operate
on the top of the stack.
 Advantage: No memory reference
 Disadvantage: Limited applicability
38
.
Subroutine call and return mechanisms
 A subroutine is a section of the program code with an entry point at the
beginning of the section and a special return mechanism at the end.
 When a subroutine is called from some program location the return mechanism
must jump back to the instruction after the call.
 The return mechanism cannot be a simple branch or up because the return
point changes depending on where the subroutine was called from.
 During the execution of a program a subroutine may be called to perform its
function many times at various points in the main program.
 The instruction that transforms program control to a subroutine is know by
different names.
 The most common names used are: call subroutine, jump to subroutine and
Branch to subroutine.
39
Subroutine call and return mechanisms
 In the diagram below , the subroutine code is shown off to the side of the main
program.

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

You might also like