Sie sind auf Seite 1von 62

Topic Video 03B

Assembly Language: Instructions 1

3B

Thursday, 2 July 2009

The HS12 Instruction Set


The CPUS12 has over 200 different instructions, performing 188 different tasks. The instruction are split into categories, these are:
Load and Store Transfer and Exchange Move Memory Decrement and Increment Arithmetic Logic Rotates and Shifts Data Test

Conditional Branches Loop Primitives Jump and Branch Condition Code Interrupt

Thursday, 2 July 2009

The HS12 Instruction Set


Load and Store Instructions
The load and store instructions allows us to move data in and out of the registers. Depending on the size of the register, this data can be byte size or words (16 bit) size. There are load and store in instructions that can operate on:
Accumulator A Accumulator B Accumulator D X index Register Y index Register Stack Pointer Load LDAA LDAB LDD LDX LDY LDS Store STAA STAB STD STX STY STS

Thursday, 2 July 2009

The HS12 Instruction Set


Load and Store Instructions (Continued) Examples
Immediate LDAA #$23 LDAB LDD LDY LDX #$FA #$4523 #3465 #65563 Direct/ Extended LDAA Val LDAB LDD LDX LDY Byte $1234 Data Value Indexed LDAA 0,X LDAB LDD LDX LDY 0,Y 0,SP 0,Y 0,PC

Thursday, 2 July 2009

The HS12 Instruction Set


Load and Store Instructions (Continued) Examples
Direct/ Extended STAA Val STAB STD STX STY Byte $1234 Data Value Indexed STAA 0,X STAB STD STX STY 0,Y 0,SP 0,Y 0,PC

Thursday, 2 July 2009

The HS12 Instruction Set


Load and Store Instructions (Continued)

There is another way that we can load or store values. We can use the stack. The act of storing a value onto the stack is called PUSHING. The act of loading a value from the stack is called PULLING. The PULL and PUSH instructions that can operate on:

Accumulator A Accumulator B Accumulator D X index Register Y index Register

Pull PULA PULB PULD PULX PULY

Push PSHA PSHB PSHD PSHX PSHY

Thursday, 2 July 2009

The HS12 Instruction Set


Load and Store Instructions (Continued) Example
... LDAA PSHA ...

#32 #SP=SP-1, M[SP]=A

Thursday, 2 July 2009

The HS12 Instruction Set


Transfer Instructions
The Transfer Instructions allow us to move data within the CPU from one register to another.

Transfer A to B Transfer B to A Transfer Registers Transfer SP to X Transfer SP to Y Transfer X to SP Transfer Y to SP Exchange Registers Exchange D and X Exchange D and Y Exchange B and A

TAB TBA TFR TFR TFR TFR TFR EXG EXG EXG EXG

Source Register, Destination Register S,X S,Y X,S Y,S Register1, Register 2 D,X D,Y B,A

Thursday, 2 July 2009

The HS12 Instruction Set


Transfer Instructions

8 bit value 8 bit register

8 bit register

16 bit value 16 bit register


Thursday, 2 July 2009

16 bit register
9

The HS12 Instruction Set


Transfer Instructions

8 bit register

8 bit value 8 bit register

16 bit value 16 bit register


Thursday, 2 July 2009

16 bit register
9

The HS12 Instruction Set


Transfer Instructions
But what happens if the registers are different sizes?

MSB LSB 16 bit register 8 bit value 8 bit register LSB 16 bit register
Thursday, 2 July 2009

8 bit register

16 bit register 8 bit value 8 bit register


10

The HS12 Instruction Set


Transfer Instructions
But what happens if the registers are different sizes?

MSB LSB 16 bit register 8 bit value 8 bit register LSB 16 bit register
Thursday, 2 July 2009

LSB 8 bit register

16 bit register 8 bit value 8 bit register


10

The HS12 Instruction Set


Transfer Instructions
But what happens if the registers are different sizes?

MSB LSB 16 bit register 8 bit value 8 bit register LSB 16 bit register
Thursday, 2 July 2009

LSB 8 bit register MSB=0 8 bit value 16 bit register 8 bit value 8 bit register
10

The HS12 Instruction Set


Transfer Instructions
But what happens if the registers are different sizes?

MSB LSB 16 bit register 8 bit value 8 bit register MSB=0 8 bit value 16 bit register
Thursday, 2 July 2009

LSB 8 bit register MSB=0 8 bit value 16 bit register LSB 8 bit register
10

