131
Introduction to The 68k Introduction to The 68k QP

Chp2introductiontothe68000microprocessor Copy 110627223604 Phpapp01

Embed Size (px)

Citation preview

8/3/2019 Chp2introductiontothe68000microprocessor Copy 110627223604 Phpapp01

http://slidepdf.com/reader/full/chp2introductiontothe68000microprocessor-copy-110627223604-phpapp01 1/131

8/3/2019 Chp2introductiontothe68000microprocessor Copy 110627223604 Phpapp01

http://slidepdf.com/reader/full/chp2introductiontothe68000microprocessor-copy-110627223604-phpapp01 2/131

68k Instruction Set68k Instruction Set

MOVE.B D0, D1

Opcode Operand

Source

DestinationSize

8/3/2019 Chp2introductiontothe68000microprocessor Copy 110627223604 Phpapp01

http://slidepdf.com/reader/full/chp2introductiontothe68000microprocessor-copy-110627223604-phpapp01 3/131

Assembly Language ProgammingAssembly Language Progamming

Machine Instruction

0011 0000 0000 0011

0011

Op-code

000000

Firstoperand

000111

Secondoperand

Ty pes of instruction i.e. addition or subtraction

Data size, byte, word or long word

The amount of the word in complete instruction

Where the data for an instruction (operand) can find

8/3/2019 Chp2introductiontothe68000microprocessor Copy 110627223604 Phpapp01

http://slidepdf.com/reader/full/chp2introductiontothe68000microprocessor-copy-110627223604-phpapp01 4/131

Cycle of InstructionCycle of Instruction

Collection Implement

8/3/2019 Chp2introductiontothe68000microprocessor Copy 110627223604 Phpapp01

http://slidepdf.com/reader/full/chp2introductiontothe68000microprocessor-copy-110627223604-phpapp01 5/131

Cycle of InstructionCycle of Instruction cont«cont«

Collection phase: Fill-in program counter with 

instruction address

Collect instruction from memor y, putin the instruction register 

For control the instruction, clean-up

PC for next instruction

Implement phase:

Count for the operation address Collect operation

Do the operation

Store the product of operation

Back to first step

8/3/2019 Chp2introductiontothe68000microprocessor Copy 110627223604 Phpapp01

http://slidepdf.com/reader/full/chp2introductiontothe68000microprocessor-copy-110627223604-phpapp01 6/131

68K Addressing Modes68K Addressing Modes

Addressing ModesAddressing Modes SyntaxSyntax

Register Direct Addressing

Data Register Direct Address Register Direct

Dn An

Absolute Data Addressing

  Absolute Short  Absolute Long

xxx.Wxxx.L

Program Counter Relative Addressing

Relative with offsetRelative with Index Offset

d16 (PC)d8 (PC,Xn)

Register Indirect Addressing

Register IndirectPostincrement Register IndirectPredecrement Register IndirectRegister Indirect with OffsetIndexed Register Indirect with offset

(An)(An)+-(An)

d16(An)d8 (An, Xn)

Immediate Data addressing

ImmediateQuick Immediate

#xxx#1-#8

Implied Addressing

Implied Register  SR USP SP PC

8/3/2019 Chp2introductiontothe68000microprocessor Copy 110627223604 Phpapp01

http://slidepdf.com/reader/full/chp2introductiontothe68000microprocessor-copy-110627223604-phpapp01 7/131

R egister Direct AddressingR egister Direct Addressing

Data R egister Direct

MOVE.B D0,D3

8/3/2019 Chp2introductiontothe68000microprocessor Copy 110627223604 Phpapp01

http://slidepdf.com/reader/full/chp2introductiontothe68000microprocessor-copy-110627223604-phpapp01 8/131

R egister Direct AddressingR egister Direct Addressing

Data R egister Direct

MOVE.W D0,D3

Cont«

8/3/2019 Chp2introductiontothe68000microprocessor Copy 110627223604 Phpapp01

http://slidepdf.com/reader/full/chp2introductiontothe68000microprocessor-copy-110627223604-phpapp01 9/131

R egister Direct AddressingR egister Direct Addressing

Data R egister Direct

MOVE.L D0,D3

Cont«

8/3/2019 Chp2introductiontothe68000microprocessor Copy 110627223604 Phpapp01

http://slidepdf.com/reader/full/chp2introductiontothe68000microprocessor-copy-110627223604-phpapp01 10/131

R egister Direct AddressingR egister Direct Addressing

Address R egister Direct

MOVEA.L A3,A0

Cont«

8/3/2019 Chp2introductiontothe68000microprocessor Copy 110627223604 Phpapp01

http://slidepdf.com/reader/full/chp2introductiontothe68000microprocessor-copy-110627223604-phpapp01 11/131

R egister Direct AddressingR egister Direct Addressing

Address R egister Direct

MOVEA A3,A0

Cont«

8/3/2019 Chp2introductiontothe68000microprocessor Copy 110627223604 Phpapp01

http://slidepdf.com/reader/full/chp2introductiontothe68000microprocessor-copy-110627223604-phpapp01 12/131

Absolute Data AddressingAbsolute Data Addressing

Absolute Long Mode

CLR.B $10000

010000 42 51 p 010000 00 51

010002 55 13 010002 55 13

8/3/2019 Chp2introductiontothe68000microprocessor Copy 110627223604 Phpapp01

http://slidepdf.com/reader/full/chp2introductiontothe68000microprocessor-copy-110627223604-phpapp01 13/131

Absolute Data AddressingAbsolute Data Addressing

Absolute Long Mode

CLR.W $10000

010000 42 51 p 010000 00 00

010002 55 13 010002 55 13

Cont«

8/3/2019 Chp2introductiontothe68000microprocessor Copy 110627223604 Phpapp01

http://slidepdf.com/reader/full/chp2introductiontothe68000microprocessor-copy-110627223604-phpapp01 14/131

Absolute Data AddressingAbsolute Data Addressing

Absolute Long Mode

CLR.L $10000

010000 42 51 p 010000 00 00

010002 55 13 010002 00 00

Cont«

8/3/2019 Chp2introductiontothe68000microprocessor Copy 110627223604 Phpapp01

http://slidepdf.com/reader/full/chp2introductiontothe68000microprocessor-copy-110627223604-phpapp01 15/131

Absolute Data AddressingAbsolute Data Addressing

Absolute Short Mode

CLR.B $1000

01000 42 51 p 01000 00 51

01002 55 13 01002 55 13

Cont«

8/3/2019 Chp2introductiontothe68000microprocessor Copy 110627223604 Phpapp01

http://slidepdf.com/reader/full/chp2introductiontothe68000microprocessor-copy-110627223604-phpapp01 16/131

Absolute Short vsAbsolute Short vsAbsolute LongAbsolute Long

Absolute short: 16-bit (0000~7FFF, 8000~FFFF)

Sign extend the 16-bit value into 24-bit

(000000~007FFF, FF8000~FFFFFF)

Absolute Long:

24-bit(000000~FFFFFF) No sign extension

Cont«

8/3/2019 Chp2introductiontothe68000microprocessor Copy 110627223604 Phpapp01

http://slidepdf.com/reader/full/chp2introductiontothe68000microprocessor-copy-110627223604-phpapp01 17/131

PC R elative AddressingPC R elative Addressing

PC R elative with Offset

MOVE.W $1200(PC), D5

Assume the instruction is located at $122000

Effective address:

$00122002 + $00001200 = $00123202

8/3/2019 Chp2introductiontothe68000microprocessor Copy 110627223604 Phpapp01

http://slidepdf.com/reader/full/chp2introductiontothe68000microprocessor-copy-110627223604-phpapp01 18/131

PC R elative AddressingPC R elative AddressingCont«

PC R elative with Offset

8/3/2019 Chp2introductiontothe68000microprocessor Copy 110627223604 Phpapp01

http://slidepdf.com/reader/full/chp2introductiontothe68000microprocessor-copy-110627223604-phpapp01 19/131

PC R elative AddressingPC R elative Addressing

PC R elative with Index and Offset

MOVE.L -20(PC,A2.L),D5

Assume the instruction is located at $00010200

