68hc11 programming model & addressing modes

Post on 30-Dec-2015

87 Views

Category:

Documents

3 Downloads

Preview:

Click to see full reader

DESCRIPTION

68HC11 Programming Model & Addressing Modes. Notes: Tests will be returned in your studios. Grades will be up by tonight. Today: First Hour : HC11 Programming model Section 1.1-1.5 of Huang’s Textbook In-class Activity #1 Second Hour : Addressing Modes - PowerPoint PPT Presentation

TRANSCRIPT

1

68HC11 Programming 68HC11 Programming Model & Addressing Model & Addressing

ModesModesNotes: Tests will be returned in your studios. Grades will be

up by tonight.

Today:• First Hour: HC11 Programming model

–Section 1.1-1.5 of Huang’s Textbook

– In-class Activity #1

• Second Hour: Addressing Modes

• Section 1.6-1.7 of Huang’s Textbook

– In-class Activity #2

2

Hardware ModelHardware ModelArchitecture, hardware timing Architecture, hardware timing specs, electrical specs, wiring specs, electrical specs, wiring specs, power specs...specs, power specs...

Hardware ModelHardware ModelArchitecture, hardware timing Architecture, hardware timing specs, electrical specs, wiring specs, electrical specs, wiring specs, power specs...specs, power specs...

Recap: Toy CPURecap: Toy CPU

Address Bus

M A R

P C

I R

Memory Address

Bus A C

A

B

M B R

Result Bus

Memory Bus

Memory Data Bus

What does a chip designer need to know

build the computer?

What does a chip designer need to know

build the computer?

3

ProgrammingProgramming• “Program” is the sequence of instructions which

serves as input to the control FSM of the computer.

• “Machine instruction” is a sequence of binary digits which can be executed by the processor

• “Assembly language” : assembly instructions

–An assembly instruction is a mnemonic representation of a machine instruction

–Assembly programs must be translated before it can be executed: translated by an assembler

• “High-level language”: syntax similar to English

–A translator is required to translate the program written in a high-level language to machine language: compiler

4

Programming ModelProgramming ModelProgramming ModelProgramming Model

Toy Programmer’s ViewToy Programmer’s View

What does a programmer

need to know to program the computer?

What does a programmer

need to know to program the computer?

2. RegistersRegisters3. Instruction SetInstruction Set

1. Memory ModelMemory Model

Registers such as MAR and MBR are “invisible” to the programmer

AC (16 bits)

PC (14 bits) Memory

(16 bits wide,

14-bit address)

List of

Instructions

5

Toy InstructionsToy Instructions

16-bit Accumulator

14-bit Program Counter

15 AC 0

13 PC 0

RegistersRegistersRegistersRegisters

What registers

do we need?

What registers

do we need?

Mnemonic Operation Op-code

LOAD mem<qhhh> -> AC 00

STORE AC -> mem<qhhh> 01

ADD AC + mem<qhhh> -> AC 10

BRN IF AC<15> =1 THEN qhhh -> PC 11

6

Programming ModelProgramming ModelInstruction FormatInstruction FormatInstruction FormatInstruction Format

How many bits are needed for the OpCode?

22

How many bits are needed to access any memory location?

1414

16-bit Instruction16-bit Instruction

2-bit OpCode2-bit OpCode

OPOP OPERANDOPERAND

14-bit Operand14-bit Operand

7

What bus do

we take?

What bus do

we take?

Toy Programming ModelToy Programming ModelInstruction SetInstruction SetInstruction SetInstruction Set

Address Bus

M A R

P C

I R

Memory Address

Bus

Mnemonic Operation Op-code

LOAD mem<qhhh> -> AC 00

STORE AC -> mem<qhhh> 01

ADD AC + mem<qhhh> -> AC 10

BRN IF AC<15> =1 THEN qhhh -> PC 11

8

Introducing the M6811Introducing the M6811A “single-chip 8-bit micro-controller”– Intended to control appliances– 8-bit data bus– 16-bit address bus– Integrates many items on one chip:»Clock»CPU»RAM»ROM»Ports for External Input/Output»Several built-in Input/Output devices like

