68HC11 Instruction Set - Montana State University Modes Whenever an instruction operates on a data...

28
68HC11 Microcontroller Instruction Set

Transcript of 68HC11 Instruction Set - Montana State University Modes Whenever an instruction operates on a data...

Page 1: 68HC11 Instruction Set - Montana State University Modes Whenever an instruction operates on a data or operand, we need to specify the location were the data resides. An addressing

68HC11 Microcontroller Instruction Set

Page 2: 68HC11 Instruction Set - Montana State University Modes Whenever an instruction operates on a data or operand, we need to specify the location were the data resides. An addressing

ECE2325 Spring 03 - Fernando Rios 2

Microcontroller Instruction Set

Data Handling GroupArithmetic and Logic GroupBranching and Decision GroupInput/Output groupSpecial

Page 3: 68HC11 Instruction Set - Montana State University Modes Whenever an instruction operates on a data or operand, we need to specify the location were the data resides. An addressing

ECE2325 Spring 03 - Fernando Rios 3

Data Handling Group

This group of instructions is used to initialize, alter the contentsof a register or memory location, to move data between registers,to move data between a register and memory, or between two memory locations, etc.

Examples: LOADSTORECLEAR

Page 4: 68HC11 Instruction Set - Montana State University Modes Whenever an instruction operates on a data or operand, we need to specify the location were the data resides. An addressing

ECE2325 Spring 03 - Fernando Rios 4

Arithmetic and Logic Group

This group of instructions is used to perform a specific Arithmetic or logic operation over one or more operands.

Examples: ADDSUBSTRACTMULTIPLYORAND, etc

Page 5: 68HC11 Instruction Set - Montana State University Modes Whenever an instruction operates on a data or operand, we need to specify the location were the data resides. An addressing

ECE2325 Spring 03 - Fernando Rios 5

Branching and Decision Group

This group of instructions is used to control the executionof the program

Examples: BRANCHJUMPCALL, etc

Page 6: 68HC11 Instruction Set - Montana State University Modes Whenever an instruction operates on a data or operand, we need to specify the location were the data resides. An addressing

ECE2325 Spring 03 - Fernando Rios 6

Special Instruction Group

This class of instructions is very close related to the hardwareof the CPU, and may control some internal signals.

Example: WAITNO OPERATIONINTERRUPT ENABLE, etc

Page 7: 68HC11 Instruction Set - Montana State University Modes Whenever an instruction operates on a data or operand, we need to specify the location were the data resides. An addressing

ECE2325 Spring 03 - Fernando Rios 7

Instruction FormatsOp Code

1 Byte Instruction

Op Code

Op Code, Operand or Address 2 Byte Instruction

Page 8: 68HC11 Instruction Set - Montana State University Modes Whenever an instruction operates on a data or operand, we need to specify the location were the data resides. An addressing

ECE2325 Spring 03 - Fernando Rios 8

Instruction Formats

Op Code

First byte of Operand or Address

Second byte of Operand or Address

Three ByteInstruction

Page 9: 68HC11 Instruction Set - Montana State University Modes Whenever an instruction operates on a data or operand, we need to specify the location were the data resides. An addressing

ECE2325 Spring 03 - Fernando Rios 9

Storing of Instructions in MemoryMemory

Operand/Address LSBOperand/Address MSB

Instruction Op codeOp code/Operand/Address

Instruction Op codeInstruction Op code

InitialAddress = 100 1 Byte instruction

101

102

103

104

105

106

2 Byte instruction

3 Byte instruction

Page 10: 68HC11 Instruction Set - Montana State University Modes Whenever an instruction operates on a data or operand, we need to specify the location were the data resides. An addressing

ECE2325 Spring 03 - Fernando Rios 10

Addressing ModesWhenever an instruction operates on a data or operand, we needto specify the location were the data resides. An addressing mode refers to the way we specify the address or location where the data is stored

InherentImmediateDirectIndexed

