microcontrollers and rt programming 3

Post on 20-Jan-2015

53 Views

Category:

Education

2 Downloads

Preview:

Click to see full reader

DESCRIPTION

 

TRANSCRIPT

1

Microprocessor Operation and Execution of Instructions

Prof. Yusuf LeblebiciMicroelectronic Systems Laboratory (LSM)

yusuf.leblebici@epfl.ch

2

8085 Functional Block Diagram

3

Basic Processor Operation

All instructions (program steps) are stored in memory.

To run a program, the individual instructions must be read from the memory in sequence, and

executed.

Detailed sequence:

Instruction fetch (read from memory)

Decode instruction

Get operands

Execute operation

Save result

getnext

instruction

4

Basic Processor Operation

We will first demonstrate the main steps of execution using a very simple processor “model” :

Few instructions (commands)

Simple memory access

Easy to understand

Then, we will start examining the actual 8085 processor instruction set and operations.

The OTC (Our Tiny Computer)

• Only 4 Instructions– Add

• sets condition of result: negative, zero, positive

– Load, Store• Absolute Reference

– Branch• PC Relative branch

• 4 Registers (r0, r1, r2, r3)

• 16 Storage (Memory) Locations

Example OTC Instructions

load r1,12 // r1 = M[12]

add r1,r2,r2 // r1 = r2 + r2

br pos,-3 // if (result > 0) PC = PC – 3

st r0,3 // M[3] = r0

Illegal instructions

load r4,17 // no register 4, no location 17

add r1,19 // add requires register references

OTC Operation

LoadStore

BranchAdd

Register File

Memory

Program Counter

Inst Reg

Load r0,b

Load r1,c

Add r2,r1,r0

Store r2,a

7

6 BB

CC

AA

0

Load r0,b

0

6

Load r0,b

0

6

Load r0,b

1

6

Load r1,c

1

6

Load r1,c

1

7

6

Load r1,c

2

7

6

Add r2,r1,r0

2

7

13

6

Add r2,r1,r0

2

7

+

13

6

Add r2,r1,r0

3

7

+

13

6

Store r2,a

3

7

+

13

6

Add r2,r1,r0

3

7

+

13

r0

r1

r2

r3

0

1

2

3

OTC Instruction Encoding

0 1 2 3 4 7

op reg loc

op reg reg reg

0 1 2 3 4 5 6 7

op cond target

0 1 2 4 5 7

Load/Store

Add

Branch

Opcodes

Load

Store

Branch

Add

00

01

10

11

LoadStore

BranchAdd

Register File

Memory

Program Counter

Inst Reg

0 0 0 0 1 0 0 1

0 0 0 1 1 0 1 0

1 1 1 0 0 1 0 0

0 1 1 0 1 0 0 0

1 10 0 0 0 0 0

1 10 0 0 0 0 1

00

0 0 0 0 1 0 0 1

1 10 0 0 0 0 0

0

0 0 0 0 1 0 0 1

1 10 0 0 0 0 0

1

0 0 0 0 1 0 0 1

1 10 0 0 0 0 0

1

0 0 0 1 1 0 1 0

1 10 0 0 0 0 11 10 0 0 0 0 0

1

0 0 0 1 1 0 1 0

1 10 0 0 0 0 11 10 0 0 0 0 0

2

0 0 0 1 1 0 1 0

1 10 0 0 0 0 11 10 0 0 0 0 0

2

1 1 1 0 0 1 0 0

1 00 0 0 0 1 11 10 0 0 0 0 11 10 0 0 0 0 0

2

1 1 1 0 0 1 0 0

+

1 00 0 0 0 1 11 10 0 0 0 0 11 10 0 0 0 0 0

3

1 1 1 0 0 1 0 0

+

0 1 1 0 1 0 0 0

1 00 0 0 0 1 11 10 0 0 0 0 11 10 0 0 0 0 0

3

+

0 1 1 0 1 0 0 0

1 00 0 0 0 1 1

0 1 1 0 1 0 0 0

1 00 0 0 0 1 11 10 0 0 0 0 11 10 0 0 0 0 0

3

+

OTC Operation

Another Simple Program

Acc = 1

Count = -n

Loop

Acc += Acc

Count += 1

Until (Count = 0)

L Ra,1

L Rc,-n

L Ri,1

Loop

Add Ra,Ra,Ra

Add Rc,Rc,Ri

Br Neg,Loop

LoadStore

BranchAdd

Register File

Memory

Program Counter

Inst Reg

Load R0,14

Load R1,14

Load R2,15

Add R0,R0,R0

Add R2,R2,R1

BR Neg,3

1

-5

00

Load R0,14

0

Load R0,14

1

1

Load R0,14

1

1

Load R1,14

1

1

Load R1,14

1

1

2

Load R2,15

1

1

2

Load R2,15

1

1

-5

3

Load R2,15

1

1

-5

3

Add R0,R0,R0

1

1

-5

3

Add R0,R0,R0

2

1

-5

4

Add R0,R0,R0

2

1

-5

+

4

Add R2,R2,R1

2

1

-5

+

4

Add R2,R2,R1

2

1

-4

-

5

Add R2,R2,R1

2

1

-4

-

5

BR Neg,3

2

1

-4

-

3

BR Neg,3

2

1

-4

-

3

Add R0,R0,R0

2

1

-4

-

3

Add R0,R0,R0

2

1

-4

-

3

Add R0,R0,R0

4

1

-4

+

OTC Operation

0

1

2

34

5

1415

r0

r1

r2

r3

12

Now:

Back to the 8085 Microprocessor

13

The 8085 Microprocessor

14

The 8085 Microprocessor

address(8 bits)

15

The 8085 Microprocessor

address and data(8 bits)

dual - use pins !!

16

The 8085 Microprocessor

Demultiplexing the address / data bus

16

8

17

Example: Instruction Fetch Operation

18

Example: Instruction Fetch Operation

Instruction (opcode) reaches the instruction decoder now !

It takes four clock cycles to get one instruction into the CPU.

19

Execution of an Instruction

Now consider the execution of a simple instruction:

Instruction 3E (hex) means: Load a data byte into

the accumulator

The instruction is followed by the data byte 32 (hex)

Two-byte instruction !

20

Execution of an Instruction

21

Execution of an Instruction

Put the first memory location on the address bus (2000 h)

22

Execution of an Instruction

Get the instruction (opcode) byte from memory

23

Execution of an Instruction

Interpret the instruction:

Wait for the data byte !

24

Execution of an Instruction

Put the next memory location on the address bus (2001 h)

25

Execution of an Instruction

Get the data byte from the memory

Put into accumulator

26

Execution of an Instruction

How long does it take to execute this two-byte instruction (op-code) ?

It is quite possible to accurately predict the time that is required to run each instruction, and to run the entire program !

27

8085 Instruction Set

The 8085 instructions can be classified as follows:

Data transfer operations

Arithmetic operations (ADD, SUB, INR, DCR)

Logic operations

Branching operations (JMP, CALL, RET)

• Between registers• Between memory location and a register• Direct write to a register / memory• Between I/O device and accumulator

28

8085 Instruction Types

29

8085 Instruction Types

30

8085 Instruction Types

31

A VERY Simple Program

Add two hexadecimal numbers:

Load register A (accumulator) with 32 (hex)

Load register B with 48 (hex)

Add the two numbers and save the sum in A

Display accumulator (A) contents at port (01)

End

32

A VERY Simple Program

top related