+ All Categories
Home > Documents > Chapter 4

Chapter 4

Date post: 23-Oct-2014
Category:
Upload: saltihie-zeni
View: 25 times
Download: 0 times
Share this document with a friend
Popular Tags:
43
CHAPTER 4: MICROCONTROLLER/MICROPROCESSOR INSTRUCTION SALTIHIE BIN ZENI [email protected] ELECTRICAL ENGINEERING DEPARTMENT POLITEKNIK MUKAH SARAWAK 1 Micrprocessor and Microcontroller System - Saltihie Zeni
Transcript
Page 1: Chapter 4

1

CHAPTER 4: MICROCONTROLLER/MICROPROCESSOR

INSTRUCTION

SALTIHIE BIN [email protected]

ELECTRICAL ENGINEERING DEPARTMENT

POLITEKNIK MUKAH SARAWAK

Micrprocessor and Microcontroller System - Saltihie Zeni

Page 2: Chapter 4

Micrprocessor and Microcontroller System - Saltihie Zeni

2

INTRODUCTION

• Instruction set – A list of instruction that can be executed by a microprocessor.

• Instruction are categorized according to basic operation performed:– Data transfer– Arithmetic– Logic– Shift and Rotates– Bit manipulation– BCD– Program control– System control

Instruction is written using mnemonic

(easy to remember code) because it is not practical to use

binary code for programming

Page 3: Chapter 4

Micrprocessor and Microcontroller System - Saltihie Zeni

3

BASIC INSTRUCTION SET

Page 4: Chapter 4

Micrprocessor and Microcontroller System - Saltihie Zeni

4

68000 REGISTER SET

Page 5: Chapter 4

Micrprocessor and Microcontroller System - Saltihie Zeni

5

68000 REGISTER

Page 6: Chapter 4

Micrprocessor and Microcontroller System - Saltihie Zeni

6

ADDRESSING MODE

Page 7: Chapter 4

Micrprocessor and Microcontroller System - Saltihie Zeni

7

1. REGISTER DIRECT ADDRESSING

Page 8: Chapter 4

Micrprocessor and Microcontroller System - Saltihie Zeni

8

2. IMMEDIATE ADDRESSING MODE

Page 9: Chapter 4

Micrprocessor and Microcontroller System - Saltihie Zeni

9

IMMEDIATE ADDRESSING MODE

Page 10: Chapter 4

Micrprocessor and Microcontroller System - Saltihie Zeni

10

3. ABSOLUTE ADDRESSING MODE

Page 11: Chapter 4

Micrprocessor and Microcontroller System - Saltihie Zeni

11

4. ADDRESS REGISTER INDIRECT ADDRESSING MODE

Page 12: Chapter 4

Micrprocessor and Microcontroller System - Saltihie Zeni

12

5. RELATIVE ADDRESSING MODE

Page 13: Chapter 4

Micrprocessor and Microcontroller System - Saltihie Zeni

13

6. INHERENT ADDRESSING MODE

Page 14: Chapter 4

Micrprocessor and Microcontroller System - Saltihie Zeni

14

Example 4.1

• State the addressing mode for the following instruction:

i. MOVE.W D2,D3

ii. JSR

iii. MOVE.B (A0), D3

iv. CLR.W $2003

v.MOVE.W #$1234,D0

vi.BRA DELAY

vii. SWAP D0,D1

viii. MOVE.B #%10010011,D3

Page 15: Chapter 4

Micrprocessor and Microcontroller System - Saltihie Zeni

15

BUILDING A PROGRAM

• Program design is a process to provide an executable program in microprocessor.

• A task that need to be done by microprocessor need a conversion to machine language that can be understood by microprocessor.

• 5 Steps to build a program:– Definition of Problem– Logic Design– Programming– Load, Test and Debug– Documentation

Page 16: Chapter 4

Micrprocessor and Microcontroller System - Saltihie Zeni

16

