hcs12 arithmetic

64
HCS12 Arithmetic Lecture 3.3

Upload: gaetan

Post on 01-Feb-2016

66 views

Category:

Documents


2 download

DESCRIPTION

HCS12 Arithmetic. Lecture 3.3. 68HC12 Arithmetic. Addition and Subtraction Shift and Rotate Instructions Multiplication Division. Addition and Subtraction. HCS12 code for 1+, 2+. ;1+ ( n -- n+1 ) ONEP LDD0,X ADDD#1 STD0,X RTS ;2+ ( n -- n+2 ) TWOP LDD0,X ADDD#2 - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: HCS12 Arithmetic

HCS12 Arithmetic

Lecture 3.3

Page 2: HCS12 Arithmetic

68HC12 Arithmetic

• Addition and Subtraction• Shift and Rotate Instructions

• Multiplication

• Division

Page 3: HCS12 Arithmetic

Addition and SubtractionTable 3.1 Addition and Subtraction InstructionsAddition Instructions:

Mnemonic FunctionABA Add B to AADDA Add memory to AADDB Add memory to BADCA Add memory with carry to AADCB Add memory with carry to BADDD Add memory to DABX Add B to XABY Add B to Y

Subtraction Instructions:

Mnemonic FunctionSBA Subtract B from ASUBA Subtract memory from ASUBB Subtract memory from BSBCA Subtract memory with borrow from ASBCB Subtract memory with borrow from BSUBD Subtract memory from D

Page 4: HCS12 Arithmetic

Table 3.2 Increment and Decrement InstructionsIncrement Instructions:

Mnemonic FunctionINC Increment memory by 1INCA Increment A by 1INCB Increment B by 1INS Increment SP by 1INX Increment X by 1INY Increment Y by 1

Decrement Instructions:

Mnemonic FunctionDEC Decrement memory by 1DECA Decrement A by 1DECB Decrement B by 1DES Decrement SP by 1DEX Decrement X by 1DEY Decrement Y by 1

Page 5: HCS12 Arithmetic

HCS12 code for 1+, 2+ ; 1+ ( n -- n+1 )ONEP

LDD 0,XADDD #1STD 0,XRTS

; 2+ ( n -- n+2 )TWOP

LDD 0,XADDD #2STD 0,XRTS

Page 6: HCS12 Arithmetic

HCS12 code for 1-, 2- ; 1- ( n -- n-1 )ONEP

LDD 0,XSUBD #1STD 0,XRTS

; 2- ( n -- n-2 )TWOP

LDD 0,XSUBD #2STD 0,XRTS

Page 7: HCS12 Arithmetic

Double Numbers

HI-word <---- top of stackLO-word

D+ ( d1 d2 -- d3 ) ( d3 = d1+d2 ) Add two double numbers leaving a double sum.

D- ( d1 d2 -- d3 ) ( d3 = d1-d2 ) Subtract two double numbers leaving a double difference.

Page 8: HCS12 Arithmetic

d1

d2

d3

X X+1 X+2 X+3

X+4 X+5 X+6 X+7

; D+ ( d1 d2 -- d3 )DPLUS

LDAA 7,XADDA 3,XSTAA 7,XLDAA 6,XADCA 2,XSTAA 6,XLDAA 5,XADCA 1,XSTAA 5,XLDAA 4,XADCA 0,XSTAA 4,XLEAX 4,XRTS

Adding Double Numbers

Page 9: HCS12 Arithmetic

d1

d2

d3

X X+1 X+2 X+3

X+4 X+5 X+6 X+7

Subtracting Double Numbers

; D- ( d1 d2 -- d3 )DMINUS

LDAA 7,XSUBA 3,XSTAA 7,XLDAA 6,XSBCA 2,XSTAA 6,XLDAA 5,XSBCA 1,XSTAA 5,XLDAA 4,XSBCA 0,XSTAA 4,XLEAX 4,XRTS

Page 10: HCS12 Arithmetic

68HC12 Arithmetic

• Addition and Subtraction• Shift and Rotate Instructions

• Multiplication

• Division

Page 11: HCS12 Arithmetic

Table 3.6 Shift and Rotate InstructionsLogical Shift Instructions:

Mnemonic FunctionLSL Logic Shift Left MemoryLSLA Logic Shift Left ALSLB Logic Shift Left BLSLD Logic Shift Left DLSR Logic Shift Right MemoryLSRA Logic Shift Right ALSRB Logic Shift Right BLSRD Logic Shift Right D

