ECE 310 Lecture 2 - Introduction To Microprocessors

Download as pdf or txt
Download as pdf or txt
You are on page 1of 41

ECE 310

Microprocessors and
Microcontrollers
Introduction to Microprocessors (1)
Mohammed Sharaf Sayed
[email protected]
Lecture Outline

• Computer and Its Organization:


 Input System  Instruction Execution
 Output System  Clock
 Arithmetic and Logic Unit (ALU)  Instruction Format
 Memory  Addressing Modes
 Control System  Instruction Set
• Programming System
 Machine Language Program
 Assembly Language Program
 Assembler Directives
 Compilers
 Operating Systems
2
Computer Organization

• The computer organization proposed by von


Neumann envisages that the binary number
system to be used for both data and instructions.
3
Input & Output

• The role of the input system is to enter instructions (for


the operation to be performed) and the related data
into the computer.

• The output system presents to the user the


information inside the computer.

4
Arithmetic and Logic Unit (ALU)

• The ALU performs arithmetic and logic functions on


the data. The basic arithmetic functions are add,
subtract, multiply, and divide. The logic functions are
AND, OR, NAND, NOR, NOT, EX-OR, etc.
• A computer which can store N-bit data and compute
on N-bit data will have N-bit registers.
5
Memory

• Memory stores the bulk of data, instructions and


results.

• The basic unit of memory is called word.

• A word can store one unit of data.

• The maximum number of bits of data that a word can


store is called its length.

• Computer memories are of two classes—main memory


and secondary or back-up memory.
6
Memory

• The main memory is a Random Access Memory (RAM)


in which any particular word can be read or written at
random.

• The time taken to read/write different data from/to


different locations in this class of memory remains the
same.

• Each memory location is associated with an address,


which is used to access that particular location.

7
Memory

• The MAR contains the address where the read/write


operation is to be performed.
• The MBR contains data to be written or data after the
8
read operation.
Memory

• Nowadays, main memory is fabricated with


semiconductor (MOS) technology.
• MOS memories are extremely compact and take much
less time for read/write.
• The two principal types of MOS memory chips are
EPROM—Erasable Programmable Read Only Memory
and RAM.
• Secondary memories are used for large data storage.
They are nonvolatile, semi-random or sequential
access and have low cost per bit.
9
Control Unit

• The control unit is the central nervous system of the


computer. It reads an instruction from memory and
generates control signals for the execution of that
instruction.

• The control signals initiate the required actions in ALU,


memory and I/O devices.
10
Control Unit

• The program counter contains the


address of the current instruction
in memory and is incremented
during the instruction execution.

• The Instruction Register stores the


instruction read from memory.

• The instruction received by the


control unit is a bit pattern and it
should be decoded to generate a
particular sequence of control
signals.
11
Control Unit (Stack)

• The control unit maintains a stack in CPU or main


memory.
• The stack is also called Last-In First-Out (LIFO) queue.
• The Stack Pointer (SP) points to the next available
memory location in the stack
• Two operations can be performed on stack; PUSH
(write data into stack) and POP (read data from stack).

12
Control Unit (Stack)

• These IN and OUT buffers are normally some registers


in the ALU.
• Example:
– The data (Z) to be pushed in the stack should be stored in IN
buffer first.
– After the POP operation has been completed, data taken out
from top of the stack will appear in OUT buffer.
13
Instruction Execution

• The instruction execution includes two basic steps:


– Instruction fetch, i.e. reading of instruction from
memory.
– Instruction execute, i.e. generation of control signals.
• These two steps are called fetch cycle and execute
14 cycle.
Clock

• All operations in the computer are controlled by clock signals.


The clock signal provides the basic timing signal for computer
operations.
• All the actions in the computer are initiated either by the leading
edge or by trailing edge of the clock and take a fixed number of
15 clock periods to complete.
Clock

• Every instruction is executed in a fixed number of clock


cycles.
• The clock controls the generation of all control signals
in the computer.

16
Instruction Format

• An instruction specifies the type of operation, the


location of operands and the location where the result
of the operation is to be stored.
• The operation code specifies the operation to be
performed.
17
Instruction Format

• The operand address specifies the location of operand.


• In case of operands located in memory, their addresses
may be specified directly or through an indirect way
based on the Addressing Mode.
• The simplest type of instruction format contains only
the Operation Code but no operand address or
addressing mode bits such as Halt instruction.
• In many operations like Decimal Adjust Accumulator,
Set Carry, Clear Carry, the location of the operand is
prefixed and therefore not mentioned.
18
Instruction Format

• The single operand instruction format specifies the


Operation Code, the Addressing Mode and the
Operand Address such as Increment or Decrement
content of register/memory location.
• There are also types of instructions where the location
of the other operand and the result is prefixed such as
IN port and OUT port.

19
Addressing Modes

• The addressing mode specifies:


Where the operand is located
How to reach the operand location
• The operand may be located as:
Immediate data as part of the instruction
Data stored in one of the registers
Data stored in memory

20
Addressing Modes

• Immediate addressing mode


MOV BX, 97F0H
BX  the value 97F0H
• Register addressing mode
MOV AX, BX
AX  the value in BX