Effective address:

$00010202 + $00020030 + $FFFFFFEC =$0003021E

Cont«

8/3/2019 Chp2introductiontothe68000microprocessor Copy 110627223604 Phpapp01

http://slidepdf.com/reader/full/chp2introductiontothe68000microprocessor-copy-110627223604-phpapp01 20/131

PC R elative AddressingPC R elative Addressing

PC R elative with Index and Offset

Cont«

8/3/2019 Chp2introductiontothe68000microprocessor Copy 110627223604 Phpapp01

http://slidepdf.com/reader/full/chp2introductiontothe68000microprocessor-copy-110627223604-phpapp01 21/131

R egister Indirect AddressingR egister Indirect Addressing

MOVE.L D0,(A0)

8/3/2019 Chp2introductiontothe68000microprocessor Copy 110627223604 Phpapp01

http://slidepdf.com/reader/full/chp2introductiontothe68000microprocessor-copy-110627223604-phpapp01 22/131

8/3/2019 Chp2introductiontothe68000microprocessor Copy 110627223604 Phpapp01

http://slidepdf.com/reader/full/chp2introductiontothe68000microprocessor-copy-110627223604-phpapp01 23/131

Address R egister IndirectAddress R egister IndirectAddressing PredecrementAddressing Predecrement

MOVE.W D0,-(A6)

8/3/2019 Chp2introductiontothe68000microprocessor Copy 110627223604 Phpapp01

http://slidepdf.com/reader/full/chp2introductiontothe68000microprocessor-copy-110627223604-phpapp01 24/131

Address R egister IndirectAddress R egister IndirectAddressing With OffsetAddressing With Offset

MOVE.W 6(A0),D0

8/3/2019 Chp2introductiontothe68000microprocessor Copy 110627223604 Phpapp01

http://slidepdf.com/reader/full/chp2introductiontothe68000microprocessor-copy-110627223604-phpapp01 25/131

Address R egister IndirectAddress R egister IndirectAddressing with Index & OffsetAddressing with Index & Offset

MOVE.W $10(A0,D0.L), A1

8/3/2019 Chp2introductiontothe68000microprocessor Copy 110627223604 Phpapp01

http://slidepdf.com/reader/full/chp2introductiontothe68000microprocessor-copy-110627223604-phpapp01 26/131

Immediate AddressingImmediate Addressing

Immediate

MOVE.L #$1FFFF, D0

Before:D0 = 12345678

After: D0 = 0001FFFF

 Note:$ = value for hexadecimal

@ = value for octal

% = value for binar y

& or blank = decimal

µAB¶ = character ASCII

8/3/2019 Chp2introductiontothe68000microprocessor Copy 110627223604 Phpapp01

http://slidepdf.com/reader/full/chp2introductiontothe68000microprocessor-copy-110627223604-phpapp01 27/131

Immediate AddressingImmediate Addressing

Quick Immediate

1. MOVEQ #$2C, D3

Before: D3 = 1234562C

After: D3 = 0000002C

2. MOVEQ #$8F, D3

Before: D3 = 1234568F

After: D3 = FFFFFF8F

Cont«

8/3/2019 Chp2introductiontothe68000microprocessor Copy 110627223604 Phpapp01

http://slidepdf.com/reader/full/chp2introductiontothe68000microprocessor-copy-110627223604-phpapp01 28/131

Implied AddressingImplied Addressing

ANDI #$27, SR

MOVE CCR, CODES

TRAPV

8/3/2019 Chp2introductiontothe68000microprocessor Copy 110627223604 Phpapp01

http://slidepdf.com/reader/full/chp2introductiontothe68000microprocessor-copy-110627223604-phpapp01 29/131

68K Instruction Set68K Instruction Set

Data transfer

Arithmetic

Logical

Shift and rotate Bit manipulation

BCD operations

Program control

System control

8/3/2019 Chp2introductiontothe68000microprocessor Copy 110627223604 Phpapp01

http://slidepdf.com/reader/full/chp2introductiontothe68000microprocessor-copy-110627223604-phpapp01 30/131

68K Instruction Set68K Instruction SetCont«

Data Transfer Instructions

8/3/2019 Chp2introductiontothe68000microprocessor Copy 110627223604 Phpapp01

http://slidepdf.com/reader/full/chp2introductiontothe68000microprocessor-copy-110627223604-phpapp01 31/131

68K Instruction Set68K Instruction SetCont«

Integer Arithmetic Instructions

8/3/2019 Chp2introductiontothe68000microprocessor Copy 110627223604 Phpapp01

http://slidepdf.com/reader/full/chp2introductiontothe68000microprocessor-copy-110627223604-phpapp01 32/131

68K Instruction Set68K Instruction SetCont«

Compare and Test Instructions

8/3/2019 Chp2introductiontothe68000microprocessor Copy 110627223604 Phpapp01

http://slidepdf.com/reader/full/chp2introductiontothe68000microprocessor-copy-110627223604-phpapp01 33/131

68K Instruction Set68K Instruction SetCont«

Logic Instructions

8/3/2019 Chp2introductiontothe68000microprocessor Copy 110627223604 Phpapp01

http://slidepdf.com/reader/full/chp2introductiontothe68000microprocessor-copy-110627223604-phpapp01 34/131

68K Instruction Set68K Instruction SetCont«

Shift Instructions

8/3/2019 Chp2introductiontothe68000microprocessor Copy 110627223604 Phpapp01

http://slidepdf.com/reader/full/chp2introductiontothe68000microprocessor-copy-110627223604-phpapp01 35/131

68K Instruction Set68K Instruction SetCont«

Rotate Instructions

8/3/2019 Chp2introductiontothe68000microprocessor Copy 110627223604 Phpapp01

http://slidepdf.com/reader/full/chp2introductiontothe68000microprocessor-copy-110627223604-phpapp01 36/131

68K Instruction Set68K Instruction SetCont«

Bit-Manipulation Instructions

8/3/2019 Chp2introductiontothe68000microprocessor Copy 110627223604 Phpapp01

http://slidepdf.com/reader/full/chp2introductiontothe68000microprocessor-copy-110627223604-phpapp01 37/131

68K Instruction Set68K Instruction SetCont«

Subroutine Control Instructions

8/3/2019 Chp2introductiontothe68000microprocessor Copy 110627223604 Phpapp01

http://slidepdf.com/reader/full/chp2introductiontothe68000microprocessor-copy-110627223604-phpapp01 38/131

68K Instruction Set68K Instruction SetCont«

Binary-Coded Decimal Arithmetic Instructions

8/3/2019 Chp2introductiontothe68000microprocessor Copy 110627223604 Phpapp01

http://slidepdf.com/reader/full/chp2introductiontothe68000microprocessor-copy-110627223604-phpapp01 39/131

Data Transfer InstructionData Transfer Instruction

Take Data from Memory ± Operation Load

MOVE.W $10000, D1

D1 FE ED BE EF D1 FE ED 42 51

010000 42 51 010000 42 51

010002 55 13 010002 55 13

8/3/2019 Chp2introductiontothe68000microprocessor Copy 110627223604 Phpapp01

http://slidepdf.com/reader/full/chp2introductiontothe68000microprocessor-copy-110627223604-phpapp01 40/131

Data Transfer InstructionData Transfer Instruction

Take Data from Memory ± Operation Load

MOVE.L $1000, D1

D1 FE ED BE EF D1 42 51 55 13

01000 42 51 01000 42 51

01002 55 13 01002 55 13

Cont«

8/3/2019 Chp2introductiontothe68000microprocessor Copy 110627223604 Phpapp01

http://slidepdf.com/reader/full/chp2introductiontothe68000microprocessor-copy-110627223604-phpapp01 41/131

Data Transfer InstructionData Transfer Instruction

Take Data from Memory ± Operation Load

MOVE.B $1000, D1

D1 FE ED BE EF D1 FE ED BE 42

01000 42 51 01000 42 51

01002 55 13 01002 55 13

Cont«

8/3/2019 Chp2introductiontothe68000microprocessor Copy 110627223604 Phpapp01

