Download presentation

Presentation is loading. Please wait.

Published byBaldwin Quinn Modified about 1 year ago

1
HCS12 Arithmetic Lecture 3.3

2
68HC12 Arithmetic Addition and Subtraction Shift and Rotate Instructions Multiplication Division

3
Addition and Subtraction

4

5
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 STD0,X RTS

6
HCS12 code for 1-, 2- ;1- ( n -- n-1 ) ONEP LDD0,X SUBD#1 STD0,X RTS ;2- ( n -- n-2 ) TWOP LDD0,X SUBD#2 STD0,X RTS

7
Double Numbers

8
Adding Double Numbers

9
Subtracting Double Numbers

10
68HC12 Arithmetic Addition and Subtraction Shift and Rotate Instructions Multiplication Division

11

12
Logic Shift Left LSL, LSLA, LSLB C Bit C Bit AB LSLD

13
Logic Shift Right LSR, LSRA, LSRB C Bit C Bit AB LSRD

14
Arithmetic Shift Right ASR, ASRA, ASRB C

15
Rotate Left ROL, ROLA, ROLB C Bit

16
Rotate Right ROR, RORA, RORB C Bit

17
2*, 2/, and U2/

18
68HC12 Arithmetic Addition and Subtraction Shift and Rotate Instructions Multiplication Division

19
Binary Multiplication

20
13 x C = 156

21
Hex Multiplication

22
61 x D x 5A 262 A x D = 82, A x 3 = 1E + 8 = x D = 41, 5 x 3 = F + 4 = = Dec Hex

23
Hex Multiplication product = $1572 is in D = A:B ; multiply 8 x 8 = 16 = ORG $ D LDAA #$3D 4002 C6 5A LDAB #$5A MUL

24
product = $1572 is in D = A:B

25
Multiplication

26
16-Bit Hex Multiplication 31A4 x1B2C 253B0 4 x C = 30 A x C = = 7B 1 x C = C + 7 = 13 3 x C = = 25

27
16-Bit Hex Multiplication 31A4 x1B2C 253B x 4 = 8 2 x A = 14 1 x 2 = = 3 2 x 3 = 6

28
16-Bit Hex Multiplication 31A4 x1B2C 253B C 4 x B = 2C A x B = 6E + 2 = 70 1 x B = B + 7 = 12 3 x B = = 22

29
16-Bit Hex Multiplication 31A4 x1B2C 253B C 31A4 0544D430 ORG $ CC 31A4 LDD #$31A4 ;D = $31A CD 1B2C LDY #$1B2C ;Y = $1B2C EMUL ;Y:D = D x Y

30
Y:D = 0544D430

31
Multiply Instructions Note that EMUL and MUL are unsigned multiplies EMULS is used to multiply signed numbers

32
Unsigned Multiplication Dec Hex x FFF8 x FFC = 7FFC0 16

33
FFF8 x FFC0

34
Unsigned Multiplication Dec Hex x FFF8 x FFC = 7FFC0 16 But FFF8 = can be a signed number 2’s comp = = $0008 = 8 10 Therefore, FFF8 can represent -8

35
Signed Multiplication Dec -8 x = = ’s comp = = $FFFFFF40 Therefore, for signed multiplication $FFF8 x $0008 = $FFFFFF40 and not $7FFC0 The EMULS instruction performs SIGNED multiplication

36
Signed Multiplication product = $FFFFFFC0 is in Y:D ; EMULS signed 16 x 16 = 32 = ORG $ CC FFF8 LDD #$FFF8 ;D = $FFF CD 0008 LDY #$0008 ;Y = $ EMULS ;Y:D = D x Y

37
product = $FFFFFFC0 is in Y:D

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

39
FFF8 x FFC0 -8 x = $FFC0 Correct 16-bit SIGNED result

40
Multiplication Even MUL can be used for an 8 x 8 = 8 SIGNED multiply

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

42
68HC12 Arithmetic Addition and Subtraction Shift and Rotate Instructions Multiplication Division

43
Binary Division D C 9C

44
Hex Division EE BC2F C C x E = A8 C x E = A8 + A = B2 B28 9AF A

45
Hex Division EE BC2F C A x E = 8C A x E = 8C + 8 = 94 B28 9AF A 94C 63 Dividend = BC2F Divisor = EE Quotient = CA Remainder = 63

46
Hex Division EE BC2F C B28 9AF A 94C 63 = ORG $ CD 0000 LDY #$ CC BC2F LDD #$BC2F 4006 CE 00EE LDX #$00EE EDIV ;BC2F/EE = CA rem 63

47
Division

48
Y:D/X => Y Remainder in D

49
Divisor may be too small EE FFBC2F rem 85 Quotient does not fit in Y Overflow bit, V, will be set S X H I N Z V C Condition code register

50

51
S X H I N Z V C Condition code register Note overflow bit, V, set N and Z are undefined Y and D unchanged

52
S X H I N Z V C Condition code register Note divide by zero sets carry bit, C N, Z, and V are undefined Y and D unchanged

53
Division

54

55
Y:D/X => Y Remainder in D Note symmetric division Truncation toward zero Sign of remainder = sign of dividend

56
Y:D/X => Y Remainder in D Note symmetric division Truncation toward zero Sign of remainder = sign of dividend

57
Symetric Division (truncation toward zero) DividendDivisorQuotientRemainder Floored Division (truncation toward minus infinity) DividendDivisorQuotientRemainder

58
D = $0001 X = $0002 FDIV => X = $8000 D = $ = 0.5 = =

59

60
D = $1234 X = $0010 IDIV => X = $0123 D = $0004

61

62
D = $FFE6 X = $0007 IDIVS => X = $FFFD D = $FFFB = -3 remainder = -5

63

64

Similar presentations

© 2017 SlidePlayer.com Inc.

All rights reserved.

Ads by Google