Arithmetic Shift Instructions:

Mnemonic FunctionASL Arithmetic Shift Left MemoryASLA Arithmetic Shift Left AASLB Arithmetic Shift Left BASLD Arithmetic Shift Left DASR Arithmetic Shift Right MemoryASRA Arithmetic Shift Right AASRB Arithmetic Shift Right B

Rotate Instructions:

Mnemonic FunctionROL Rotate Left Memory Through CarryROLA Rotate Left A Through CarryROLB Rotate Left B Through CarryROR Rotate Right Memory Through CarryRORA Rotate Right A Through CarryRORB Rotate Right B Through Carry

Page 12: HCS12 Arithmetic

Logic Shift LeftLSL, LSLA, LSLB

01 0 1 0 0 1 0 11C 7 6 5 4 3 2 1 0Bit

1 0 1 0 0 1 0 11 0C 7 6 5 4 3 2 1 0Bit

1 0 1 0 0 1 0 1

7 6 5 4 3 2 1 0

A B

LSLD

Page 13: HCS12 Arithmetic

Logic Shift RightLSR, LSRA, LSRB

1 0 1 0 0 1 0 1 10

C7 6 5 4 3 2 1 0Bit

1 0 1 0 0 1 0 1 10

C7 6 5 4 3 2 1 0Bit

1 0 1 0 0 1 0 1

7 6 5 4 3 2 1 0

A B

LSRD

Page 14: HCS12 Arithmetic

Arithmetic Shift RightASR, ASRA, ASRB

1 0 1 0 0 1 0 1 1

C

Page 15: HCS12 Arithmetic

Rotate LeftROL, ROLA, ROLB

1 0 1 0 0 1 0 11C 7 6 5 4 3 2 1 0Bit

Page 16: HCS12 Arithmetic

Rotate RightROR, RORA, RORB

1 0 1 0 0 1 0 1 1C7 6 5 4 3 2 1 0Bit

Page 17: HCS12 Arithmetic

2*, 2/, and U2/; 2* ( n -- 2*n )TWOT

ASL 1,X ;arith shift leftROL 0,XRTS

; 2/ ( n -- n/2 )TWOS

ASR 0,X ;arith shift rightROR 1,XRTS

; U2/ ( u -- u/2 )U2S

LSR 0,XROR 1,X ;logic shift rightRTS

Page 18: HCS12 Arithmetic

68HC12 Arithmetic

• Addition and Subtraction• Shift and Rotate Instructions

• Multiplication

• Division

Page 19: HCS12 Arithmetic

Binary Multiplication

Table 10.8Binary Multiplication Table

0 10 0 01 0 1

Page 20: HCS12 Arithmetic

Binary Multiplication

13x 12 26 13 156

1101 1100 0000 0000 1101 110110011100

9 C = 156

Page 21: HCS12 Arithmetic

Table 10.9Hexadecimal Multiplication Table

0 1 2 3 4 5 6 7 8 9 A B C D E F0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 01 1 2 3 4 5 6 7 8 9 A B C D E F2 4 6 8 A C E 10 12 14 16 18 1A 1C 1E3 9 C F 12 15 18 1B 1E 21 24 27 2A 2D4 10 14 18 1C 20 24 28 2C 30 34 38 3C5 19 1E 23 28 2D 32 37 3C 41 46 4B6 24 2A 30 36 3C 42 48 4E 54 5A7 31 38 3F 46 4D 54 5B 62 698 40 48 50 58 60 68 70 789 51 5A 63 6C 75 7E 87A 64 6E 78 82 8C 96B 79 84 8F 9A A5C 90 9C A8 B4D A9 B6 C3E C4 D2F E1

Hex Multiplication

Page 22: HCS12 Arithmetic

Hex MultiplicationTable 10.9

Hexadecimal Multiplication Table0 1 2 3 4 5 6 7 8 9 A B C D E F

0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 01 1 2 3 4 5 6 7 8 9 A B C D E F2 4 6 8 A C E 10 12 14 16 18 1A 1C 1E3 9 C F 12 15 18 1B 1E 21 24 27 2A 2D4 10 14 18 1C 20 24 28 2C 30 34 38 3C5 19 1E 23 28 2D 32 37 3C 41 46 4B6 24 2A 30 36 3C 42 48 4E 54 5A7 31 38 3F 46 4D 54 5B 62 698 40 48 50 58 60 68 70 789 51 5A 63 6C 75 7E 87A 64 6E 78 82 8C 96B 79 84 8F 9A A5C 90 9C A8 B4D A9 B6 C3E C4 D2F E1