timers, serial and parallel communication

9

ROM-8KB

RAM-256 bytes

EEPROM-512 bytes

PORTA

PULSE ACCUMULATOR

PERIODIC INTERRUPT

COP WATCHDOG

PAIOC2

OC3OC4OC5

OC1

IC1

IC2IC3

PA7

PA6PA5PA4PA3PA2PA1

PA0

PE7

PE6PE5PE4

PE3

PE2

PE1PE0

PORTE

VREFH

VREFL

A/DCONVERTER

DA

TA

DIR

EC

TIO

N

PORTD

SSSCK

MOSI

MISO

SPI

TxD

RxDSCI

PD5

PD4PD3

PD2

PD1

PD0

M68HC11 CPU

ADDRESS DATA BUS

INTERRUPTS

RESET

XIRQ

IRQ(V

PPBULK) HANDSHAKE I/O

DATA DIRECTION C

PORT CPORT B

PARALLELI/O

SINGLECHIP

PB7

PB6

PB5

PB4

PB3

PB2

PB1

PB0

PC7

PC6

PC5

PC4

PC3

PC2

PC1

PC0

STRA

STRB

A15

A14

A13

A12

A11

A10

A9

A8

AD7

AD6

AD5

AD4

AD3

AD2

AD1

AD0

R/W ASEXPAND

OSCILLATOR

XTAL

EXTAL

E

MODALIR

MODB(VSTBY )

VDD

VSS

MODESELECT

POWER

M6811 Hardware ModelM6811 Hardware Model

10

Bus #1

M A R

Memory Address

Bus

A

B

M B R

Bus #2

Memory Data BusRegister File

(A, B, IX, IY, IR)

MUX

FLAGS

P C

M6811 ALUM6811 ALU

11

M6811 Memory ModelM6811 Memory ModelMemory = 64K x 8

$0000

7 mem 0

$FFFF

$hhhh

16-bit Program Counter

15 PC 0

Number Notation

$ denotes hexadecimal

h = 0000 .. 1111

Number Notation

$ denotes hexadecimal

h = 0000 .. 1111

8-bit Accumulator

7 ACCx 0

12

M6811 RegistersM6811 Registers

8-bit Accumulators AA & BB7 A 0 7 B 0

15 D 0 16-bit Accumulator D

- - HH - NN ZZ VV CC CCondition CCode RRegister

CCarry/borrow (MSB)

oVVerflow (2s C)

ZZero

NNegativeHHalf carry (bit 34),(BCD)

15 PC 0 Program CounterProgram Counter

15 IX 0 16-bit Index Register IX

15 IY 0 16-bit Index Register IY

13

M6811 Instruction NotationM6811 Instruction Notation

LDAA (opr) : opr = data in memory

The Load Accumulator A instruction copies the contents of the addressed memory register into the accumulator

This means the contents of memory (M) replaces the contents of accumulator A (A)

denoted by (M) denoted by (M) (A) (A)

Motorola short-hand notation: M M A A

See PRG entry for “LDAA”

14

Sample InstructionSample Instruction

$C120 B6

$C121 C2

$C122 10

$C123 ..

$C210 12

LDAA Transfer content of M($C210) toAccumulator A

Instruction Format

OPCODEOPCODE

Address-High ByteAddress-High Byte

Address-Low ByteAddress-Low Byte

The instruction directly specifies the address

The instruction directly specifies the address

LDAALDAA

15

$C120 B6

$C121 C2

$C122 10

$C123 ..

$C210 12

Memory Segment

LDAA

M6811 Registers

PC

IR

A

B

C1 20

23

45

A & B contain

values from previous

write operations

A & B contain

values from previous

write operations

PC holds address of next instructionPC holds address of next instruction

Example: LDAAExample: LDAA

16

1. Fetch Opcode1. Fetch Opcode

$C120 B6

$C121 C2

$C122 10

$C123 ..

$C210 12

Memory Segment

LDAA

LDAA ExampleM6811 Registers