The HS12 Instruction Set


Move Instructions Using the MOVE instructions it is possible to transfer data from one memory location to another without the need for a register. The MOVE instructions have two possible forms; MOVB for moving bytes and MOVW, for moving words. The source can be a constant or a memory location, however the destination must always be a memory address. Move (copy) a byte Move (copy) a word MOVB Source, Destination MOVW Source, Destination

Thursday, 2 July 2009

11

The HS12 Instruction Set


Move Instructions

MOVB 23

#23, Data

MOVB PortA, Data

M[Data]
MOVB #$FF, PortA $FF

8 bit value M[PortA]

M[Data]

MOVB #23, $1234 23

M[PortA]
Thursday, 2 July 2009

M[$1234]
12

The HS12 Instruction Set


Move Instructions

MOVB 23

#23, Data 23

MOVB PortA, Data

M[Data]
MOVB #$FF, PortA $FF

8 bit value M[PortA]

M[Data]

MOVB #23, $1234 23

M[PortA]
Thursday, 2 July 2009

M[$1234]
12

The HS12 Instruction Set


Move Instructions

MOVB 23

#23, Data 23

MOVB PortA, Data

M[Data]
MOVB #$FF, PortA $FF

8 bit value M[PortA]

8 bit value M[Data]

MOVB #23, $1234 23

M[PortA]
Thursday, 2 July 2009

M[$1234]
12

The HS12 Instruction Set


Move Instructions

MOVB 23

#23, Data 23

MOVB PortA, Data

M[Data]
MOVB #$FF, PortA $FF $FF

8 bit value M[PortA]

8 bit value M[Data]

MOVB #23, $1234 23

M[PortA]
Thursday, 2 July 2009

M[$1234]
12

The HS12 Instruction Set


Move Instructions

MOVB 23

#23, Data 23

MOVB PortA, Data

M[Data]
MOVB #$FF, PortA $FF $FF

8 bit value M[PortA]

8 bit value M[Data]

MOVB #23, $1234 23 23

M[PortA]
Thursday, 2 July 2009

M[$1234]
12

The HS12 Instruction Set


Move Instructions

MOVW

#$1423, Data

$14 $23
MOVW PortA, Data

M[Data](MSB) M[Data+1](LSB)

Port A Port B

8 bit value 8 bit value

M[Data](MSB) M[Data+1](LSB)

Thursday, 2 July 2009

13

The HS12 Instruction Set


Move Instructions

MOVW

#$1423, Data

$14 $23
MOVW PortA, Data

$14 $23

M[Data](MSB) M[Data+1](LSB)

Port A Port B

8 bit value 8 bit value

M[Data](MSB) M[Data+1](LSB)

Thursday, 2 July 2009

13

The HS12 Instruction Set


Move Instructions

MOVW

#$1423, Data

$14 $23
MOVW PortA, Data

$14 $23

M[Data](MSB) M[Data+1](LSB)

Port A Port B

8 bit value 8 bit value

8 bit value 8 bit value

M[Data](MSB) M[Data+1](LSB)

Thursday, 2 July 2009

13

The HS12 Instruction Set


Decrement and Increment Instructions

Using the increment and decrement commands it is possible to increase or decrease the value in a register or memory location by 1. We can use this commands on: Accumulator A Accumulator B X index Register Y index Register Stack Pointer Memory Increment INCA INCB INX INY INS INC mem Decrement DECA DECB DEX DEY DES DEC mem

Thursday, 2 July 2009

14

The HS12 Instruction Set


Decrement and Increment Instructions Examples
mainLoop: JSR LDAB INCB JSR BRA EQU INCLUDE ... InitSCI #2 OUT2HEX Spin $00D0;Base Address for SCI. 'Serial.inc';Add serial routines

Spin: Serial_Base

Thursday, 2 July 2009

15

The HS12 Instruction Set


Decrement and Increment Instructions
mainLoop: JSR InitSCI MOVB #2,Counter INC Counter LDAB Counter JSR OUT2HEX BRA Spin EQU $00D0 ;Base Address for SCI INCLUDE 'Serial.inc' ;Add serial routines DS 1 ...

Spin: Serial_Base Counter

Thursday, 2 July 2009

16

The HS12 Instruction Set


Clear and Set Instructions The clear and set instructions allows us to clear accumulator A, B or even a memory location (variable). They also allows us to set or clear particular bits in a memory location without affecting those bit near it. Clear Accumulator A Clear Accumulator B Clear Memory CLRA CLRB CLR emory location m