61x 905490

3D x 5A 262 A x D = 82, A x 3 = 1E + 8 = 26 131 5 x D = 41, 5 x 3 = F + 4 = 13 157216 = 549010

Dec Hex

Page 23: HCS12 Arithmetic

Hex Multiplication

product = $1572 is in D = A:B

; multiply 8 x 8 = 16

=00004000 ORG $4000

4000 86 3D LDAA #$3D

4002 C6 5A LDAB #$5A

4004 12 MUL

Page 24: HCS12 Arithmetic

product = $1572 is in D = A:B

Page 25: HCS12 Arithmetic

MultiplicationTable 3.3 Multiply Instructions

Mnemonic Function OperationEMUL 16x16 multiply (unsigned) (D) x (Y) => Y:DEMULS 16x16 multiply (signed) (D) x (Y) => Y:DMUL 8x8 multiply (unsigned) (A) x (B) => A:B

Page 26: HCS12 Arithmetic

16-Bit Hex MultiplicationTable 10.9

Hexadecimal Multiplication Table0 1 2 3 4 5 6 7 8 9 A B C D E F

0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 01 1 2 3 4 5 6 7 8 9 A B C D E F2 4 6 8 A C E 10 12 14 16 18 1A 1C 1E3 9 C F 12 15 18 1B 1E 21 24 27 2A 2D4 10 14 18 1C 20 24 28 2C 30 34 38 3C5 19 1E 23 28 2D 32 37 3C 41 46 4B6 24 2A 30 36 3C 42 48 4E 54 5A7 31 38 3F 46 4D 54 5B 62 698 40 48 50 58 60 68 70 789 51 5A 63 6C 75 7E 87A 64 6E 78 82 8C 96B 79 84 8F 9A A5C 90 9C A8 B4D A9 B6 C3E C4 D2F E1

31A4 x1B2C 253B0

4 x C = 30A x C = 78 + 3 = 7B1 x C = C + 7 = 133 x C = 24 + 1 = 25

Page 27: HCS12 Arithmetic

16-Bit Hex MultiplicationTable 10.9

Hexadecimal Multiplication Table0 1 2 3 4 5 6 7 8 9 A B C D E F

0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 01 1 2 3 4 5 6 7 8 9 A B C D E F2 4 6 8 A C E 10 12 14 16 18 1A 1C 1E3 9 C F 12 15 18 1B 1E 21 24 27 2A 2D4 10 14 18 1C 20 24 28 2C 30 34 38 3C5 19 1E 23 28 2D 32 37 3C 41 46 4B6 24 2A 30 36 3C 42 48 4E 54 5A7 31 38 3F 46 4D 54 5B 62 698 40 48 50 58 60 68 70 789 51 5A 63 6C 75 7E 87A 64 6E 78 82 8C 96B 79 84 8F 9A A5C 90 9C A8 B4D A9 B6 C3E C4 D2F E1

31A4 x1B2C 253B0 6348

2 x 4 = 82 x A = 141 x 2 = 2 + 1 = 32 x 3 = 6

Page 28: HCS12 Arithmetic

16-Bit Hex MultiplicationTable 10.9

Hexadecimal Multiplication Table0 1 2 3 4 5 6 7 8 9 A B C D E F

0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 01 1 2 3 4 5 6 7 8 9 A B C D E F2 4 6 8 A C E 10 12 14 16 18 1A 1C 1E3 9 C F 12 15 18 1B 1E 21 24 27 2A 2D4 10 14 18 1C 20 24 28 2C 30 34 38 3C5 19 1E 23 28 2D 32 37 3C 41 46 4B6 24 2A 30 36 3C 42 48 4E 54 5A7 31 38 3F 46 4D 54 5B 62 698 40 48 50 58 60 68 70 789 51 5A 63 6C 75 7E 87A 64 6E 78 82 8C 96B 79 84 8F 9A A5C 90 9C A8 B4D A9 B6 C3E C4 D2F E1

31A4 x1B2C 253B0 6348 2220C

4 x B = 2CA x B = 6E + 2 = 701 x B = B + 7 = 123 x B = 21 + 1 = 22