Problem analysis is a phase to convert a task that need to be done to an abstract shape and not particular to a microprocessor.This phase include a design using pseudo code or flow chart (will be discuss later).6 mini steps in problem analysis:– Clarify objectives and users– Clarify desired outputs– Clarify desired inputs– Clarify desired process– Double-check feasibility of implementing the program– Document the analysis.

1. DEFINITION OF PROBLEMS

Page 17: Chapter 4

Micrprocessor and Microcontroller System - Saltihie Zeni

17

2. LOGIC DESIGN

Page 18: Chapter 4

Micrprocessor and Microcontroller System - Saltihie Zeni

18

2. LOGIC DESIGN

• Algorithm can be represented in flow chart or pseudo code.

• Flow chart – A graphical representation of algorithm

• Pseudo – Artificial and informal language– Similar to everyday English

Page 19: Chapter 4

Micrprocessor and Microcontroller System - Saltihie Zeni

19

2. LOGIC DESIGNFlow chart – Basic blocks

Page 20: Chapter 4

Micrprocessor and Microcontroller System - Saltihie Zeni

20

• This phase is where a programmer write a task using editor(discussed in chapter 3).

• Editor is any software that can provide ASCII text like notepad or particular software like SciTE or programmers notepad.

• After source code provided, it then need to compile to produce a program that can be understood by microprocessor.

3. PROGRAMMING

Page 21: Chapter 4

Micrprocessor and Microcontroller System - Saltihie Zeni

21

• In program writing, there will be a mistake or technically called error.

• 2 types of error:– Syntax error– Semantic error

3. PROGRAMMING

Page 22: Chapter 4

Micrprocessor and Microcontroller System - Saltihie Zeni

22

• Syntax error– Mistake in program writing for example more or

less comma than needed. This error can be detect early and easy to do a correction.

• Semantic error– Logic mistake for example programmer done a

operation which is not appropriate and not suitable in the program.

– This error cannot detected by compiler and only can be seen when the program already execute.

3. PROGRAMMING

Page 23: Chapter 4

Micrprocessor and Microcontroller System - Saltihie Zeni

23

3. PROGRAMMING

Page 24: Chapter 4

Micrprocessor and Microcontroller System - Saltihie Zeni

24

4. LOAD, TESTING AND DEBUGGING

Page 25: Chapter 4

Micrprocessor and Microcontroller System - Saltihie Zeni

25

5. DOCUMENTATION

Page 26: Chapter 4

Micrprocessor and Microcontroller System - Saltihie Zeni

26

PROGRAM EXECUTION STRUCTURE

SEQUENCE SELECTION LOOPING

Page 27: Chapter 4

Micrprocessor and Microcontroller System - Saltihie Zeni

27

JUMP Instruction

JMP = JumpEffect : Program Counter Effective AddressSyntax:

JMP <ea>Example:

JMP START ;START = $1000

JMP $2000

JMP (A0) ; A0 = $1000Useful in selection structure especially to go to sub-routine or sub-program.

Page 28: Chapter 4

Micrprocessor and Microcontroller System - Saltihie Zeni

28

BRANCH ALWAYS Instruction

BRA = Branch AlwaysEffect : PC > PC +offsetSyntax:

BRA <ea>Example:

BRA LAST

Page 29: Chapter 4

Micrprocessor and Microcontroller System - Saltihie Zeni

29

if-then STRUCTURE

• Basic control structure – conditional statement• Syntax in high level language programming

if <condition> then <statement>

• In 68000, this structure is:

<condition> ; testing condition and set CCRBCC SKIP ; select subroutine<Statement> ;execute statement

SKIP ….. ;continue

Page 30: Chapter 4

Micrprocessor and Microcontroller System - Saltihie Zeni

30

CONDITIONAL BRANCH (Bcc)• Syntax:

Bcc <ea>• cc represent the condition that will be tested.• If condition TRUE = Subroutine executed• If condition FALSE = Subroutine not executed, program go to next instruction.

Page 31: Chapter 4

Micrprocessor and Microcontroller System - Saltihie Zeni

31

Example Using Conditional Branch

1. Clear data in D7 if operation D6-1 equal to zero.