Thursday, 2 July 2009

17

The HS12 Instruction Set


Clear and Set Instructions
Bit Clear Bit Set BCLR BSET Operand, Mask Operand, Mask

The operand is a memory location or variable name. The Mask species the bits to be set or cleared. The Mask consists of a binary number, the bit locations were a 1 appear the locations that are cleared (BCLR) or set (BSET).

Thursday, 2 July 2009

18

The HS12 Instruction Set


Clear and Set Instructions Example

MOVB #%10101010,PortA %10101010 BSET PortA, %11110000 BCLR PortA, %10101010

PortA

Thursday, 2 July 2009

19

The HS12 Instruction Set


Clear and Set Instructions Example

MOVB #%10101010,PortA BSET PortA, %11110000 BCLR PortA, %10101010

PortA

%10101010

Thursday, 2 July 2009

19

The HS12 Instruction Set


Clear and Set Instructions Example

MOVB #%10101010,PortA BSET PortA, %11110000 BCLR PortA, %10101010

PortA

%10101010

Thursday, 2 July 2009

19

The HS12 Instruction Set


Clear and Set Instructions Example

MOVB #%10101010,PortA BSET PortA, %11110000 BCLR PortA, %10101010

PortA

%10101010

Thursday, 2 July 2009

19

The HS12 Instruction Set


Clear and Set Instructions Example

MOVB #%10101010,PortA BSET PortA, %11110000 BCLR PortA, %10101010

PortA

%11111010

Thursday, 2 July 2009

19

The HS12 Instruction Set


Clear and Set Instructions Example

MOVB #%10101010,PortA BSET PortA, %11110000 BCLR PortA, %10101010

PortA

%11111010

Thursday, 2 July 2009

19

The HS12 Instruction Set


Clear and Set Instructions Example

MOVB #%10101010,PortA BSET PortA, %11110000 BCLR PortA, %10101010

PortA

%11111010

Thursday, 2 July 2009

19

The HS12 Instruction Set


Clear and Set Instructions Example

MOVB #%10101010,PortA BSET PortA, %11110000 BCLR PortA, %10101010

PortA

%01010000

Thursday, 2 July 2009

19

The HS12 Instruction Set


Clear and Set Instructions Example

MOVB #%10101010,PortA BSET PortA, %11110000 BCLR PortA, %10101010

PortA

%01010000

Thursday, 2 July 2009

19

The HS12 Instruction Set


Shift and Rotate Instructions We can use the the shift and rotate instructions on accumulators A, B, D or even directly on memory.
Arithmetic Shifting Accumulator A Accumulator B Accumulator D Memory Left ASLA ASLB ASLD Right ASRA ASRB ASRD ASR mem

ASL mem Right LSRA LSRB

Logical Shifting Accumulator A Accumulator B Accumulator D Memory

Left LSLA LSLB LSLD LSL mem

LSRD LSR mem

Thursday, 2 July 2009

20

The HS12 Instruction Set


Shift and Rotate Instructions

Logical Shift Left / Arithmetic Shift Left 0 CCR[C] 0 0 0 0 0 0 0 1

Thursday, 2 July 2009

21

The HS12 Instruction Set


Shift and Rotate Instructions

Logical Shift Left / Arithmetic Shift Left 0 CCR[C] 0 0 0 0 0 0 1

Thursday, 2 July 2009

22

The HS12 Instruction Set


Shift and Rotate Instructions

Logical Shift Left / Arithmetic Shift Left 0 CCR[C] 0 0 0 0 0 0 1 0

Thursday, 2 July 2009

22

The HS12 Instruction Set


Shift and Rotate Instructions

Logical Shift Left / Arithmetic Shift Left 0 CCR[C] 0 0 0 0 0 1 0

Thursday, 2 July 2009

23

The HS12 Instruction Set


Shift and Rotate Instructions

Logical Shift Left / Arithmetic Shift Left 0 CCR[C] 0 0 0 0 0 1 0 0

Thursday, 2 July 2009

23

The HS12 Instruction Set


Shift and Rotate Instructions

Logical Shift Left / Arithmetic Shift Left 0 CCR[C] 0 0 0 0 1 0 0

Thursday, 2 July 2009

24

The HS12 Instruction Set


Shift and Rotate Instructions

Logical Shift Left / Arithmetic Shift Left 0 CCR[C] 0 0 0 0 1 0 0 0