PC

IR

A

B

C1 20

23

45

21Increment

PC

Increment

PC

B6

17

2. Decode Opcode2. Decode Opcode

$C120 B6

$C121 C2

$C122 10

$C123 ..

$C210 12

Memory Segment

LDAA

M6811 Registers

PC

IR

A

B

C1 21

23

45

B6

LDAA Example

Decode opcode

How many operand bytes?

(Use PRG)

22

Decode opcode

How many operand bytes?

(Use PRG)

22

18

M6811 Registers

PC

IR

A

B

C1

23

45

B6

21

3. Operand Fetch3. Operand Fetch

$C120 B6

$C121 C2

$C122 10

$C123 ..

$C210 12

Memory Segment

LDAA

LDAA Example

Fetch two operand bytes

C2

22Increment

PC

Increment

PC

10

23

Increment

PC

Increment

PC

19

4. Instruction Execution4. Instruction Execution

$C120 B6

$C121 C2

$C122 10

$C123 ..

$C210 12

Memory Segment

LDAA

M6811 Registers

PC

IR

A

B

C1 23

23

45

B6 C2 10

LDAA Example

Get data from memory

Get data from memory

12

20

Do Activity #1 NowDo Activity #1 Now

It is really, really important to bring

the Huang textbook, and

the 6811 manual

To each and every class

21

The LOAD instructions

A group of instructions that place a value or copy the contents of a memorylocation (or locations) into a register

LDAA <opr>LDAB <opr>LDD <opr>LDX <opr>LDY <opr>LDS <opr>

<opr> can be immediate, direct, extended, or index modeExamples

LDAA $10LDX #$1000

HC11 Sample InstructionsHC11 Sample Instructions

22

The ADD instructionA group of instructions perform addition operation

ABAABXABYADDA <opr>ADDB <opr>ADDD <opr>ADCA <opr>ADCB <opr><opr> is specified using an addressing mode

Examples.ADDA #10ADDA $20ADDD $30

23

The SUB instruction

A group of instructions that perform the subtract operation

SBASUBA <opr>SUBB <opr>SUBD <opr>SBCA <opr> ; A [A] - <opr> - C flagSBCB <opr> ; A [B] - <opr> - C flag

<opr> can be one of selected addressing modesExamples

SUBA #10SUBA $10SUBA 0,XSUBD 10,X

24

The STORE instructionA group of instructions that store the contents of a register into a memory location or memory locations

STAA <addr>STAB <addr>STD <addr>STX <addr>STY <addr>STS <addr>

<addr> can be one of selected modeExamples:

STAA $20STAA 10,XSTD $10STD $1000STD 0,X

25

Sample InstructionSample Instruction

$C120 B6

$C121 C2

$C122 10

$C123 ..

$C210 12

LDAA Transfer content of M($C210) toAccumulator A

Instruction Format

OPCODEOPCODE

Address-High ByteAddress-High Byte

Address-Low ByteAddress-Low Byte

The instruction directly specifies the address

The instruction directly specifies the address

This is not the only way to the jobThis is not the only way to the job

How did we specify the operand?How did we specify the operand?

26

Addressing ModesAddressing Modes

SourceForm Operation Boolean

Expression Opcode Operand BytesMachine Code

LDAA Load Accumulator A M A IMMIMM 86 ii 2

DIRDIR 96 dd 2

EXTEXT B6 hh ll 3

IND,XIND,X A6 ff 2

IND,YIND,Y 18 A6 ff 3

AddressingAddressingMode forMode forOperandOperand

5 different ways to specify the operand!5 different ways to specify the operand!

Each way is called an Addressing ModeAddressing Mode

They have differentdifferent OpCodes

They have differentdifferent OpCodes

How do we tell these addressing modes apart?How do we tell these addressing modes apart?

27

Address Mode ExamplesAddress Mode Examples

SourceForm Operation Boolean

Expression Opcode Operand BytesMachine Code

LDAA Load Accumulator A M A IMMIMM 86 ii 2

DIRDIR 96 dd 2