http://slidepdf.com/reader/full/chp2introductiontothe68000microprocessor-copy-110627223604-phpapp01 42/131

Data Transfer InstructionData Transfer Instruction

Store Data into Memory ± Operation Save

MOVE.W D1, $1000

D1 FE ED BE EF D1 FE ED BE EF

01000 42 51 01000 BE EF

01002 55 13 01002 55 13

Cont«

8/3/2019 Chp2introductiontothe68000microprocessor Copy 110627223604 Phpapp01

http://slidepdf.com/reader/full/chp2introductiontothe68000microprocessor-copy-110627223604-phpapp01 43/131

Data Transfer InstructionData Transfer Instruction

Store Data into Memory ± Operation Save

MOVE.L D1, $1000

D1 FE ED BE EF D1 FE ED BE EF

01000 42 51 01000 FE ED

01002 55 13 01002 BE EF

Cont«

8/3/2019 Chp2introductiontothe68000microprocessor Copy 110627223604 Phpapp01

http://slidepdf.com/reader/full/chp2introductiontothe68000microprocessor-copy-110627223604-phpapp01 44/131

Data Transfer InstructionData Transfer Instruction

Store Data into Memory ± Operation Save

MOVE.B D1, $1000

D1 FE ED BE EF D1 FE ED BE EF

01000 42 51 01000 EF 51

01002 55 13 01002 55 13

Cont«

8/3/2019 Chp2introductiontothe68000microprocessor Copy 110627223604 Phpapp01

http://slidepdf.com/reader/full/chp2introductiontothe68000microprocessor-copy-110627223604-phpapp01 45/131

Data Transfer InstructionData Transfer Instruction

Moving Memory Data To Memory

MOVE.W $1000, $1006

Cont«

001000 42 51 001000 42 51

001002 55 13 001002 55 13

001004 01 02 001004 01 02001006 90 AB 001006 42 51

8/3/2019 Chp2introductiontothe68000microprocessor Copy 110627223604 Phpapp01

http://slidepdf.com/reader/full/chp2introductiontothe68000microprocessor-copy-110627223604-phpapp01 46/131

Data Transfer InstructionData Transfer Instruction

Moving Memory Data To Memory

MOVE.B $1000, $1006

Cont«

001000 42 51 001000 42 51

001002 55 13 001002 55 13

001004 01 02 001004 01 02001006 90 AB 001006 42 AB

8/3/2019 Chp2introductiontothe68000microprocessor Copy 110627223604 Phpapp01

http://slidepdf.com/reader/full/chp2introductiontothe68000microprocessor-copy-110627223604-phpapp01 47/131

Data Transfer InstructionData Transfer Instruction

Immediate Mode

MOVE.B #$F1, D1

Cont«

D1 FE ED BE EF D1 FE ED BE F1

MOVE.B D1, #$F1

8/3/2019 Chp2introductiontothe68000microprocessor Copy 110627223604 Phpapp01

http://slidepdf.com/reader/full/chp2introductiontothe68000microprocessor-copy-110627223604-phpapp01 48/131

Data Transfer InstructionData Transfer Instruction

MOVEQ Instruction

MOVEQ #$F1, D1

Cont«

D1 FE ED BE EF D1 FF FF FF F1

8/3/2019 Chp2introductiontothe68000microprocessor Copy 110627223604 Phpapp01

http://slidepdf.com/reader/full/chp2introductiontothe68000microprocessor-copy-110627223604-phpapp01 49/131

Data Transfer InstructionData Transfer Instruction

Fill up Memory

MOVE.B #$F1, $1000

Cont«

001000 42 51 001000 F1 51

001002 55 13 001002 55 13

001004 01 02 001004 01 02

001006 90 AB 001006 90 AB

8/3/2019 Chp2introductiontothe68000microprocessor Copy 110627223604 Phpapp01

http://slidepdf.com/reader/full/chp2introductiontothe68000microprocessor-copy-110627223604-phpapp01 50/131

Data Transfer InstructionData Transfer Instruction

EXG Instruction

EXG D1, D5

Cont«

D1 12 12 20 30 D1 00 FF 48 7C

D5 00 FF 48 7C D5 12 12 20 30

8/3/2019 Chp2introductiontothe68000microprocessor Copy 110627223604 Phpapp01

http://slidepdf.com/reader/full/chp2introductiontothe68000microprocessor-copy-110627223604-phpapp01 51/131

Data Transfer InstructionData Transfer Instruction

SWAP Instruction

SWAP D1

Cont«

D1 12 34 20 30 D1 20 30 12 34

8/3/2019 Chp2introductiontothe68000microprocessor Copy 110627223604 Phpapp01

http://slidepdf.com/reader/full/chp2introductiontothe68000microprocessor-copy-110627223604-phpapp01 52/131

Data Transfer InstructionData Transfer Instruction

LEA Instruction ± Load Effective Address

LEA $00200001, A0

Cont«

A0 00 12 70 02 A0 00 20 00 01

Similar to:MOVEA.L #00200001, A0

8/3/2019 Chp2introductiontothe68000microprocessor Copy 110627223604 Phpapp01

http://slidepdf.com/reader/full/chp2introductiontothe68000microprocessor-copy-110627223604-phpapp01 53/131

Data Transfer InstructionData Transfer Instruction

LEA Instruction ± Load Effective Address

LEA (A1), A0

Cont«

A0 00 12 70 02 A0 00 10 FF FF

A1 00 10 FF FF A1 00 10 FF FF

Similar to:

MOVEA.L A1, A0

8/3/2019 Chp2introductiontothe68000microprocessor Copy 110627223604 Phpapp01

http://slidepdf.com/reader/full/chp2introductiontothe68000microprocessor-copy-110627223604-phpapp01 54/131

Data Transfer InstructionData Transfer Instruction

LEA Instruction ± Load Effective Address

LEA 8(A0), A1

Cont«

A0 00 12 70 02 A0 00 12 70 02

A1 00 00 40 00 A1 00 12 70 0A

8/3/2019 Chp2introductiontothe68000microprocessor Copy 110627223604 Phpapp01

http://slidepdf.com/reader/full/chp2introductiontothe68000microprocessor-copy-110627223604-phpapp01 55/131

Data Transfer InstructionData Transfer Instruction

LEA Instruction ± Load Effective Address

LEA 8(A0, D4.L), A1

Cont«

D4 00 00 20 00 D4 00 00 20 00

A0 00 12 70 02 A0 00 12 70 02

A1 00 00 40 00 A1 00 12 90 0A

8/3/2019 Chp2introductiontothe68000microprocessor Copy 110627223604 Phpapp01

http://slidepdf.com/reader/full/chp2introductiontothe68000microprocessor-copy-110627223604-phpapp01 56/131

Arithmetic InstructionArithmetic Instruction

ADD Instruction

Destination + Source p Destination

ADD.W D1, D3D1 12 34 56 78 D1 12 34 56 78

D3 FD CC 01 23 D3 FD CC 57 9B

  ADD.W $1000,$2000

  ADD.W $2000,D3

8/3/2019 Chp2introductiontothe68000microprocessor Copy 110627223604 Phpapp01

http://slidepdf.com/reader/full/chp2introductiontothe68000microprocessor-copy-110627223604-phpapp01 57/131

Arithmetic InstructionArithmetic Instruction

Data Addition in MemoryProblem:

A = B + C, where A, B & C are memory

Solution:

- Copy the first word (B) from memory to register- Add the second word (C) to register

- Copy the addition product to the memory

Program:MOVE.W B,D1 ; Take B

ADD.W C,D1 ; Add with C

MOVE.W D1,A ; Store product in A

Cont«

8/3/2019 Chp2introductiontothe68000microprocessor Copy 110627223604 Phpapp01

http://slidepdf.com/reader/full/chp2introductiontothe68000microprocessor-copy-110627223604-phpapp01 58/131

Arithmetic InstructionArithmetic Instruction

Carry Production (0~255) ± Unsigned integers

Cont«

ADD.B D0, D3

 No carr y, C = 0

9-bit after addition, C = 1

8/3/2019 Chp2introductiontothe68000microprocessor Copy 110627223604 Phpapp01