Page 29: HCS12 Arithmetic

16-Bit Hex MultiplicationTable 10.9

Hexadecimal Multiplication Table0 1 2 3 4 5 6 7 8 9 A B C D E F

0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 01 1 2 3 4 5 6 7 8 9 A B C D E F2 4 6 8 A C E 10 12 14 16 18 1A 1C 1E3 9 C F 12 15 18 1B 1E 21 24 27 2A 2D4 10 14 18 1C 20 24 28 2C 30 34 38 3C5 19 1E 23 28 2D 32 37 3C 41 46 4B6 24 2A 30 36 3C 42 48 4E 54 5A7 31 38 3F 46 4D 54 5B 62 698 40 48 50 58 60 68 70 789 51 5A 63 6C 75 7E 87A 64 6E 78 82 8C 96B 79 84 8F 9A A5C 90 9C A8 B4D A9 B6 C3E C4 D2F E1

31A4 x1B2C 253B0 6348 2220C 31A4

0544D430ORG $4000

4000 CC 31A4 LDD #$31A4 ;D = $31A4

4003 CD 1B2C LDY #$1B2C ;Y = $1B2C

4006 13 EMUL ;Y:D = D x Y

Page 30: HCS12 Arithmetic

Y:D = 0544D430

Page 31: HCS12 Arithmetic

Multiply InstructionsTable 3.3 Multiply Instructions

Mnemonic Function OperationEMUL 16x16 multiply (unsigned) (D) x (Y) => Y:DEMULS 16x16 multiply (signed) (D) x (Y) => Y:DMUL 8x8 multiply (unsigned) (A) x (B) => A:B

Note that EMUL and MUL are unsigned multiplies

EMULS is used to multiply signed numbers

Page 32: HCS12 Arithmetic

Unsigned MultiplicationDec Hex

65528x 8524224

FFF8x 0008 7FFC0 52422410 = 7FFC016

Page 33: HCS12 Arithmetic

FFF8x 0008 7FFC0

Page 34: HCS12 Arithmetic

Unsigned MultiplicationDec Hex

65528x 8524224

FFF8x 0008 7FFC0 52422410 = 7FFC016

But FFF8 = 1111111111111000 can be a signed number 2’s comp = 0000000000001000 = $0008 = 810

Therefore, FFF8 can represent -8

Page 35: HCS12 Arithmetic

Signed MultiplicationDec

-8 x 8 -64

6410 = 0000004016

= 0000 0000 0000 0000 0000 0000 0100 00002’s comp = 1111 1111 1111 1111 1111 1111 0100 0000 = $FFFFFF40

Therefore, for signed multiplication$FFF8 x $0008 = $FFFFFF40and not $7FFC0

The EMULS instruction performs SIGNED multiplication

Page 36: HCS12 Arithmetic

Signed Multiplication

product = $FFFFFFC0 is in Y:D

; EMULS signed 16 x 16 = 32

=00004000 ORG $4000

4000 CC FFF8 LDD #$FFF8 ;D = $FFF8

4003 CD 0008 LDY #$0008 ;Y = $0008

4006 1813 EMULS ;Y:D = D x Y

Page 37: HCS12 Arithmetic

product = $FFFFFFC0 is in Y:D

Page 38: HCS12 Arithmetic

MultiplicationTable 3.3 Multiply Instructions

Mnemonic Function OperationEMUL 16x16 multiply (unsigned) (D) x (Y) => Y:DEMULS 16x16 multiply (signed) (D) x (Y) => Y:DMUL 8x8 multiply (unsigned) (A) x (B) => A:B

Note that EMUL is a 16 x 16 multiply that producesa 32-bit unsigned product.If the product fits into 16-bits, then it produces thecorrect SIGNED product.

Page 39: HCS12 Arithmetic

FFF8x 0008 7FFC0

-8x 8 -64 = $FFC0

Correct 16-bitSIGNED result

Page 40: HCS12 Arithmetic

MultiplicationTable 3.3 Multiply Instructions

Mnemonic Function OperationEMUL 16x16 multiply (unsigned) (D) x (Y) => Y:DEMULS 16x16 multiply (signed) (D) x (Y) => Y:DMUL 8x8 multiply (unsigned) (A) x (B) => A:B

Even MUL can be used for an8 x 8 = 8 SIGNED multiply

Page 41: HCS12 Arithmetic

Note: A x B = A:BB contains the correct 8-bit SIGNED value