2. Add 1 to D0 if addition of D1+D2 produce carry.

Page 32: Chapter 4

Micrprocessor and Microcontroller System - Saltihie Zeni

32

Compare Instruction

Compare = CMP• Function : Compare 2 data. Subtract data and set CCR. Destination must

data register. It look like subtract instruction but data register not change.

Page 33: Chapter 4

Micrprocessor and Microcontroller System - Saltihie Zeni

33

Variation of CMP Instruction• CMPI (Compare immediate)

– To compare immediate data– Operation size : B,W,L– Destination : Data or memory register

• CMPA(Compare Address)– To compare address register– Operation size : W,L . W will be extended to L before comparison– Destination : memory register

• CMPM(Compare Memory)– To compare data inside memory – Operation size : B,W,L– Destination : (An)+ only

Page 34: Chapter 4

Micrprocessor and Microcontroller System - Saltihie Zeni

34

Example of CMP and Bcc1. Subtract D1 from D0. Jump if result is 0.

2. Jump if value in D0 equal to 10.

CMPI #10, D0 ; Compare D0 with 10BEQ SAMA ; Jump if D0=10

Page 35: Chapter 4

Micrprocessor and Microcontroller System - Saltihie Zeni

35

if-then-else Structure

• Syntax in high level language:if <condition> then<statement 1> else <statement 2>

• In 68000, this structure is:

Page 36: Chapter 4

Micrprocessor and Microcontroller System - Saltihie Zeni

36

do-while Structure

• Syntax in high level programmingdo <statement>while <condition>

• In 68000, the structure is:

Page 37: Chapter 4

Micrprocessor and Microcontroller System - Saltihie Zeni

37

while Structure

• Syntax in high level programmingwhile <condition> do <statement>

• In 68000, the structure is:

Page 38: Chapter 4

Micrprocessor and Microcontroller System - Saltihie Zeni

38

SIMPLE PROGRAMMING EXAMPLE(ADDITION OF 2 NUMBERS)

1. Define the problemInput : 2 numbers (for example decimal 12 and 34) – save in data register D0 and D1Process : Addition of 2 numbersOutput : Add from Data register D0 and D1 and save result in D1.

2. Draw a flow chart or pseudo code.3. Using the assembly language, write the program.

Page 39: Chapter 4

Micrprocessor and Microcontroller System - Saltihie Zeni

39

Enter first number to data register D0

Enter second number to register

D1

Calculate:D1 = D0 +D1ADD D0, D1

START

END

Flow chart to add 2 number saved in

data register

Page 40: Chapter 4

Micrprocessor and Microcontroller System - Saltihie Zeni

40

PROGRAM

ORG $1000MOVE.B #12,D0MOVE.B #34,D1ADD.B D0,D1END

Write the following program in easy68k and observe the change in

register

Page 41: Chapter 4

Micrprocessor and Microcontroller System - Saltihie Zeni

41

Example 4.2

Case study

1. A robot will move forward when the sensor 1 (S1) enabled. When the sensor 2 (S2)

is activated,) it will make a round of U (right and stop for 20 seconds, then

continue to move forward. Until the sensor 3 (S3) is activated, then the robot will

stop. Draw a flow chart to illustrate the process.

2. In a classroom, when switch 1 is ON it will ON an air-conditioner and all light

respectively. After 3 minutes, LCD screen move down and 2 minutes after that LCD

projector also ON. When switch 1 is turn OFF, 5 minutes after that, air-conditioner,

light and LCD also turn OFF and LCD screen will move up. Draw a flow chart to

illustrate the process.

Page 42: Chapter 4

Micrprocessor and Microcontroller System - Saltihie Zeni

42

Example 4.3

Writing a program

Write a program for the flow chart given. Assume the starting address of your program

is $1000.

D0>5

D1=D0+7D0=D0-1

D7=D0/7

FALSETRUE

END

START

Page 43: Chapter 4

Micrprocessor and Microcontroller System - Saltihie Zeni

43

Note ….


Recommended