http://slidepdf.com/reader/full/chp2introductiontothe68000microprocessor-copy-110627223604-phpapp01 59/131

Arithmetic InstructionArithmetic Instruction

Overflow Production (-128~+127) ±signed integers

Cont«

8/3/2019 Chp2introductiontothe68000microprocessor Copy 110627223604 Phpapp01

http://slidepdf.com/reader/full/chp2introductiontothe68000microprocessor-copy-110627223604-phpapp01 60/131

Arithmetic InstructionArithmetic Instruction

ADD.B D0, D3

V = 0, C = 0

V = 0, C = 1

Cont«

V = 1, C = 0

V = 1, C = 1

8/3/2019 Chp2introductiontothe68000microprocessor Copy 110627223604 Phpapp01

http://slidepdf.com/reader/full/chp2introductiontothe68000microprocessor-copy-110627223604-phpapp01 61/131

Arithmetic InstructionArithmetic Instruction

ADDA Instruction

Data size: W, L

ADDA.L #$70, A1

Cont«

A1 00 00 20 30 A1 00 00 20 A0

Use ADDQ.L #$1, A1 for value 1~8,it is faster than ADDA.L #$1, A1

8/3/2019 Chp2introductiontothe68000microprocessor Copy 110627223604 Phpapp01

http://slidepdf.com/reader/full/chp2introductiontothe68000microprocessor-copy-110627223604-phpapp01 62/131

Arithmetic InstructionArithmetic Instruction

SUBA Instruction

Data size: W, L

SUBA.L #$70,A1

Cont«

A1 00 00 20 30 A1 00 00 1F C0

Use SUBQ.L #$1, A1 for value 1~8,it is faster than SUBA.L #$1, A1

8/3/2019 Chp2introductiontothe68000microprocessor Copy 110627223604 Phpapp01

http://slidepdf.com/reader/full/chp2introductiontothe68000microprocessor-copy-110627223604-phpapp01 63/131

Arithmetic InstructionArithmetic Instruction

ADDQ Instruction

ADDQ.W #3,D6

Cont«

D6 12 34 56 FF D6 12 34 57 02

1~8 only

8/3/2019 Chp2introductiontothe68000microprocessor Copy 110627223604 Phpapp01

http://slidepdf.com/reader/full/chp2introductiontothe68000microprocessor-copy-110627223604-phpapp01 64/131

Arithmetic InstructionArithmetic Instruction

ADDQ vs MOVEQ

Cont«

ADDQ MOVEQ

Source 1..8 -128«+127

Destination Any Dn only

Data Size B, W, L L only

8/3/2019 Chp2introductiontothe68000microprocessor Copy 110627223604 Phpapp01

http://slidepdf.com/reader/full/chp2introductiontothe68000microprocessor-copy-110627223604-phpapp01 65/131

Arithmetic InstructionArithmetic Instruction

SUB Instruction

Destination - Source p Destination

SUB.B D3, D1

Cont«

D1 12 34 56 78 D1 12 34 56 55

D3 FD CC 01 23 D3 FD CC 01 23

SUB.W $1000, $2000

8/3/2019 Chp2introductiontothe68000microprocessor Copy 110627223604 Phpapp01

http://slidepdf.com/reader/full/chp2introductiontothe68000microprocessor-copy-110627223604-phpapp01 66/131

Arithmetic InstructionArithmetic Instruction

The Effect for V Flag after ADD/SUB

ADD S, D

Cont«

s d Answer (d) Overflow

Positive Negative AnyNothing happen

(always V=0)

 Negative Positive AnyNothing happen

(always V=0)

Positive PositivePositive

 Negative

V=0

V=1

 Negative NegativeNegative

Positive

V=0

V=1

8/3/2019 Chp2introductiontothe68000microprocessor Copy 110627223604 Phpapp01

http://slidepdf.com/reader/full/chp2introductiontothe68000microprocessor-copy-110627223604-phpapp01 67/131

Arithmetic InstructionArithmetic Instruction

The Effect for V Flag after ADD/SUB

SUB S, D

Cont«

s d Answer (d) Overflow

Positive Positive AnyNothing happen

(always V=0)

 Negative Negative AnyNothing happen

(always V=0)

 Negative PositivePositive

 Negative

V=0

V=1

Positive NegativeNegative

Positive

V=0

V=1

8/3/2019 Chp2introductiontothe68000microprocessor Copy 110627223604 Phpapp01

http://slidepdf.com/reader/full/chp2introductiontothe68000microprocessor-copy-110627223604-phpapp01 68/131

Arithmetic InstructionArithmetic Instruction

The Effect for Flag after SUB

C = Set; 2 unsigned values

V = Set; 2 signed values

Z = Set; product is 0

N = MSB

X = C

Cont«

8/3/2019 Chp2introductiontothe68000microprocessor Copy 110627223604 Phpapp01

http://slidepdf.com/reader/full/chp2introductiontothe68000microprocessor-copy-110627223604-phpapp01 69/131

Arithmetic InstructionArithmetic Instruction

The Effect for Flag after SUB

SUB.W D1,D0 ;D0 D0 ± D1

Cont«

D0 00 00 30 40 D1 00 00 00 02 D0 00 00 30 3E 0 0 0 0 0

D0 00 00 00 40 D1 00 00 00 40 D0 00 00 00 00 0 0 1 0 0

D0 00 00 FF FF D1 00 00 55 AA D0 00 00 AA 55 0 1 0 0 0

D0 00 00 00 00 D1 00 00 03 00 D0 00 00 FD 00 1 1 0 0 1

D0 00 00 90 00 D1 00 00 70 00 D0 00 00 20 00 0 0 0 1 0

D0 00 00 70 00 D1 00 00 90 00 D0 00 00 E0 00 1 1 0 1 1

D0 before SUB D1 before SUB D1 before SUB

X  N Z V C 

After instruction

8/3/2019 Chp2introductiontothe68000microprocessor Copy 110627223604 Phpapp01

http://slidepdf.com/reader/full/chp2introductiontothe68000microprocessor-copy-110627223604-phpapp01 70/131

Arithmetic InstructionArithmetic Instruction

SUBQ Instruction

SUBQ.W #7,D6

Cont«

D6 12 34 56 FF D6 12 34 56 F8

1~8 only

8/3/2019 Chp2introductiontothe68000microprocessor Copy 110627223604 Phpapp01

http://slidepdf.com/reader/full/chp2introductiontothe68000microprocessor-copy-110627223604-phpapp01 71/131

Arithmetic InstructionArithmetic Instruction

SUBQ vs MOVEQ

Cont«

SUBQ MOVEQ

Source 1..8 -128«+127

Destination Any Dn only

Data Size B, W, L L only

8/3/2019 Chp2introductiontothe68000microprocessor Copy 110627223604 Phpapp01

http://slidepdf.com/reader/full/chp2introductiontothe68000microprocessor-copy-110627223604-phpapp01 72/131

Arithmetic InstructionArithmetic Instruction

Multiplication Instruction

1. Unsigned number

MULU.W source, Dn

2. Signed number

MULS.W source, Dn

Cont«

Note: Source: 16-bit of any address mode

Both operand: 32-bit data register 

Multiply product: 32-bit stores in destination data register 

8/3/2019 Chp2introductiontothe68000microprocessor Copy 110627223604 Phpapp01

http://slidepdf.com/reader/full/chp2introductiontothe68000microprocessor-copy-110627223604-phpapp01 73/131

Arithmetic InstructionArithmetic Instruction

MULU

1. Multiply 256 with 2

MOVE.W #256, D3

MULU.W #2, D3

Cont«

D3 FD CC 01 00 D3 00 00 02 00

16-bit 32-bit

8/3/2019 Chp2introductiontothe68000microprocessor Copy 110627223604 Phpapp01

http://slidepdf.com/reader/full/chp2introductiontothe68000microprocessor-copy-110627223604-phpapp01 74/131

Arithmetic InstructionArithmetic Instruction

MULU

2. Multiply #$FFFF with #$FFFF

MULU.W #$FFFF, D3

Cont«

D3 FD CC FF FF D3 FF FE 00 01