Page 11: 68HC11 Instruction Set - Montana State University Modes Whenever an instruction operates on a data or operand, we need to specify the location were the data resides. An addressing

ECE2325 Spring 03 - Fernando Rios 11

Inherent Addressing

The instruction itself implies the location of the operand.Inherent addressing always deals with data or operandsstored in registers not in memory.Examples: Address Code Mnemonic Instruction Actions0100 4F CLRA ; Clear Acc A0101 5C INCB ; Increment Acc B0102 18 09 DEY ; Decrement register IY0104 1B ABA ;Add Acc A to Acc B0105 18 8F XGDY ; Swap contents of Acc D with IY

Page 12: 68HC11 Instruction Set - Montana State University Modes Whenever an instruction operates on a data or operand, we need to specify the location were the data resides. An addressing

ECE2325 Spring 03 - Fernando Rios 12

Immediate AddressingThe instruction itself contains the data or operand that is needed by

The instruction.Immediate addressing always deals with data or operands stored in

registers not in memory.Examples: Address Code Mnemonic Instruction Actions0100 86 5C LDAA #$5C ; Load Acc A with 5C0102 8B 02 ADDA #$02 ; Add 02 to the contents of Acc A0104 CC 12 34 LDD #$1234 ; Load register D with 1234

Note that immediate addressing is specified by putting a # before the operand

Page 13: 68HC11 Instruction Set - Montana State University Modes Whenever an instruction operates on a data or operand, we need to specify the location were the data resides. An addressing

ECE2325 Spring 03 - Fernando Rios 13

Data Numbering Definitions

• The symbols that are used to define the numbering system used in the operand field are:

a) No Symbol Decimal Numberb) $ Hexadecimal Numberc) @ Octal Numberd) % Binary Number

Page 14: 68HC11 Instruction Set - Montana State University Modes Whenever an instruction operates on a data or operand, we need to specify the location were the data resides. An addressing

ECE2325 Spring 03 - Fernando Rios 14

Examples

• ADDA 25 ;Add 25d to Acc A• ADDA $25 ; Add 25h (37d) to Acc A• ADDA @25 ; Add 25o (21d) to Acc A• ADDA %00011001 ; Add 25d to Acc A

Page 15: 68HC11 Instruction Set - Montana State University Modes Whenever an instruction operates on a data or operand, we need to specify the location were the data resides. An addressing

ECE2325 Spring 03 - Fernando Rios 15

Direct AddressingThe instruction contains the address of the memory location wherethe data or operand is stored.Direct addressing always deals with data or operands stored in

memory.There are two options for direct addressing: short and extendedExamples: Address Code Mnemonic Instruction Actions0100 96 5C LDAA $5C ; Load acc A with data in location 5C0102 8B 02 ADDA $02 ; Add the contents of loc 02 to acc A0104 B6 00 05 LDAA $005C ; Load acc A with data in location 5C

Page 16: 68HC11 Instruction Set - Montana State University Modes Whenever an instruction operates on a data or operand, we need to specify the location were the data resides. An addressing

ECE2325 Spring 03 - Fernando Rios 16

Indexed AddressingThe address of the memory location where the data or operand is

stored, is specified by using a special register.There are two registers that can be used to hold the address, and

they are commonly known as index registers X and YIndexed addressing always deals with data or operands stored in

memory.This is the most complex type of addressing that the micro-

controller can use to access a data in memory.Besides the address pointed by the index register, we can also

specify a second number called an “offset”. This number is added to the number stored in the index register to calculate the effective address of the data that is used by the instruction

Page 17: 68HC11 Instruction Set - Montana State University Modes Whenever an instruction operates on a data or operand, we need to specify the location were the data resides. An addressing

ECE2325 Spring 03 - Fernando Rios 17

Indexed AddressingExamples: Address Code Mnemonic0100 A6 00 LDAA $0,X0102 18 E6 56 LDAB $56,X0105 18 A7 05 STAA $05,Y

Page 18: 68HC11 Instruction Set - Montana State University Modes Whenever an instruction operates on a data or operand, we need to specify the location were the data resides. An addressing