Thursday, 2 July 2009

24

The HS12 Instruction Set


Shift and Rotate Instructions

Logical Shift Left / Arithmetic Shift Left 0 CCR[C] 1 0 0 0 0 0 0

Thursday, 2 July 2009

25

The HS12 Instruction Set


Shift and Rotate Instructions

Logical Shift Left / Arithmetic Shift Left 0 CCR[C] 1 0 0 0 0 0 0 0

Thursday, 2 July 2009

25

The HS12 Instruction Set


Shift and Rotate Instructions

Logical Shift Left / Arithmetic Shift Left 1 CCR[C] 0 0 0 0 0 0 0

Thursday, 2 July 2009

26

The HS12 Instruction Set


Shift and Rotate Instructions

Logical Shift Left / Arithmetic Shift Left 1 CCR[C] 0 0 0 0 0 0 0 0

Thursday, 2 July 2009

26

The HS12 Instruction Set


Shift and Rotate Instructions

CCR[C]

0 1 0

Logical Shift Right 0 0 0 0 0 0

CCR[C] 1

Arithmetic Shift Right 0 0 0 0 0 0 0

Thursday, 2 July 2009

27

The HS12 Instruction Set


Shift and Rotate Instructions

CCR[C]

0 1 0

Logical Shift Right 0 0 0 0 0 0

CCR[C]

1 1

Arithmetic Shift Right 0 0 0 0 0 0 0

Thursday, 2 July 2009

27

The HS12 Instruction Set


Shift and Rotate Instructions

CCR[C]

Logical Shift Right 1 0 0 0 0 0 0 0

CCR[C]

Arithmetic Shift Right 1 0 0 0 0 0 0 0

Thursday, 2 July 2009

28

The HS12 Instruction Set


Shift and Rotate Instructions

CCR[C] 0 0

Logical Shift Right 1 0 0 0 0 0 0

CCR[C] 0 1

Arithmetic Shift Right 1 0 0 0 0 0 0

Thursday, 2 July 2009

28

The HS12 Instruction Set


Shift and Rotate Instructions

CCR[C]

Logical Shift Right 0 1 0 0 0 0 0 0

CCR[C]

Arithmetic Shift Right 1 1 0 0 0 0 0 0

Thursday, 2 July 2009

29

The HS12 Instruction Set


Shift and Rotate Instructions

CCR[C] 0 0

Logical Shift Right 0 1 0 0 0 0 0

CCR[C] 0 1

Arithmetic Shift Right 1 1 0 0 0 0 0

Thursday, 2 July 2009

29

The HS12 Instruction Set


Shift and Rotate Instructions We can use the the shift and rotate instructions on accumulators A, B, D or even directly on memory.
Rotating Left ROLA ROLB ROLD ROL Right RORA RORB RORD ROR

Accumulator A Accumulator B Accumulator D Memory

Thursday, 2 July 2009

30

The HS12 Instruction Set


Shift and Rotate Instructions

CCR[C] X 0 1

Rotate Right 0 0 0 0 0 0

CCR[C] X 0 0

Rotate Left 0 0 0 0 0 0

Thursday, 2 July 2009

31

The HS12 Instruction Set


Shift and Rotate Instructions

CCR[C] 0 0

Rotate Right 1 0 0 0 0 0 0

CCR[C] 0 1 0 0

Rotate Left 0 0 0 0 0

Thursday, 2 July 2009

32

The HS12 Instruction Set


Shift and Rotate Instructions

CCR[C] 0 0 0

Rotate Right 1 0 0 0 0 0

CCR[C] 1 0 0

Rotate Left 0 0 0 0 0 0

Thursday, 2 July 2009

32

The HS12 Instruction Set


Shift and Rotate Instructions

CCR[C] 0 0

Rotate Right 0 1 0 0 0 0 0

CCR[C] 1 0 0 0

Rotate Left 0 0 0 0 0

Thursday, 2 July 2009

33

The HS12 Instruction Set


Shift and Rotate Instructions

CCR[C] 0 0 0

Rotate Right 0 1 0 0 0 0

CCR[C] 0 0 0

Rotate Left 0 0 0 0 0 1

Thursday, 2 July 2009

33

Need Further Assistance?


Ask your Demonstrator, Post a question on the Forum, Email the Convener, or Make an appointment.
Thursday, 2 July 2009 34

Das könnte Ihnen auch gefallen