Note:FFFF = 65535

65535 * 65535 = 4294836225 = FFFE0001

8/3/2019 Chp2introductiontothe68000microprocessor Copy 110627223604 Phpapp01

http://slidepdf.com/reader/full/chp2introductiontothe68000microprocessor-copy-110627223604-phpapp01 75/131

Arithmetic InstructionArithmetic Instruction

MULS

Multiply #$FFFF with #$FFFF

MULS.W #-1, D3

Cont«

D3 FD CC FF FF D3 00 00 00 01

Note:D3 = -1

(-1) * (-1) = 1

i h i ii h i i

8/3/2019 Chp2introductiontothe68000microprocessor Copy 110627223604 Phpapp01

http://slidepdf.com/reader/full/chp2introductiontothe68000microprocessor-copy-110627223604-phpapp01 76/131

Arithmetic InstructionArithmetic Instruction

MULS & MULU

Cont«

Content in hex As unsigned decimal As signed decimal

Location XX 0003 3 3

Location YY B000 45056 -20480

Register D0 00A0 160 160

Register D1 FF00 65280 -256

MULS XX, D0 D0=000001E0 (3 x 160 = 48010)

MULU XX, D0 D0=000001E0 (3 x 160 = 48010)MULS XX, D1 D1=FFFFFD00 (3 x (-256) = -76810)

MULU XX, D1 D1=0002FD00 (3x 65280 = 19584010)

MULS YY, D1 D1=00500000 (-20480 x (-256) = 524288010)

MULU YY, D1 D1=AF500000 (45056 x 65280 = 294125568010)

i h i ii h i i

8/3/2019 Chp2introductiontothe68000microprocessor Copy 110627223604 Phpapp01

http://slidepdf.com/reader/full/chp2introductiontothe68000microprocessor-copy-110627223604-phpapp01 77/131

Arithmetic InstructionArithmetic Instruction

Division Instruction

1. Unsigned number

DIVU.W source, Dn

2. Signed number

DIVS.W source, Dn

Cont«

Note: Source: 16-bit of any address mode

Both operand: 32-bit data register 

Division product: lower word destination register 

Remainder: upper word destination register 

A i h i I iA i h i I i

8/3/2019 Chp2introductiontothe68000microprocessor Copy 110627223604 Phpapp01

http://slidepdf.com/reader/full/chp2introductiontothe68000microprocessor-copy-110627223604-phpapp01 78/131

Arithmetic InstructionArithmetic Instruction

Division Instruction

Example 1:

DIVU.W D0, D3

Cont«

D0 FE CC 01 00 D0 FE CC 01 00

D3 00 10 00 01 D5 00 01 10 00

Remainder  Quotient

A ith ti I t tiA ith ti I t ti

8/3/2019 Chp2introductiontothe68000microprocessor Copy 110627223604 Phpapp01

http://slidepdf.com/reader/full/chp2introductiontothe68000microprocessor-copy-110627223604-phpapp01 79/131

Arithmetic InstructionArithmetic Instruction

Division Instruction

Example 2: (Overflow)

MOVE.L #$40000, D3

DIVU.W #2, D3

Result D3 = 100 0000 0000 0000 0000 (19-bit)

Destination can hold 16-bit data only

Operand remains unchanged and a divisionoverflow sets the V = 1

Cont«

A ith ti I t tiA ith ti I t ti

8/3/2019 Chp2introductiontothe68000microprocessor Copy 110627223604 Phpapp01

http://slidepdf.com/reader/full/chp2introductiontothe68000microprocessor-copy-110627223604-phpapp01 80/131

Arithmetic InstructionArithmetic Instruction

Division Instruction

Example 3: (Case divide with zero)

MOVE.L #$122, D3

CLR D0

DIV D0, D3

Cont«

A ith ti I t tiA ith ti I t ti

8/3/2019 Chp2introductiontothe68000microprocessor Copy 110627223604 Phpapp01

http://slidepdf.com/reader/full/chp2introductiontothe68000microprocessor-copy-110627223604-phpapp01 81/131

Arithmetic InstructionArithmetic Instruction

Division Instruction

Example 3: (Case divide with zero)

Cont«

Content in hex DecimalLocation XX 0012 Decimal 18

Location YY FFAE Decimal ±82

Location ZZ FF00 Unsigned decimal 65280

Register D0 00000308 Decimal 776

Register D1 FFFFFE00 Decimal -512

A ith ti I t tiA ith ti I t ti

8/3/2019 Chp2introductiontothe68000microprocessor Copy 110627223604 Phpapp01

http://slidepdf.com/reader/full/chp2introductiontothe68000microprocessor-copy-110627223604-phpapp01 82/131

Arithmetic InstructionArithmetic Instruction

Division Instruction

Example 3: (Case divide with zero)

Cont«

Instruction Result in hex Quotient Remainder

DIVU XX,D0 D0=0002002B Decimal 43 Decimal 2

DIVS XX,D1 D1=FFF8FFE4 Decimal -28 Decimal ±8

DIVS YY,D0 0026FFF7 -9 38

DIVS YY,D1 FFEC0006 6 -20DIVU ZZ,D0 03080000 0 308

DIVU ZZ,D1 FFFFFE00 65792 65024

A ith ti I t tiA ith ti I t ti

8/3/2019 Chp2introductiontothe68000microprocessor Copy 110627223604 Phpapp01

http://slidepdf.com/reader/full/chp2introductiontothe68000microprocessor-copy-110627223604-phpapp01 83/131

Arithmetic InstructionArithmetic Instruction

NEG Instruction (Negate)

Form 2¶s complement

X n 0 - X

NEG.W D5

Cont«

D5 34 67 00 F0 D5 34 67 FF 10

A ith ti I t tiA ith ti I t ti

8/3/2019 Chp2introductiontothe68000microprocessor Copy 110627223604 Phpapp01

http://slidepdf.com/reader/full/chp2introductiontothe68000microprocessor-copy-110627223604-phpapp01 84/131

Arithmetic InstructionArithmetic Instruction

EXT Instruction (Sign Extend) Convert byte @ word operand to word @ longword

by extending the sign bit of the operand

EXT.W D5

Cont«

D5 34 67 00 F0 D5 34 67 FF F0

D5 34 27 20 65 D5 34 27 00 65

A ith ti I t tiA ith ti I t ti

8/3/2019 Chp2introductiontothe68000microprocessor Copy 110627223604 Phpapp01

http://slidepdf.com/reader/full/chp2introductiontothe68000microprocessor-copy-110627223604-phpapp01 85/131

Arithmetic InstructionArithmetic Instruction

EXT Instruction (Sign Extend)

EXT.L D5

Cont«

D5 34 67 30 F0 D5 00 00 30 F0

D5 34 27 99 65 D5 FF FF 99 65

P ti l E lP ti l E l

8/3/2019 Chp2introductiontothe68000microprocessor Copy 110627223604 Phpapp01

http://slidepdf.com/reader/full/chp2introductiontothe68000microprocessor-copy-110627223604-phpapp01 86/131

Practical ExamplePractical Example

Write a sequence of program to computeX = 5 * Y + Z/W

where Y, Z and W are 16-bit signed integers and the resultis stored as longword X.Solution:

MOVE.W Y, D0MULS #5, D0MOVE.W Z, D1EXT.L D1DIVS W, D1

EXT.L D1ADD.L D1, D0

MOVE.L D0, X

Location andregister 

AsHexadecimal

Location X 0012

Location Y FF AE

Location ZFF00

Register D0 00000308

Register D1 FFFFFE00

C & T t I t tiC & T t I t ti

8/3/2019 Chp2introductiontothe68000microprocessor Copy 110627223604 Phpapp01

http://slidepdf.com/reader/full/chp2introductiontothe68000microprocessor-copy-110627223604-phpapp01 87/131

Compare & Test InstructionCompare & Test Instruction

Compare Instruction ± CMP

CMP.W D1, D0

D0-D1X N Z V C1 1 1 1 1

D0 01 20 30 40 D1 01 20 30 40 0000 1 0 1 0  0

D0 01 20 30 41 D1 01 20 30 40 0001 1 0  0  0  0

