Microcontrollers and RT programming 3

32
1 Microprocessor Operation and Execution of Instructions Prof. Yusuf Leblebici Microelectronic Systems Laboratory (LSM) [email protected]

description

 

Transcript of Microcontrollers and RT programming 3

Page 1: Microcontrollers and RT programming 3

1

Microprocessor Operation and Execution of Instructions

Prof. Yusuf LeblebiciMicroelectronic Systems Laboratory (LSM)

[email protected]

Page 2: Microcontrollers and RT programming 3

2

8085 Functional Block Diagram

Page 3: Microcontrollers and RT programming 3

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

Page 4: Microcontrollers and RT programming 3

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.

Page 5: Microcontrollers and RT programming 3

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

Page 6: Microcontrollers and RT programming 3

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

Page 7: Microcontrollers and RT programming 3

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

Page 8: Microcontrollers and RT programming 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

Page 9: Microcontrollers and RT programming 3

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

Page 10: Microcontrollers and RT programming 3

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

Page 11: Microcontrollers and RT programming 3

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

Page 12: Microcontrollers and RT programming 3

12

Now:

Back to the 8085 Microprocessor

Page 13: Microcontrollers and RT programming 3

13

The 8085 Microprocessor

Page 14: Microcontrollers and RT programming 3

14

The 8085 Microprocessor

address(8 bits)

Page 15: Microcontrollers and RT programming 3

15

The 8085 Microprocessor

address and data(8 bits)

dual - use pins !!

Page 16: Microcontrollers and RT programming 3

16

The 8085 Microprocessor

Demultiplexing the address / data bus

16

8

Page 17: Microcontrollers and RT programming 3

17

Example: Instruction Fetch Operation

Page 18: Microcontrollers and RT programming 3

18

Example: Instruction Fetch Operation

Instruction (opcode) reaches the instruction decoder now !

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

Page 19: Microcontrollers and RT programming 3

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 !

Page 20: Microcontrollers and RT programming 3

20

Execution of an Instruction

Page 21: Microcontrollers and RT programming 3

21

Execution of an Instruction

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

Page 22: Microcontrollers and RT programming 3

22

Execution of an Instruction

Get the instruction (opcode) byte from memory

Page 23: Microcontrollers and RT programming 3

23

Execution of an Instruction

Interpret the instruction:

Wait for the data byte !

Page 24: Microcontrollers and RT programming 3

24

Execution of an Instruction

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

Page 25: Microcontrollers and RT programming 3

25

Execution of an Instruction

Get the data byte from the memory

Put into accumulator

Page 26: Microcontrollers and RT programming 3

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 !

Page 27: Microcontrollers and RT programming 3

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

Page 28: Microcontrollers and RT programming 3

28

8085 Instruction Types

Page 29: Microcontrollers and RT programming 3

29

8085 Instruction Types

Page 30: Microcontrollers and RT programming 3

30

8085 Instruction Types

Page 31: Microcontrollers and RT programming 3

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

Page 32: Microcontrollers and RT programming 3

32

A VERY Simple Program