21
Addressing Modes

• Memory addressing modes


Direct addressing mode
MOV AX, [2345H]
AX  the word in location 2345H
MOV [2345H], BX
The location whose address is 2345H  BX
Indirect addressing mode
MOV AL, [BX]
AL  the word in the location whose address is in BX
MOV [BX], CL
The location whose address is in BX  CL
22
Addressing Modes

Indexed addressing mode


Base plus Index Indirect Addressing mode
 The base of the array is specified in a register called
Base register.
 The index or distance of the element from the base of
the array to be accessed is specified in a register called
Index register.
 The sum of the contents of Base register and Index
register is the address of the operand in memory.
MOV [BX + DI], AL
The location whose address is in BX + DI  AL
23
Addressing Modes

Indexed addressing mode


Base plus Index Register Relative Addressing mode,
 Base register contains the base address of the array.
 Index register contains the increment from base to the
row where the data is stored.
 Displacement mentioned in the instruction or in a
separate register is the displacement of the element
from the start of the row.
MOV [BX + DI + 4], AL
The location whose address is in BX + DI + 4  AL

24
Addressing Modes

25
Instruction Set

• Instructions may be divided into the following five


general groups:
– Data transfer group
– Arithmetic and logic group
– String manipulation group
– Program control group
– Execution control group

26
Instruction Set

• Data transfer group; this group of instructions deals


with the movement of data in byte/word/bit form
between:
 Register to Register
 Memory to Register
 Register to Memory
 Immediate data to Register
 Immediate data to Memory
 Exchange of data between two registers
Example: MOV BX, CX

27
Instruction Set

• Arithmetic and logic group; this group of


instructions includes:
 Arithmetic operations
Example: ADD AL, BL
 Logical operations
Example: XOR AL, BL

28
Instruction Set

• String manipulation group; this group of instructions


includes:
 Loading/storing of byte/word string elements.
 Movement of byte/word string elements to
another memory location.
 Comparison of two byte/word string elements.
Example: MOVSB
Move the string byte from DS:SI to ES:DI in memory

29
Instruction Set

• Program control group; this group of instructions


includes:
 Conditional/Unconditional branch
 Conditional/Unconditional call to subroutine
 Return from subroutine
 Restart
Example: JNZ Label
Jump to Label if zero flag is not set.

30
Instruction Set

• Execution control group; this group of instructions


includes:
 No operation
 Halt
 Enabling/Disabling Interrupts
 Initialization of control/function registers for
interrupts, on chip timer/counter (if any)
Example: HLT
Program halts

31
Programming System

• Machine Language Program


 Machine instructions are the instructions which are
decoded directly by the control unit and executed.
 And, the language is called machine language.
 Machine language consists of different binary numbers
(bit patterns) for different operations.
 To perform a particular action by computer, one would
need to write a number of instructions, each performing a
step in calculation or action.
 This combination of instructions is called a program.

32
Programming System

• Example:
0100.....0111.....(Code for MOV B, A)......;....Move
Accumulator content to B register
• For each instruction:
 Instruction will be loaded
 Instruction will be decoded
 Control signals will be generated.
• It is very difficult to write programs in machine
language.  A single bit error in any instruction will
produce undesirable results.
33
Programming System

• Assembly Language Program


 In assembly language, each machine instruction
has been replaced by a mnemonic which signifies
the operation
 Examples:
ADD (for addition)
SUB (for subtraction)
LOAD (for memory read)
STORE (for memory write)
34
Programming System

• Assembler is a software program which translates


assembly programs to their machine level programs.
• In the memory, the program will be stored as a
machine level program.

35
Programming System

 Example (Intel 8085 assembly):


ORG.............2000H (Hex)
LDA.............2400H
MOV.............B, A
LDA.............2401H
ADD.............B
STA.............2402H
END
36
Programming System

• Assembler Directives
 Every assembler will have Pseudo Instructions or
directives to help the programmer to communicate
the program requirements to the assembler.
 Examples:
ORG 2000H  indicates to Intel 8085 assembler that the
following instructions are to be loaded, starting from
memory location 2000 Hex.
END  indicates to Intel 8085 assembler that the program
has ended and thus no further translation of assembly
instructions to machine instructions is required.

37
Programming System

• Compilers
 With the increase of computer programs
complexity, assembly language programs became
very lengthy and unmanageable.
 This leads to the development of high-level
languages like BASIC, FORTRAN, C etc.
 Compilers translate high-level languages programs
into machine level language which can then be
directly executed by computers.

38
Programming System

• Operating Systems
 An operating system (OS) is system software that
manages computer hardware, software resources,
and provides common services for computer
programs.
 It allocates computer resources to the user
programs.

39
Lecture Summary

• We have discussed the following topics:


• Computer and Its Organization:
 Input System  Instruction Execution
 Output System  Clock
 Arithmetic and Logic Unit (ALU)  Instruction Format
 Memory  Addressing Modes
 Control System  Instruction Set
• Programming System
 Machine Language Program
 Assembly Language Program
 Assembler Directives
 Compilers
40  Operating Systems
Mohammed Sharaf Sayed
[email protected]

You might also like