Page 42: HCS12 Arithmetic

68HC12 Arithmetic

• Addition and Subtraction• Shift and Rotate Instructions

• Multiplication

• Division

Page 43: HCS12 Arithmetic

Binary Division

1001110011001

110001111

1

110000110

0

000001100

1

11000000

DC 9C

Page 44: HCS12 Arithmetic

Hex DivisionTable 10.9

Hexadecimal Multiplication Table0 1 2 3 4 5 6 7 8 9 A B C D E F

0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 01 1 2 3 4 5 6 7 8 9 A B C D E F2 4 6 8 A C E 10 12 14 16 18 1A 1C 1E3 9 C F 12 15 18 1B 1E 21 24 27 2A 2D4 10 14 18 1C 20 24 28 2C 30 34 38 3C5 19 1E 23 28 2D 32 37 3C 41 46 4B6 24 2A 30 36 3C 42 48 4E 54 5A7 31 38 3F 46 4D 54 5B 62 698 40 48 50 58 60 68 70 789 51 5A 63 6C 75 7E 87A 64 6E 78 82 8C 96B 79 84 8F 9A A5C 90 9C A8 B4D A9 B6 C3E C4 D2F E1

EE BC2FC

C x E = A8C x E = A8 + A = B2

B28 9AF

A

Page 45: HCS12 Arithmetic

Hex DivisionTable 10.9

Hexadecimal Multiplication Table0 1 2 3 4 5 6 7 8 9 A B C D E F

0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 01 1 2 3 4 5 6 7 8 9 A B C D E F2 4 6 8 A C E 10 12 14 16 18 1A 1C 1E3 9 C F 12 15 18 1B 1E 21 24 27 2A 2D4 10 14 18 1C 20 24 28 2C 30 34 38 3C5 19 1E 23 28 2D 32 37 3C 41 46 4B6 24 2A 30 36 3C 42 48 4E 54 5A7 31 38 3F 46 4D 54 5B 62 698 40 48 50 58 60 68 70 789 51 5A 63 6C 75 7E 87A 64 6E 78 82 8C 96B 79 84 8F 9A A5C 90 9C A8 B4D A9 B6 C3E C4 D2F E1

EE BC2FC

A x E = 8CA x E = 8C + 8 = 94

B28 9AF

A

94C 63

Dividend = BC2FDivisor = EEQuotient = CARemainder = 63

Page 46: HCS12 Arithmetic

Hex DivisionTable 10.9

Hexadecimal Multiplication Table0 1 2 3 4 5 6 7 8 9 A B C D E F

0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 01 1 2 3 4 5 6 7 8 9 A B C D E F2 4 6 8 A C E 10 12 14 16 18 1A 1C 1E3 9 C F 12 15 18 1B 1E 21 24 27 2A 2D4 10 14 18 1C 20 24 28 2C 30 34 38 3C5 19 1E 23 28 2D 32 37 3C 41 46 4B6 24 2A 30 36 3C 42 48 4E 54 5A7 31 38 3F 46 4D 54 5B 62 698 40 48 50 58 60 68 70 789 51 5A 63 6C 75 7E 87A 64 6E 78 82 8C 96B 79 84 8F 9A A5C 90 9C A8 B4D A9 B6 C3E C4 D2F E1

EE BC2FC

B28 9AF

A

94C 63

=00004000 ORG $4000

4000 CD 0000 LDY #$0000

4003 CC BC2F LDD #$BC2F

4006 CE 00EE LDX #$00EE

4009 11 EDIV ;BC2F/EE = CA rem 63

Page 47: HCS12 Arithmetic

DivisionTable 3.4 Divide Instructions

Mnemonic Function OperationEDIV 32x16 divide (unsigned) (Y:D) / (X) => Y

Remainder => DEDIVS 32x16 divide (signed) (Y:D) / (X) => Y

Remainder => DFDIV 16x16 fractional divide (D) / (X) => X

Remainder => DIDIV 16x16 integer divide (unsigned) (D) / (X) => X

Remainder => DIDIVS 16x16 integer divide (signed) (D) / (X) => X

Remainder => D

Page 48: HCS12 Arithmetic

Y:D/X => YRemainder in D

Page 49: HCS12 Arithmetic

Divisor may be too small

EE FFBC2F11313 rem 85

Quotient does not fit in YOverflow bit, V, will be set

S X

H

I N

Z