EXTEXT B6 hh ll 3

IND,XIND,X A6 ff 2

IND,YIND,Y 18 A6 ff 3

AddressingAddressingMode forMode forOperandOperand

IMM (immediate)86 28 : LDAA #$28

Load ACCA with the "immediate"constant $28

IMM (immediate)86 28 : LDAA #$28

Load ACCA with the "immediate"constant $28

DIR (direct)96 28 : LDAA $28

Load ACCA with the content of memoryaddress $000028

DIR (direct)96 28 : LDAA $28

Load ACCA with the content of memoryaddress $000028

How much of the address space can we "reach" with DIR?

256 BytesWhat is this mode good for?

Saves Bytes & Fetches

How much of the address space can we "reach" with DIR?

256 BytesWhat is this mode good for?

Saves Bytes & Fetches

28

Address Mode Examples-2Address Mode Examples-2

SourceForm Operation Boolean

Expression Opcode Operand BytesMachine Code

LDAA Load Accumulator A M A IMMIMM 86 ii 2

DIRDIR 96 dd 2

EXTEXT B6 hh ll 3

IND,XIND,X A6 ff 2

IND,YIND,Y 18 A6 ff 3

AddressingAddressingMode forMode forOperandOperand

EXT (extended)B6 C128 : LDAA $C128

Load ACCA with the content of memoryaddress $C128

EXT (extended)B6 C128 : LDAA $C128

Load ACCA with the content of memoryaddress $C128

How much of the address space can we "reach" with EXT?

65536 BytesWhat is this mode good for?

Reaches all memory

How much of the address space can we "reach" with EXT?

65536 BytesWhat is this mode good for?

Reaches all memory

29

Address Mode Examples-3Address Mode Examples-3

SourceForm Operation Boolean

Expression Opcode Operand BytesMachine Code

LDAA Load Accumulator A M A IMMIMM 86 ii 2

DIRDIR 96 dd 2

EXTEXT B6 hh ll 3

IND,XIND,X A6 ff 2

IND,YIND,Y 18 A6 ff 3

AddressingAddressingMode forMode forOperandOperand

IND,X (indexed,X)A6 28: LDAA $28,X

Load ACCA with the content of memory address (EA), where

EA = IX + $28IX is called an Index Register It holds a 16-bit base address

The operand is an unsignedunsigned offset byteEA = Base + Offset

There’s another index register, IY

IND,X (indexed,X)A6 28: LDAA $28,X

Load ACCA with the content of memory address (EA), where

EA = IX + $28IX is called an Index Register It holds a 16-bit base address

The operand is an unsignedunsigned offset byteEA = Base + Offset

There’s another index register, IY

How much of the address space can we "reach" with IND,X?

256 BytesWhat is this mode good for?Addressing elements in an array

How much of the address space can we "reach" with IND,X?

256 BytesWhat is this mode good for?Addressing elements in an array

30

NeedNeed Addressing ModeAddressing Mode

Reach the first 256 RAM Directlocations quickly

Load a constant without having Immediateto first put it in memory

Access arrays of numbers Indexedefficiently, implement pointers

We’ll do array and pointer examples later...We’ll do array and pointer examples later...

What’s the big idea?What’s the big idea?All of the addressing modes were developed in response to specific needsAll of the addressing modes were developed in response to specific needs

31

Immediate OP CODE

DATA

Direct OP CODE

Address-Low00 Address-Low

Extended OP CODE

Address-High

Address-Low

Address-High Address-Low

Indexed OP CODE

Offset

Index Register

Address-High Address-Low

Effective Address

Address Mode SummaryAddress Mode SummaryOP CODE

DATA-High

DATA-Low

16-bit data

32

Do Activity #2 NowDo Activity #2 NowDue: End of Class Today.

RETAIN THE LAST PAGE(S) (#3 onwards)!!

For Next Class:• Bring Huang Textbook, & HC11 PRG

• Required Reading:– Sec 2.1-2.4, 2.8 of Huang

• This reading is necessary for getting points in the Studio Activity!

top related