D0 01 20 30 40 D1 01 20 30 41 FFFF 1 1 0  0 1

D0 01 20 00 00 D1 01 20 FF FF 0001 1 0  0  0 1

D0 01 20 FF FF D1 01 20 00 00 FFFF 1 1 0  0  0

D0 01 20 10 00 D1 01 20 20 00 F000 1 1 0  0 1

D0 01 20 70 00 D1 01 20 90 00 E000 1 1 0 1 1

D0 01 20 90 00 D1 01 20 70 00 2000 1 0  0 1 0

Logical InstructionLogical Instruction

8/3/2019 Chp2introductiontothe68000microprocessor Copy 110627223604 Phpapp01

http://slidepdf.com/reader/full/chp2introductiontothe68000microprocessor-copy-110627223604-phpapp01 88/131

Logical InstructionLogical Instruction

A B AB AB AB A B

00

11

010

1

00

0

1

0111

0110

110

0

10

10

Logical InstructionLogical Instruction

8/3/2019 Chp2introductiontothe68000microprocessor Copy 110627223604 Phpapp01

http://slidepdf.com/reader/full/chp2introductiontothe68000microprocessor-copy-110627223604-phpapp01 89/131

Logical InstructionLogical Instruction

AND.s <sea>, <dea> Either one is Dn operand

ANDI.s #data, <dea> The 1st immediate operand

OR.s <sea>, <dea> Either one is Dn operand

ORI.s #data, <dea> The 1st immediate operandEOR.s <sea>, <dea> Either one is Dn operand

EORI.s #data, <dea> The 1st immediate operand

NOT.s <ea>

Cont«

Logical InstructionLogical Instruction

8/3/2019 Chp2introductiontothe68000microprocessor Copy 110627223604 Phpapp01

http://slidepdf.com/reader/full/chp2introductiontothe68000microprocessor-copy-110627223604-phpapp01 90/131

Logical InstructionLogical Instruction

AND Instruction To clear more than 1 bit in operand

ADNI.L #$0F, D0 If D0 = $0000B2DA

Cont«

D0 0000 0000 0000 0000 1011 0010 1101 1010

$0F 0000 0000 0000 0000 0000 0000 0000 1111

 AB 0000 0000 0000 0000 0000 0000 0000 1010

@ D0 = $0000000A

Logical InstructionLogical Instruction

8/3/2019 Chp2introductiontothe68000microprocessor Copy 110627223604 Phpapp01

http://slidepdf.com/reader/full/chp2introductiontothe68000microprocessor-copy-110627223604-phpapp01 91/131

Logical InstructionLogical Instruction

OR Instruction To set more than 1 bit in operand

ORI.W #$00E0, D0 If D0 = $A22D

Cont«

D0 1010 0010 0010 1101

$E0 0000 0000 1110 0000

 AB 1010 0010 1110 1101

@ D0 = $A2ED

Logical InstructionLogical Instruction

8/3/2019 Chp2introductiontothe68000microprocessor Copy 110627223604 Phpapp01

http://slidepdf.com/reader/full/chp2introductiontothe68000microprocessor-copy-110627223604-phpapp01 92/131

Logical InstructionLogical Instruction

EOR Instruction To invert more than 1 bit in operand

EORI.W #$00FF, D0 If D0 = $A22D

Cont«

D0 1010 0010 0010 1101

$FF 0000 0000 1111 1111

 AB 1010 0010 1101 0010

@ D0 = $A2D2

Logical InstructionLogical Instruction

8/3/2019 Chp2introductiontothe68000microprocessor Copy 110627223604 Phpapp01

http://slidepdf.com/reader/full/chp2introductiontothe68000microprocessor-copy-110627223604-phpapp01 93/131

Logical InstructionLogical Instruction

NOT Instruction To get 1¶s complement of the

operand

NOT.B D0

If D0 = $A22D

Cont«

D0.B 0000 0000 1111 1111 D0.B 1010 0010 1101 0010

@ D0 = $A2D2

Shift InstructionShift Instruction

8/3/2019 Chp2introductiontothe68000microprocessor Copy 110627223604 Phpapp01

http://slidepdf.com/reader/full/chp2introductiontothe68000microprocessor-copy-110627223604-phpapp01 94/131

Shift InstructionShift Instruction

4 instructions of shift operations: ASL (arithmetic shift left) ASR (arithmetic shift right) LSL (logical shift left) LSR (logical shift right)

Size:B, W, L

Affected flag: X & C = depend to the bit shift out N & Z = depend to the product V = 1 if sign operand changes by shifting, but 0 for rotate

Shift InstructionShift Instruction

8/3/2019 Chp2introductiontothe68000microprocessor Copy 110627223604 Phpapp01

http://slidepdf.com/reader/full/chp2introductiontothe68000microprocessor-copy-110627223604-phpapp01 95/131

Shift InstructionShift Instruction

Arithmetic Shift Instruction

Example:

ASR.B #2, D1

Cont«

D1 12 34 56 F0 D1 12 34 56 FC

(-16) (-4)

Shift InstructionShift Instruction

8/3/2019 Chp2introductiontothe68000microprocessor Copy 110627223604 Phpapp01

http://slidepdf.com/reader/full/chp2introductiontothe68000microprocessor-copy-110627223604-phpapp01 96/131

Shift InstructionShift Instruction

Logical Shift Instruction Unsigned value

Example: LSR.B #2, D1

Cont«

D1 12 34 56 F0 D1 12 34 56 3C

(240) (60)

0

Rotate InstructionRotate Instruction

8/3/2019 Chp2introductiontothe68000microprocessor Copy 110627223604 Phpapp01

http://slidepdf.com/reader/full/chp2introductiontothe68000microprocessor-copy-110627223604-phpapp01 97/131

R otate InstructionR otate Instruction

4 instructions of rotate operations: ROL (rotate left) ROR (rotate right) ROXL (rotate left through X flag) ROXR (rotate right through X flag)

Size:B, W, L

Affected flag: X & C = depend to the bit shift out N & Z = depend to the product V = 1 if sign operand changes by shifting, but 0 for rotate

Rotate InstructionRotate Instruction

8/3/2019 Chp2introductiontothe68000microprocessor Copy 110627223604 Phpapp01

http://slidepdf.com/reader/full/chp2introductiontothe68000microprocessor-copy-110627223604-phpapp01 98/131

R otate InstructionR otate Instruction

Example: ROR.B #2, D1

Cont«

D1 12 34 56 A1 D1 12 34 56 68

(10100001) (01101000)

Rotate InstructionRotate Instruction

8/3/2019 Chp2introductiontothe68000microprocessor Copy 110627223604 Phpapp01

http://slidepdf.com/reader/full/chp2introductiontothe68000microprocessor-copy-110627223604-phpapp01 99/131

R otate InstructionR otate Instruction

R otate Instruction through X

Example: ROXR.B #2, D1

Cont«

D1 12 34 56 A1 D1 12 34 56 A8

(10100001) (10101000)

ExampleExample

8/3/2019 Chp2introductiontothe68000microprocessor Copy 110627223604 Phpapp01

http://slidepdf.com/reader/full/chp2introductiontothe68000microprocessor-copy-110627223604-phpapp01 100/131

ExampleExample

Running light in address $80000

MOVE.B #1,D0

REPEAT MOVE.B D0,$800000

JSR DELAY ;Delay

ROL.B #1,D0

BRA REPEAT

Bit Manipulation InstructionBit Manipulation Instruction

8/3/2019 Chp2introductiontothe68000microprocessor Copy 110627223604 Phpapp01

http://slidepdf.com/reader/full/chp2introductiontothe68000microprocessor-copy-110627223604-phpapp01 101/131

Bit Manipulation InstructionBit Manipulation Instruction

Test the specified bit in the destination

Data size = B or only 1.

The bit manipulation instruction included:

a. BCHG (bit test and change) instructionb. BCLR (bit test and clear) instruction

c. BSET (bit test and set) instruction

d. BTST (bit test) instruction

Bit Manipulation InstructionBit Manipulation Instruction

8/3/2019 Chp2introductiontothe68000microprocessor Copy 110627223604 Phpapp01