V

C Condition code regis ter

Page 50: HCS12 Arithmetic
Page 51: HCS12 Arithmetic

S X

H

I N

Z

V

C Condition code regis ter

Note overflow bit, V, setN and Z are undefined

Y and D unchanged

Page 52: HCS12 Arithmetic

S X

H

I N

Z

V

C Condition code regis ter

Note divide by zero setscarry bit, C

N, Z, and V are undefinedY and D unchanged

Page 53: HCS12 Arithmetic

DivisionTable 3.4 Divide Instructions

Mnemonic Function OperationEDIV 32x16 divide (unsigned) (Y:D) / (X) => Y

Remainder => DEDIVS 32x16 divide (signed) (Y:D) / (X) => Y

Remainder => DFDIV 16x16 fractional divide (D) / (X) => X

Remainder => DIDIV 16x16 integer divide (unsigned) (D) / (X) => X

Remainder => DIDIVS 16x16 integer divide (signed) (D) / (X) => X

Remainder => D

Page 54: HCS12 Arithmetic
Page 55: HCS12 Arithmetic

Y:D/X => YRemainder in D

Note symmetric divisionTruncation toward zeroSign of remainder = sign of dividend

Page 56: HCS12 Arithmetic

Y:D/X => YRemainder in D

Note symmetric divisionTruncation toward zeroSign of remainder = sign of dividend

Page 57: HCS12 Arithmetic

Symetric Division (truncation toward zero)

Dividend Divisor Quotient Remainder

26 7 3 5

-26 7 -3 -5

26 -7 -3 5

-26 -7 3 -5

Floored Division (truncation toward minus infinity)Dividend Divisor Quotient Remainder

26 7 3 5

-26 7 -4 2

26 -7 -4 -2

-26 -7 3 -5

Page 58: HCS12 Arithmetic

Table 3.4 Divide InstructionsMnemonic Function OperationEDIV 32x16 divide (unsigned) (Y:D) / (X) => Y

Remainder => DEDIVS 32x16 divide (signed) (Y:D) / (X) => Y

Remainder => DFDIV 16x16 fractional divide (D) / (X) => X

Remainder => DIDIV 16x16 integer divide (unsigned) (D) / (X) => X

Remainder => DIDIVS 16x16 integer divide (signed) (D) / (X) => X

Remainder => D

D = $0001X = $0002

FDIV => X = $8000 D = $0000

12

= 0.5 = 0.10000000000000002

= 0.800016

Page 59: HCS12 Arithmetic
Page 60: HCS12 Arithmetic

Table 3.4 Divide InstructionsMnemonic Function OperationEDIV 32x16 divide (unsigned) (Y:D) / (X) => Y

Remainder => DEDIVS 32x16 divide (signed) (Y:D) / (X) => Y

Remainder => DFDIV 16x16 fractional divide (D) / (X) => X

Remainder => DIDIV 16x16 integer divide (unsigned) (D) / (X) => X

Remainder => DIDIVS 16x16 integer divide (signed) (D) / (X) => X

Remainder => D

D = $1234X = $0010

IDIV => X = $0123 D = $0004

Page 61: HCS12 Arithmetic
Page 62: HCS12 Arithmetic

Table 3.4 Divide InstructionsMnemonic Function OperationEDIV 32x16 divide (unsigned) (Y:D) / (X) => Y

Remainder => DEDIVS 32x16 divide (signed) (Y:D) / (X) => Y

Remainder => DFDIV 16x16 fractional divide (D) / (X) => X

Remainder => DIDIV 16x16 integer divide (unsigned) (D) / (X) => X

Remainder => DIDIVS 16x16 integer divide (signed) (D) / (X) => X

Remainder => D

D = $FFE6X = $0007

IDIVS => X = $FFFD D = $FFFB

-26 7

= -3 remainder = -5

Page 63: HCS12 Arithmetic
Page 64: HCS12 Arithmetic

Table 3.4 Divide InstructionsMnemonic Function OperationEDIV 32x16 divide (unsigned) (Y:D) / (X) => Y

Remainder => DEDIVS 32x16 divide (signed) (Y:D) / (X) => Y

Remainder => DFDIV 16x16 fractional divide (D) / (X) => X

Remainder => DIDIV 16x16 integer divide (unsigned) (D) / (X) => X

Remainder => DIDIVS 16x16 integer divide (signed) (D) / (X) => X

Remainder => D