ECE2325 Spring 03 - Fernando Rios 18

Instruction Actions

Page 19: 68HC11 Instruction Set - Montana State University Modes Whenever an instruction operates on a data or operand, we need to specify the location were the data resides. An addressing

ECE2325 Spring 03 - Fernando Rios 19

Instruction Actions

Page 20: 68HC11 Instruction Set - Montana State University Modes Whenever an instruction operates on a data or operand, we need to specify the location were the data resides. An addressing

ECE2325 Spring 03 - Fernando Rios 20

Pseudo instructions and Directivesa) Control Directives

ORG ;Specify Memory Storage LocationEND ;Specify end of program

b) Data DirectivesFCB ;Specify constant ByteFDB ;Specify double constant byteFCC ;Form Constant CharacterEQU ;Assign Value to a LabelRMB ;Reserve Memory Block

Page 21: 68HC11 Instruction Set - Montana State University Modes Whenever an instruction operates on a data or operand, we need to specify the location were the data resides. An addressing

ECE2325 Spring 03 - Fernando Rios 21

Pseudo-Instruction Usage ExamplesORG $C000

NUM1 EQU 25NUM2 EQU $25CONST FDB $ABCDMESSA FCC ‘HELLO’

ORG $C100DATA1 FCB $A0DATA2 FCB $B5BUFFER RMB 2

ORG $C200START LDAA NUM2

END

Page 22: 68HC11 Instruction Set - Montana State University Modes Whenever an instruction operates on a data or operand, we need to specify the location were the data resides. An addressing

22

Programin

Memory

19

96

B5

A0

6F

6C

6C

65

48

CD

ABC000C001C002C003C004C005C006C007C008C009::C100C001::C200

2 Reservedlocations

Double biteData

Message

Single Byte

Single Byte

Start ofProgramCode

Page 23: 68HC11 Instruction Set - Montana State University Modes Whenever an instruction operates on a data or operand, we need to specify the location were the data resides. An addressing

ECE2325 Spring 03 - Fernando Rios 23

Page 24: 68HC11 Instruction Set - Montana State University Modes Whenever an instruction operates on a data or operand, we need to specify the location were the data resides. An addressing

ECE2325 Spring 03 - Fernando Rios 24

Page 25: 68HC11 Instruction Set - Montana State University Modes Whenever an instruction operates on a data or operand, we need to specify the location were the data resides. An addressing

ECE2325 Spring 03 - Fernando Rios 25

Page 26: 68HC11 Instruction Set - Montana State University Modes Whenever an instruction operates on a data or operand, we need to specify the location were the data resides. An addressing

ECE2325 Spring 03 - Fernando Rios 26

Program Example 1Write a program in assembly language to add the numbers that arestored in memory at locations C100 – C1005

MemoryAddress

211713951C100

C101C102C103C104C105

Page 27: 68HC11 Instruction Set - Montana State University Modes Whenever an instruction operates on a data or operand, we need to specify the location were the data resides. An addressing

ECE2325 Spring 03 - Fernando Rios 27

Programstart

Load 1Start LOAD C100

ADD C101ADD C102ADD C103ADD C104ADD C105

End

Add 5

Add 9

Add 13

Add 17

Add 21

end

Page 28: 68HC11 Instruction Set - Montana State University Modes Whenever an instruction operates on a data or operand, we need to specify the location were the data resides. An addressing

ECE2325 Spring 03 - Fernando Rios 28

Program SyntaxLDAA Load acc A Moves a new data to AccADDA Add a data using A Adds a new data to contents

of acc A result is left in acc A

Mnemonic Instruction Action

Label Mnemonic ActionORG $C200 ; specify starting address of program

Start LDAA $C100 ; loads first operant into AADDA $C101 ; adds second dataADDA $C102 ; adds third dataADDA $C103 ; adds fourth dataADDA $C104 ; adds fifth dataADDA $C105 ; adds sixth data

End