http://slidepdf.com/reader/full/chp2introductiontothe68000microprocessor-copy-110627223604-phpapp01 102/131

Bit Manipulation InstructionBit Manipulation Instruction

Example 1:In address $FF8000 contains $AA. What isthe result after BTST.B #3, $FF8000?

Solution: ($FF8000) = 101010102 where the 3rd bit

is 1.

Therefore Z = 0

Cont«

Bit Manipulation InstructionBit Manipulation Instruction

8/3/2019 Chp2introductiontothe68000microprocessor Copy 110627223604 Phpapp01

http://slidepdf.com/reader/full/chp2introductiontothe68000microprocessor-copy-110627223604-phpapp01 103/131

Bit Manipulation InstructionBit Manipulation Instruction

Example 2:Data register D5 contains 2C3459A7.What is the state of the Z flag and whatare the contents of D5 after BCHG #6, D5?

Solution: lower byte of D5 = 101001112. Bit 6, 1<0>100111, is a 0. This will set the Z flag & complement bit 6. This result in D5 = 2C3459E716.

Cont«

Bit Manipulation InstructionBit Manipulation Instruction

8/3/2019 Chp2introductiontothe68000microprocessor Copy 110627223604 Phpapp01

http://slidepdf.com/reader/full/chp2introductiontothe68000microprocessor-copy-110627223604-phpapp01 104/131

Bit Manipulation InstructionBit Manipulation Instruction

Example 3:Data registers D6 and D7 contain 0000000C and75793290, respectively. What is the result of BCLR D6, D7?

Solution: Register D6 specifies that the 12th bit position

001<1>001010010000) should be tested andcleared.

Since the 12th bit is a 1, Z = 0 bit 12 of D7 will be cleared D7 = 75792290.

Cont«

Bit Manipulation InstructionBit Manipulation Instruction

8/3/2019 Chp2introductiontothe68000microprocessor Copy 110627223604 Phpapp01

http://slidepdf.com/reader/full/chp2introductiontothe68000microprocessor-copy-110627223604-phpapp01 105/131

Bit Manipulation InstructionBit Manipulation Instruction

Example 4:

What is the result of BSET #2,(A3)?

Solution:The bit in position 2 of the memory locationpointed to by A3 is tested and then set.

Cont«

Subroutine ControlSubroutine Control

8/3/2019 Chp2introductiontothe68000microprocessor Copy 110627223604 Phpapp01

http://slidepdf.com/reader/full/chp2introductiontothe68000microprocessor-copy-110627223604-phpapp01 106/131

InstructionInstruction

Flow Chart Symbol

Subroutine ControlSubroutine Control

8/3/2019 Chp2introductiontothe68000microprocessor Copy 110627223604 Phpapp01

http://slidepdf.com/reader/full/chp2introductiontothe68000microprocessor-copy-110627223604-phpapp01 107/131

InstructionInstruction

Program Control Structure

Cont«

Subroutine ControlSubroutine Control

8/3/2019 Chp2introductiontothe68000microprocessor Copy 110627223604 Phpapp01

http://slidepdf.com/reader/full/chp2introductiontothe68000microprocessor-copy-110627223604-phpapp01 108/131

InstructionInstruction

Jump Instruction ± JMP

Unconditional transfer to target destination

PC n effective address

JMP <ea> Type of effective address:

a. Absolute short

b. Absolute long

c. Address register indirect

Cont«

Subroutine ControlSubroutine Control

8/3/2019 Chp2introductiontothe68000microprocessor Copy 110627223604 Phpapp01

http://slidepdf.com/reader/full/chp2introductiontothe68000microprocessor-copy-110627223604-phpapp01 109/131

InstructionInstruction

Jump Instruction ± JMP

JMP START ; START = $1000

JMP $FF8000

Cont«

0100 1110 1111 10000001 0000 0000 0000

0100 1110 1111 1001

0000 0000 1111 11111000 0000 0000 0000

Subroutine ControlSubroutine Controlii

8/3/2019 Chp2introductiontothe68000microprocessor Copy 110627223604 Phpapp01

http://slidepdf.com/reader/full/chp2introductiontothe68000microprocessor-copy-110627223604-phpapp01 110/131

InstructionInstruction

Bcc (branch condition) InstructionBcc<ea>

Cont«

Instruction Meaning Arithmetic If the test is true

BEQ EQual to zero U Z=1

B NE Not Equal to zero U Z=0

BMI Minus U N=1BPL Plus U N=0

BCS/LO Carr y Set/LOwer U C=1

BCC/HS Carr y Clear/Higher or Same U C=0

BVS oVerflow Set S V=1

BVC oVerflow Clear S V=0

BGT GreaTer than S Z+( NV)=0

BLT Less Than S NV=1

BGE Greater than or Equal S NV=0

BLE Less than or Equal S Z+( NV)=0

BHI Higher U C+Z=0

BLS Lower than or Same U C+Z=1

Subroutine ControlSubroutine Controlii

8/3/2019 Chp2introductiontothe68000microprocessor Copy 110627223604 Phpapp01

http://slidepdf.com/reader/full/chp2introductiontothe68000microprocessor-copy-110627223604-phpapp01 111/131

InstructionInstruction

Branch Always Instruction - BR APC n PC + offsetBRA.s <ea>

Short branch: -128 e PC e +127 Syntax: BRA.S

Long branch:

-32k e PC e 32k Syntax: BRA.L

Cont«

Subroutine ControlSubroutine ControlI iI i

8/3/2019 Chp2introductiontothe68000microprocessor Copy 110627223604 Phpapp01

http://slidepdf.com/reader/full/chp2introductiontothe68000microprocessor-copy-110627223604-phpapp01 112/131

InstructionInstruction

Control Constructions1. IF condition

THEN action 1;

2. IF condition

THEN action 1

ELSE action 2;

3. FOR counter = initial TO final value

DO action 1;

4. R EPEA

Taction1

UNTIL condition;

Cont«

5. WHILE condition

DO action 1;

6. CASE selector OF

action 1,action 2 ,

.

.action N ;

Subroutine ControlSubroutine ControlI t tiI t ti

8/3/2019 Chp2introductiontothe68000microprocessor Copy 110627223604 Phpapp01

http://slidepdf.com/reader/full/chp2introductiontothe68000microprocessor-copy-110627223604-phpapp01 113/131

InstructionInstruction

Example for IF - THENIF A=10 THEN Action 1

CMPI.W #10, VARA

BNE NEXT.

.

.

NEXT

Cont«

Action 1 F

T

Subroutine ControlSubroutine ControlI t tiI t ti

8/3/2019 Chp2introductiontothe68000microprocessor Copy 110627223604 Phpapp01

http://slidepdf.com/reader/full/chp2introductiontothe68000microprocessor-copy-110627223604-phpapp01 114/131

InstructionInstruction

Example for IF ± THEN ± ELSEIF A<=0 THEN Action 1; ELSE Action 2

TST.W VARA

BLE NEXT1.

.

BRA NEXTNEXT1

.

.

NEXT

Cont«

Action 1

Action 2

Subroutine ControlSubroutine ControlI t tiI t ti

8/3/2019 Chp2introductiontothe68000microprocessor Copy 110627223604 Phpapp01

http://slidepdf.com/reader/full/chp2introductiontothe68000microprocessor-copy-110627223604-phpapp01 115/131

InstructionInstruction

Example for FOR LOOP

FOR I=1 TO 10 DO Action 1

MOVE.W #9, D7

LOOP.

.

.

DBF D7, LOOP

Cont«

Action 1

Subroutine ControlSubroutine ControlI t tiI t ti

8/3/2019 Chp2introductiontothe68000microprocessor Copy 110627223604 Phpapp01

http://slidepdf.com/reader/full/chp2introductiontothe68000microprocessor-copy-110627223604-phpapp01 116/131

InstructionInstruction

Example for R EPEAT ± UNTILREPEAT Action 1 UNTIL A=0 or maximum count isreached

MOVE.W LIMIT,D7SUBQ.W #1, D7LOOP

.

.

.TST.W VARADBNE D7, LOOP

Cont«

Action 1

Subroutine ControlSubroutine ControlI t tiI t ti

8/3/2019 Chp2introductiontothe68000microprocessor Copy 110627223604 Phpapp01

http://slidepdf.com/reader/full/chp2introductiontothe68000microprocessor-copy-110627223604-phpapp01 117/131

InstructionInstruction

Example for WHILE ± DOWHILE A<=10 and maximum countis not reached DO Action 1

MOVE.W LIMIT, D7AGAIN CMPI.W #10, VARA

DBGT D7, LOOPLOOP

.

.

.BRA AGAIN

NEXT...

Cont«

Action 1

Action 2

BCD (Binary Coded Decimal)BCD (Binary Coded Decimal)I t tiI t ti

8/3/2019 Chp2introductiontothe68000microprocessor Copy 110627223604 Phpapp01

http://slidepdf.com/reader/full/chp2introductiontothe68000microprocessor-copy-110627223604-phpapp01 118/131

InstructionInstruction

Each BCD byte contents 2 digit of 4-bit BCD. Each BCD instruction involve in X bit.

Z bit is changed if the product is not zero.

Before doing the first BCD operation, it have to

start with X=0 and Z=1. Syntax:

ABCD Dx,Dy (source)10 + (destination)10 + X p destination

ABCD- (Ay)-(Ax)

NBCD <ea> 0 ± (source)10 ± X p destination

SBCD Dx,Dy (destination)10 - (source)10 - X p destination

BCD (Binary Coded Decimal)BCD (Binary Coded Decimal)I t tiI t ti

8/3/2019 Chp2introductiontothe68000microprocessor Copy 110627223604 Phpapp01

http://slidepdf.com/reader/full/chp2introductiontothe68000microprocessor-copy-110627223604-phpapp01 119/131

InstructionInstruction

ABCD and SBCD InstructionsExample 1:

Add BCD number in D0 to D1.

MOVE #4, CCR ; x=0 and z=1

ABCD D0, D1

Example 2:Subtract BCD number in D0 from D1

MOVE #4, CCR ; x=0 and z=1

SBCD D0, D1

Cont«

BCD (Binary Coded Decimal)BCD (Binary Coded Decimal)I t tiI t ti

8/3/2019 Chp2introductiontothe68000microprocessor Copy 110627223604 Phpapp01

http://slidepdf.com/reader/full/chp2introductiontothe68000microprocessor-copy-110627223604-phpapp01 120/131

InstructionInstruction

BCD InstructionAddition for 2 BCD number 8 bit (byte).

MOVE #4,CCR ;x=0 and z=1

ABCD -(A0),-(A1)

ABCD -(A0),-(A1)ABCD -(A0),-(A1)

ABCD -(A0),-(A1)

Cont«

A1 after addition p Upper Byte Upper  Middle

Lower Middle Lower  Byte

A1 before addition p

A0 after addition p Upper Byte Upper  Middle

Lower Middle Lower  Byte

A0 before addition p

Destination

Source

BCD (Binary Coded Decimal)BCD (Binary Coded Decimal)Inst ctionInst ction

8/3/2019 Chp2introductiontothe68000microprocessor Copy 110627223604 Phpapp01

http://slidepdf.com/reader/full/chp2introductiontothe68000microprocessor-copy-110627223604-phpapp01 121/131

InstructionInstruction

NBCD Instruction Use 9¶s @ 10¶s complement notation to represent

a negative BCD number

Example 1:What is the 10s complement for fill-in D0. Let sayD0 = 23.

MOVE #0,CCR

NBCD D0NBCD operation: 100 (0 borrow 1)

Original D0: -23

X bit: - 0

Product: 77

Cont«

BCD (Binary Coded Decimal)BCD (Binary Coded Decimal)InstructionInstruction

8/3/2019 Chp2introductiontothe68000microprocessor Copy 110627223604 Phpapp01

http://slidepdf.com/reader/full/chp2introductiontothe68000microprocessor-copy-110627223604-phpapp01 122/131

InstructionInstruction

NBCD Instruction

Example 2:

What is the 9s complement for fill-in D0. Let say D0

= 23.MOVE #$10,CCR

NBCD D0

NBCD operation : 100 (0 borrow 1)

Original D0 : -23X bit: - 1

Product : 76

Cont«

Stack and SubroutineStack and Subroutine

8/3/2019 Chp2introductiontothe68000microprocessor Copy 110627223604 Phpapp01

http://slidepdf.com/reader/full/chp2introductiontothe68000microprocessor-copy-110627223604-phpapp01 123/131

Stack Data structure that is used to save and restore

information in a last-in, first-out (LIFO) fashion.

Register A7 is implicitly used as the stack pointer.

Push (save):MOVE source, -(SP) orMOVE.L source, -(SP)

Pop (retrieve):

MOVE (SP)+, destination orMOVE.L (SP)+, destination

Stack and SubroutineStack and Subroutine

8/3/2019 Chp2introductiontothe68000microprocessor Copy 110627223604 Phpapp01

http://slidepdf.com/reader/full/chp2introductiontothe68000microprocessor-copy-110627223604-phpapp01 124/131

Stack

Cont«

Stack and SubroutineStack and Subroutine

8/3/2019 Chp2introductiontothe68000microprocessor Copy 110627223604 Phpapp01

http://slidepdf.com/reader/full/chp2introductiontothe68000microprocessor-copy-110627223604-phpapp01 125/131

StackSTACKA DS.W 50

MOVEA.L #STACKA + 100, A2

MOVE.L D1, -(A2)MOVE.W VAR, -(A2)

MOVE.W #$25, -(A2)

MOVE.L (A2)+, D2

MOVE.L (A2)+, D3

Cont«

Stack and SubroutineStack and Subroutine

8/3/2019 Chp2introductiontothe68000microprocessor Copy 110627223604 Phpapp01

http://slidepdf.com/reader/full/chp2introductiontothe68000microprocessor-copy-110627223604-phpapp01 126/131

Stack

Cont«

SubroutineSubroutine

8/3/2019 Chp2introductiontothe68000microprocessor Copy 110627223604 Phpapp01

http://slidepdf.com/reader/full/chp2introductiontothe68000microprocessor-copy-110627223604-phpapp01 127/131

SubroutineSubroutine

8/3/2019 Chp2introductiontothe68000microprocessor Copy 110627223604 Phpapp01

http://slidepdf.com/reader/full/chp2introductiontothe68000microprocessor-copy-110627223604-phpapp01 128/131

Cont«

Subroutine Concept A program structure where one part of the program is called

the main program. In addition to this, a smaller segment attached to the main

program, known as a subroutine. The subroutine is written to provide a function that must be

performed at various points in the main program. A return instruction must be included at the end of the

subroutine to initiate the return sequence to the mainprogram environment.

The instructions provided to transfer control from the mainprogram to a subroutine and return control back to the main

program are called subroutine-handling instructions.

SubroutineSubroutine

8/3/2019 Chp2introductiontothe68000microprocessor Copy 110627223604 Phpapp01

http://slidepdf.com/reader/full/chp2introductiontothe68000microprocessor-copy-110627223604-phpapp01 129/131

Cont«

Subroutine Control Instructions ±JSR, BSR, R TS & R TR 

InterruptInterrupt

8/3/2019 Chp2introductiontothe68000microprocessor Copy 110627223604 Phpapp01

http://slidepdf.com/reader/full/chp2introductiontothe68000microprocessor-copy-110627223604-phpapp01 130/131

pp

An external event which informs the CPUthat a device needs its service.

Interrupt Service Routine (ISR):a. a program which associates with interrupt.

b. also called the interrupt handlerc. there are 4 bytes of memory allocated as

interrupt vector table.

d. handled in the supervisor mode, S = 1.

InterruptInterrupt

8/3/2019 Chp2introductiontothe68000microprocessor Copy 110627223604 Phpapp01

http://slidepdf.com/reader/full/chp2introductiontothe68000microprocessor-copy-110627223604-phpapp01 131/131

pp

Example 1:Calculate the sum of 10 numbers in theaddress memory

$2000.

Cont«

extra