m68k arithmetic instructions
DESCRIPTION
M68k Arithmetic Instructions. ECE 511: Digital System & Microprocessor. What we are going to learn in this session:. M68k arithmetic instructions: Plus Minus Multiply Divide Compare Test Negate. Introduction. Introduction. M68k has instructions for simple arithmetic operations. - PowerPoint PPT PresentationTRANSCRIPT
![Page 1: M68k Arithmetic Instructions](https://reader031.vdocument.in/reader031/viewer/2022012922/56813595550346895d9d0740/html5/thumbnails/1.jpg)
M68k Arithmetic Instructions
ECE 511: Digital System & Microprocessor
![Page 2: M68k Arithmetic Instructions](https://reader031.vdocument.in/reader031/viewer/2022012922/56813595550346895d9d0740/html5/thumbnails/2.jpg)
What we are going to learn in this session: M68k arithmetic instructions:
PlusMinusMultiplyDivideCompareTestNegate
![Page 3: M68k Arithmetic Instructions](https://reader031.vdocument.in/reader031/viewer/2022012922/56813595550346895d9d0740/html5/thumbnails/3.jpg)
Introduction
![Page 4: M68k Arithmetic Instructions](https://reader031.vdocument.in/reader031/viewer/2022012922/56813595550346895d9d0740/html5/thumbnails/4.jpg)
Introduction
M68k has instructions for simple arithmetic operations.
Enhances ability to perform tasks:Perform calculations + control tasks.
Can also do floating-point, but requires math co-processor:Not covered.
![Page 5: M68k Arithmetic Instructions](https://reader031.vdocument.in/reader031/viewer/2022012922/56813595550346895d9d0740/html5/thumbnails/5.jpg)
Some Basics
![Page 6: M68k Arithmetic Instructions](https://reader031.vdocument.in/reader031/viewer/2022012922/56813595550346895d9d0740/html5/thumbnails/6.jpg)
Addressing Modes
![Page 7: M68k Arithmetic Instructions](https://reader031.vdocument.in/reader031/viewer/2022012922/56813595550346895d9d0740/html5/thumbnails/7.jpg)
We have covered these addressing modes
DRD D0 D7ARD A0 A7
Dn and An ARI (An)ARI+PI (An)+ARI+PD -(An)ARI+D D(An)ARI+I D(An,Dn/An.s)PC+D D(PC)PC+I D(PC,Dn/An.s)ALA $001001ASA $FFAAIA CCR, SR, PC
Effective Address: <ea>
ID#($/%/@/’’)
Immediate data: <id>
![Page 8: M68k Arithmetic Instructions](https://reader031.vdocument.in/reader031/viewer/2022012922/56813595550346895d9d0740/html5/thumbnails/8.jpg)
Addressing Modes
Dn: Data Register (D0 D7)32-bit register (32-bit max).
An: Address Register (A0 A7).32-bit register (24-bit max).Don’t use A7.
![Page 9: M68k Arithmetic Instructions](https://reader031.vdocument.in/reader031/viewer/2022012922/56813595550346895d9d0740/html5/thumbnails/9.jpg)
Addressing Modes
<ea> Effective address (24-bit value): $000000 $FFFFFF Also includes Address Register Indirect methods. Anything else: address error.
<id> (Immediate Data): Preceded by #. Binary: %, Octal: @, Hex: $, Decimal: no sign,
Character: ‘ ‘.
![Page 10: M68k Arithmetic Instructions](https://reader031.vdocument.in/reader031/viewer/2022012922/56813595550346895d9d0740/html5/thumbnails/10.jpg)
Addressing Modes Example
D1, D2, D3, D4, …
$123456 24(A0,D0.W) $123(PC) (A4)
A1, A2, A3, A4, …
#1000 #$1F34 #@4567 #$00011011 #’ABCD’
![Page 11: M68k Arithmetic Instructions](https://reader031.vdocument.in/reader031/viewer/2022012922/56813595550346895d9d0740/html5/thumbnails/11.jpg)
2’s Complement
![Page 12: M68k Arithmetic Instructions](https://reader031.vdocument.in/reader031/viewer/2022012922/56813595550346895d9d0740/html5/thumbnails/12.jpg)
2’s Complement
Used by M68k to represent negative numbers.
MSB as sign bit. If 0, positive number. If 1, negative number.
![Page 13: M68k Arithmetic Instructions](https://reader031.vdocument.in/reader031/viewer/2022012922/56813595550346895d9d0740/html5/thumbnails/13.jpg)
2’s Complement Example
Converting 10 to -10:
10 (decimal) = 00001010 (binary)
1. Start with positive number
2. Invert all the bits
00001010(invert) 11110101
3. Add 1 to inverted result
11110101+ 1
11110110 2’s Complement (-10)
![Page 14: M68k Arithmetic Instructions](https://reader031.vdocument.in/reader031/viewer/2022012922/56813595550346895d9d0740/html5/thumbnails/14.jpg)
2’s Complement Example
Converting -5 to 5:
-5 (decimal) = 11111011 (binary)1. The 2’s complement representation:
2. Invert all the bits 11111011
(invert) 00000100
3. Add 1 to inverted result
00000100+ 1
00000101 Positive value (+5)
![Page 15: M68k Arithmetic Instructions](https://reader031.vdocument.in/reader031/viewer/2022012922/56813595550346895d9d0740/html5/thumbnails/15.jpg)
Condition Code Register
![Page 16: M68k Arithmetic Instructions](https://reader031.vdocument.in/reader031/viewer/2022012922/56813595550346895d9d0740/html5/thumbnails/16.jpg)
Condition Code Register (CCR)
Used to store status of evaluated conditions. Final 5-bits of SR. CCR = XNZVC
X: rotate, multi-precision BCD operations. N: result is negative Z: result is zero V: overflow has occurred. C: carry/borrow has occurred.
![Page 17: M68k Arithmetic Instructions](https://reader031.vdocument.in/reader031/viewer/2022012922/56813595550346895d9d0740/html5/thumbnails/17.jpg)
X Example – Rotate
1 10 0 1 1 00
ROXL.B #1,D0
D0.B =
1 10 0 1 1 00
10 0 1 1 00 1
X
X = 1 C = 1
*X keeps extra bit
And moves it to the back…
C set as well
![Page 18: M68k Arithmetic Instructions](https://reader031.vdocument.in/reader031/viewer/2022012922/56813595550346895d9d0740/html5/thumbnails/18.jpg)
N Example
MOVE.B #0,D0 MOVE.B #100,D1 SUB.B D1,D0
D0 = $00 (0)D1 = $64 (100)D0 = 0 – 100 = $9C (-100)
$9C = 1 10 0 1 1 00
MSB = 1, N = 1
![Page 19: M68k Arithmetic Instructions](https://reader031.vdocument.in/reader031/viewer/2022012922/56813595550346895d9d0740/html5/thumbnails/19.jpg)
Z Example
MOVE.L #$FFFFFFFF,D0 SUB.B #$FF,D0
Z = 1* Only B is tested, since .B was used
Initial D0 = F FF F F F FF
Final D0 = F FF F F F 00
![Page 20: M68k Arithmetic Instructions](https://reader031.vdocument.in/reader031/viewer/2022012922/56813595550346895d9d0740/html5/thumbnails/20.jpg)
V- Overflow Bit
Set during arithmetic/divide overflow. For ADD, SUB & CMP:
P + P = NN + N = PP – N = NN – P = P
More on divide overflow later.
* P = Positive Number (MSB = 0) N = Negative Number (MSB = 1)
![Page 21: M68k Arithmetic Instructions](https://reader031.vdocument.in/reader031/viewer/2022012922/56813595550346895d9d0740/html5/thumbnails/21.jpg)
V Example
MOVE.B #$41,D0 MOVE.B #$46,D1 ADD.B D1,D0
0 1 0 0 0 0 0 1
0 1 0 0 0 1 1 0
D0.B =
+ D1.B =
1 0 0 0 0 1 1 1New D0.B =
V = 1
+65
+70
-121?
2’s complement
D0 = 65 + 70
![Page 22: M68k Arithmetic Instructions](https://reader031.vdocument.in/reader031/viewer/2022012922/56813595550346895d9d0740/html5/thumbnails/22.jpg)
V Example
MOVE.B #$41,D0 MOVE.B #$BA,D1 SUB.B D1,D0
0 1 0 0 0 0 0 1
1 0 1 1 1 0 1 0
D0.B =
- D1.B =
1 0 0 0 0 1 1 1New D0.B =
V = 1
+65
-70
-79?
2’s complement
D0 = 65 – (-70)
![Page 23: M68k Arithmetic Instructions](https://reader031.vdocument.in/reader031/viewer/2022012922/56813595550346895d9d0740/html5/thumbnails/23.jpg)
C Example - Carry
MOVE.B #$FF,D0 MOVE.B #$FF,D1 ADD.B D1,D0
D0.B = 1 11 1 1 1 11
D1.B = 1 11 1 1 1 11+
1 11 1 1 1 011
Carry occurred, C = 1
![Page 24: M68k Arithmetic Instructions](https://reader031.vdocument.in/reader031/viewer/2022012922/56813595550346895d9d0740/html5/thumbnails/24.jpg)
C Example - Borrow
MOVE.B #$12,D0 MOVE.B #$34,D1 SUB.B D1,D0
D0.B = 0 00 0 1 0 01
D1.B = 0 10 1 1 0 00-
1 11 0 1 1 01
Borrow occurred, C = 1
![Page 25: M68k Arithmetic Instructions](https://reader031.vdocument.in/reader031/viewer/2022012922/56813595550346895d9d0740/html5/thumbnails/25.jpg)
Add Instructions
![Page 26: M68k Arithmetic Instructions](https://reader031.vdocument.in/reader031/viewer/2022012922/56813595550346895d9d0740/html5/thumbnails/26.jpg)
Available Instructions
Add Instructions
ADD
ADDA
ADDI
ADDQ
ADDX
![Page 27: M68k Arithmetic Instructions](https://reader031.vdocument.in/reader031/viewer/2022012922/56813595550346895d9d0740/html5/thumbnails/27.jpg)
ADD
Adds two numbers together. D = S + D. Can use BWL. Effects all CCR.
![Page 28: M68k Arithmetic Instructions](https://reader031.vdocument.in/reader031/viewer/2022012922/56813595550346895d9d0740/html5/thumbnails/28.jpg)
ADD
Dn An (An) (An)+ -(An) d(An) d(An,i) ASA ALA d(PC) d(PC,i) #n
s s s s s s s s s s s s
d d d d d d d d d - - -
N Z V CX
* * * **BWL
![Page 29: M68k Arithmetic Instructions](https://reader031.vdocument.in/reader031/viewer/2022012922/56813595550346895d9d0740/html5/thumbnails/29.jpg)
How ADD Effects CCR
X = set according to C. N = 1 if MSB is 1. Z = 1 if all active bits are 0. V = 1 if overflow occurred (4 rules). C = 1 if carry occurred.
![Page 30: M68k Arithmetic Instructions](https://reader031.vdocument.in/reader031/viewer/2022012922/56813595550346895d9d0740/html5/thumbnails/30.jpg)
ADD Example D0 = $000011FF D1 = $22223333 ADD.B D0,D1
0 0 0 0 1 1 F F
2 2 2 2 3 3 3 3D1 =
+ D0 =
2 2 2 2 3 3 3 2D1 =
Only lower byte changed, the rest are the same.
CCRX = CN = 0, MSB = 0Z = 0, result non-zero.V = 0, (N + P = P).C = 1, carry occurred.
![Page 31: M68k Arithmetic Instructions](https://reader031.vdocument.in/reader031/viewer/2022012922/56813595550346895d9d0740/html5/thumbnails/31.jpg)
Try It Yourself
STARTORG $1000
move.l #$000011ff,d0move.l #$22223333,d1add.b d0,d1
END START
![Page 32: M68k Arithmetic Instructions](https://reader031.vdocument.in/reader031/viewer/2022012922/56813595550346895d9d0740/html5/thumbnails/32.jpg)
ADDA (Add Address)
Perform add to An:Destination must be An.
Can use WL:W sign-extended to 32-bits before add.
Doesn’t effect CCR.
![Page 33: M68k Arithmetic Instructions](https://reader031.vdocument.in/reader031/viewer/2022012922/56813595550346895d9d0740/html5/thumbnails/33.jpg)
ADDA
Dn An (An) (An)+ -(An) d(An) d(An,i) ASA ALA d(PC) d(PC,i) #n
s s s s s s s s s s s s
- d - - - - - - - - - -
N Z V CX
- - - --WL
![Page 34: M68k Arithmetic Instructions](https://reader031.vdocument.in/reader031/viewer/2022012922/56813595550346895d9d0740/html5/thumbnails/34.jpg)
ADDA ExampleD0 = $0000AAAAA1 = $00001111ADDA.W D0,A1
sign-extended.
0 0 0 0 1 1 1 1
0 0 0 0 A A A A+
A0 =
F F F F B B B BA0 =
X = unchangedN = unchangedZ = unchangedV = unchangedC = unchanged
![Page 35: M68k Arithmetic Instructions](https://reader031.vdocument.in/reader031/viewer/2022012922/56813595550346895d9d0740/html5/thumbnails/35.jpg)
Try It Yourself
STARTORG $1000
movea.l #$0000aaaa,a0movea.l #$00001111,a1adda.w a0,a1
END START
![Page 36: M68k Arithmetic Instructions](https://reader031.vdocument.in/reader031/viewer/2022012922/56813595550346895d9d0740/html5/thumbnails/36.jpg)
ADDA ExampleD0 = $0000AAAAA1 = $00001111ADDA.L D0,A1
.L is used, value in D0 not sign-extended.
0 0 0 0 1 1 1 1
0 0 0 0 A A A A+ D0 =
A0 =
0 0 0 0 B B B BA0 =
X = unchangedN = unchangedZ = unchangedV = unchangedC = unchanged
![Page 37: M68k Arithmetic Instructions](https://reader031.vdocument.in/reader031/viewer/2022012922/56813595550346895d9d0740/html5/thumbnails/37.jpg)
Try It Yourself
STARTORG $1000
movea.l #$0000aaaa,a0movea.l #$00001111,a1adda.l a0,a1
END START
![Page 38: M68k Arithmetic Instructions](https://reader031.vdocument.in/reader031/viewer/2022012922/56813595550346895d9d0740/html5/thumbnails/38.jpg)
ADDI (Add Immediate)
Adds immediate data to destination. Source must be immediate data. Can use BWL. Effects all CCR (similar to ADD).
![Page 39: M68k Arithmetic Instructions](https://reader031.vdocument.in/reader031/viewer/2022012922/56813595550346895d9d0740/html5/thumbnails/39.jpg)
ADDI
Dn An (An) (An)+ -(An) d(An) d(An,i) ASA ALA d(PC) d(PC,i) #n
- - - - - - - - - - - s
d - d d d d d d d - - -
N Z V CX
* * * **BWL
![Page 40: M68k Arithmetic Instructions](https://reader031.vdocument.in/reader031/viewer/2022012922/56813595550346895d9d0740/html5/thumbnails/40.jpg)
ADDI ExampleD0 = $12345678ADDI.L #$44,D0
1 2 3 4 5 6 7 8D0=
4 4+
1 2 3 4 5 6 B CD0=
CCRX = Set similar to CN = 0 (MSB = 0) Z = 0 (result nonzero)V = 0 (P + P = P)C = 0 (No carry)
000000
![Page 41: M68k Arithmetic Instructions](https://reader031.vdocument.in/reader031/viewer/2022012922/56813595550346895d9d0740/html5/thumbnails/41.jpg)
Try It Yourself
STARTORG $1000
move.l #$12345678,d0
addi.l #$44,d0
END START
![Page 42: M68k Arithmetic Instructions](https://reader031.vdocument.in/reader031/viewer/2022012922/56813595550346895d9d0740/html5/thumbnails/42.jpg)
ADDQ (Add Quick)
Similar to ADDI, but immediate data between 1 8.
Can use BWL. Effects all CCR (similar to ADD). Generates smaller MC, faster execution.
![Page 43: M68k Arithmetic Instructions](https://reader031.vdocument.in/reader031/viewer/2022012922/56813595550346895d9d0740/html5/thumbnails/43.jpg)
ADDQ
Dn An (An) (An)+ -(An) d(An) d(An,i) ASA ALA d(PC) d(PC,i) #n
- - - - - - - - - - - s
d d d d d d d d d - - -
N Z V CX
* * * **BWL
![Page 44: M68k Arithmetic Instructions](https://reader031.vdocument.in/reader031/viewer/2022012922/56813595550346895d9d0740/html5/thumbnails/44.jpg)
ADDQ ExampleD0 = $12345678ADDQ.B #1,D0
1 2 3 4 5 6 7 8D0=
0 1+
1 2 3 4 5 6 7 9D0=
CCRX = Set similar to CN = 0 (MSB = 0) Z = 0 (result nonzero)V = 0 (P + P = P)C = 0 (No carry)
![Page 45: M68k Arithmetic Instructions](https://reader031.vdocument.in/reader031/viewer/2022012922/56813595550346895d9d0740/html5/thumbnails/45.jpg)
Try It Yourself
STARTORG $1000
move.l #$12345678,d0
addq.l #$01,d0
END START
![Page 46: M68k Arithmetic Instructions](https://reader031.vdocument.in/reader031/viewer/2022012922/56813595550346895d9d0740/html5/thumbnails/46.jpg)
This Causes an Error. Why?
STARTORG $1000
move.l #$12345678,d0
addq.l #$9,d0
END START
![Page 47: M68k Arithmetic Instructions](https://reader031.vdocument.in/reader031/viewer/2022012922/56813595550346895d9d0740/html5/thumbnails/47.jpg)
ADDX (Add Extended)
Adds X together with results. D = D + S + X. Can use BWL. Limited addressing modes. Effects all CCR.
![Page 48: M68k Arithmetic Instructions](https://reader031.vdocument.in/reader031/viewer/2022012922/56813595550346895d9d0740/html5/thumbnails/48.jpg)
ADDX
Dn An (An) (An)+ -(An) d(An) d(An,i) ASA ALA d(PC) d(PC,i) #n
s - - - s - - - - - - -
d - - - d - - - - - - -
N Z V CX
* * * **BWL
![Page 49: M68k Arithmetic Instructions](https://reader031.vdocument.in/reader031/viewer/2022012922/56813595550346895d9d0740/html5/thumbnails/49.jpg)
ADDX ExampleD0 = $12345678D1 = $ABCDEF12X = 1ADDX.B D1,D0
1 2 3 4 5 6 7 8D0=
1+
1 2 3 4 5 6 8 BD0=
CCRX = Set similar to CN = 1 (MSB = 1) Z = 0 (result nonzero)V = 1 (P + P = N)C = 0 (No carry)
A B C D E F 1 2D1=
![Page 50: M68k Arithmetic Instructions](https://reader031.vdocument.in/reader031/viewer/2022012922/56813595550346895d9d0740/html5/thumbnails/50.jpg)
Try It Yourself
START ORG $1000
move.l #$12345678,d0move.l #$ABCDEF12,d1and.b #$00,ccror.b #$10,ccraddx.b d1,d0
END START
![Page 51: M68k Arithmetic Instructions](https://reader031.vdocument.in/reader031/viewer/2022012922/56813595550346895d9d0740/html5/thumbnails/51.jpg)
Subtraction Instructions
![Page 52: M68k Arithmetic Instructions](https://reader031.vdocument.in/reader031/viewer/2022012922/56813595550346895d9d0740/html5/thumbnails/52.jpg)
Available Instructions
Subtract Instructions
SUB
SUBA
SUBI
SUBQ
SUBX
![Page 53: M68k Arithmetic Instructions](https://reader031.vdocument.in/reader031/viewer/2022012922/56813595550346895d9d0740/html5/thumbnails/53.jpg)
SUB
Subtracts source from destination. D = D – S. Can use BWL. Effects all CCR.
![Page 54: M68k Arithmetic Instructions](https://reader031.vdocument.in/reader031/viewer/2022012922/56813595550346895d9d0740/html5/thumbnails/54.jpg)
SUB
Dn An (An) (An)+ -(An) d(An) d(An,i) ASA ALA d(PC) d(PC,i) #n
s s s s s s s s s s s s
d d d d d d d d d - - -
N Z V CX
* * * **BWL
![Page 55: M68k Arithmetic Instructions](https://reader031.vdocument.in/reader031/viewer/2022012922/56813595550346895d9d0740/html5/thumbnails/55.jpg)
How SUB Effects CCR
X = set according to C. N = 1 if MSB is 1. Z = 1 if all active bits are 0. V = 1 if overflow occurred. C = 1 if borrow occurred.
![Page 56: M68k Arithmetic Instructions](https://reader031.vdocument.in/reader031/viewer/2022012922/56813595550346895d9d0740/html5/thumbnails/56.jpg)
SUB Example D0 = $00004444 D1 = $22223333 SUB.W D0,D1
0 0 0 0 4 4 4 4
2 2 2 2 3 3 3 3
- D0 =
D1 =
2 2 2 2 E E E FD1 = (destination)X = CN = 1, MSB = 1Z = 0, result non-zero.V = 0 (P – P = N).C = 1, borrow occurred.
![Page 57: M68k Arithmetic Instructions](https://reader031.vdocument.in/reader031/viewer/2022012922/56813595550346895d9d0740/html5/thumbnails/57.jpg)
Try It Yourself
STARTORG $1000
move.l #$00004444,d0move.l #$22223333,d1sub.w d0,d1
END START
![Page 58: M68k Arithmetic Instructions](https://reader031.vdocument.in/reader031/viewer/2022012922/56813595550346895d9d0740/html5/thumbnails/58.jpg)
SUBA (Subtract Address)
Used to subtract values from address register.
Can use WL. Source not sign-extended (unlike ADDA). Doesn’t effect CCR.
![Page 59: M68k Arithmetic Instructions](https://reader031.vdocument.in/reader031/viewer/2022012922/56813595550346895d9d0740/html5/thumbnails/59.jpg)
SUBA
Dn An (An) (An)+ -(An) d(An) d(An,i) ASA ALA d(PC) d(PC,i) #n
s s s s s s s s s s s s
- d - - - - - - - - - -
N Z V CX
- - - --WL
![Page 60: M68k Arithmetic Instructions](https://reader031.vdocument.in/reader031/viewer/2022012922/56813595550346895d9d0740/html5/thumbnails/60.jpg)
SUBA Example A0 = $00002222 D1 = $2222EEEE SUBA.W D1,A0
2 2 2 2 E E E E
0 0 0 0 2 2 2 2
- D1 =
A0 =
0 0 0 0 3 3 3 4A0 =
Only lower word changed, the rest are the same.
(destination)
XNZVC unchanged
![Page 61: M68k Arithmetic Instructions](https://reader031.vdocument.in/reader031/viewer/2022012922/56813595550346895d9d0740/html5/thumbnails/61.jpg)
Try It Yourself
STARTORG $1000
move.l #$00002222,a0move.l #$2222EEEE,d1suba.w d1,a0
END START
![Page 62: M68k Arithmetic Instructions](https://reader031.vdocument.in/reader031/viewer/2022012922/56813595550346895d9d0740/html5/thumbnails/62.jpg)
SUBI (Subtract Immediate)
Subtracts immediate data from destination.
Can use BWL. Effects all CCR similar to SUB.
![Page 63: M68k Arithmetic Instructions](https://reader031.vdocument.in/reader031/viewer/2022012922/56813595550346895d9d0740/html5/thumbnails/63.jpg)
SUBI
Dn An (An) (An)+ -(An) d(An) d(An,i) ASA ALA d(PC) d(PC,i) #n
- - - - - - - - - - - s
d - d d d d d d d - - -
N Z V CX
* * * **BWL
![Page 64: M68k Arithmetic Instructions](https://reader031.vdocument.in/reader031/viewer/2022012922/56813595550346895d9d0740/html5/thumbnails/64.jpg)
SUBI Example D0 = $00001234 SUBI.W #$3345,D0
0 0 0 0 3 3 4 5
0 0 0 0 1 2 3 4
-
D1 =
0 0 0 0 D E E FD1 =
Only lower word changed, the rest are the same.
(destination) X = CN = 1, MSB = 1Z = 0, result non-zero.V = 0 (P – P = N).C = 1, borrow occurred.
![Page 65: M68k Arithmetic Instructions](https://reader031.vdocument.in/reader031/viewer/2022012922/56813595550346895d9d0740/html5/thumbnails/65.jpg)
Try It Yourself
STARTORG $1000
move.l #$00001234,d0
SUBI.W #$3345,D0
END START
![Page 66: M68k Arithmetic Instructions](https://reader031.vdocument.in/reader031/viewer/2022012922/56813595550346895d9d0740/html5/thumbnails/66.jpg)
SUBQ (Subtract Quick)
Similar to SUBI, but immediate data between 1 8.
Source must be immediate data. Can use BWL. Effects all CCR (similar to SUB). Generates smaller MC, faster execution.
![Page 67: M68k Arithmetic Instructions](https://reader031.vdocument.in/reader031/viewer/2022012922/56813595550346895d9d0740/html5/thumbnails/67.jpg)
SUBQ
Dn An (An) (An)+ -(An) d(An) d(An,i) ASA ALA d(PC) d(PC,i) #n
- - - - - - - - - - - s
d - d d d d d d d - - -
N Z V CX
* * * **BWL
![Page 68: M68k Arithmetic Instructions](https://reader031.vdocument.in/reader031/viewer/2022012922/56813595550346895d9d0740/html5/thumbnails/68.jpg)
SUBQ ExampleD0 = $12345678SUBQ.B #$07,D0
1 2 3 4 5 6 7 8D0=
0 7-
1 2 3 4 5 6 7 1D0=
CCRX = Set similar to CN = 0 (MSB = 0) Z = 0 (result nonzero)V = 0 (P - P = P)C = 0 (No carry)
![Page 69: M68k Arithmetic Instructions](https://reader031.vdocument.in/reader031/viewer/2022012922/56813595550346895d9d0740/html5/thumbnails/69.jpg)
Try It Yourself
STARTORG $1000
move.l #$12345678,d0
SUBQ.B #$07,D0
END START
![Page 70: M68k Arithmetic Instructions](https://reader031.vdocument.in/reader031/viewer/2022012922/56813595550346895d9d0740/html5/thumbnails/70.jpg)
SUBX (Subtract Extended)
Subtracts X with results. D = D - S - X. Can use BWL. Limited addressing modes. Effects all CCR.
![Page 71: M68k Arithmetic Instructions](https://reader031.vdocument.in/reader031/viewer/2022012922/56813595550346895d9d0740/html5/thumbnails/71.jpg)
SUBX
Dn An (An) (An)+ -(An) d(An) d(An,i) ASA ALA d(PC) d(PC,i) #n
s - - - s - - - - - - -
d - - - d - - - - - - -
N Z V CX
* * * **BWL
![Page 72: M68k Arithmetic Instructions](https://reader031.vdocument.in/reader031/viewer/2022012922/56813595550346895d9d0740/html5/thumbnails/72.jpg)
SUBX Example
D0 = $12345678D1 = $ABCDEFABX = 1SUBX.B D1,D0
1 2 3 4 5 6 7 8D0=
1-
1 2 3 4 5 6 C CD0=
CCRX = Set similar to CN = 1 (MSB = 1) Z = 0 (result nonzero)V = 1 (P – N = N)C = 1 (borrow occurred)
A B C D E F A BD1=
![Page 73: M68k Arithmetic Instructions](https://reader031.vdocument.in/reader031/viewer/2022012922/56813595550346895d9d0740/html5/thumbnails/73.jpg)
Try It Yourself
START ORG $1000
MOVE.L #$12345678,D0MOVE.L #$ABCDEFAB,D1AND.B #$00,CCROR.B #$10,CCRSUBX.B D1,D0
END START
![Page 74: M68k Arithmetic Instructions](https://reader031.vdocument.in/reader031/viewer/2022012922/56813595550346895d9d0740/html5/thumbnails/74.jpg)
Compare Instruction
![Page 75: M68k Arithmetic Instructions](https://reader031.vdocument.in/reader031/viewer/2022012922/56813595550346895d9d0740/html5/thumbnails/75.jpg)
Available Instructions
Compare Instructions
CMP
CMPA
CMPI
CMPM
![Page 76: M68k Arithmetic Instructions](https://reader031.vdocument.in/reader031/viewer/2022012922/56813595550346895d9d0740/html5/thumbnails/76.jpg)
CMP (Compare)
Compare destination to source:Similar to SUB (D - S), but doesn’t modify
source/destination.Only modifies CCR.Destination must be data register.
Can use BWL. Effects all CCR except X.
![Page 77: M68k Arithmetic Instructions](https://reader031.vdocument.in/reader031/viewer/2022012922/56813595550346895d9d0740/html5/thumbnails/77.jpg)
CMP vs. SUB
CMPSUB
Subtracts source from destination.
Final result
Method of operationSubtracts source from destination.
Result not stored, only CCR updated.
Result stored in destination.
CCR ResultUpdated according
to “subtract” operation. Effects all CCR except X.
Updated according to subtract operation.
Effects all CCR.
BWLValid operand size BWL
Effect on X X unchanged.X = C
![Page 78: M68k Arithmetic Instructions](https://reader031.vdocument.in/reader031/viewer/2022012922/56813595550346895d9d0740/html5/thumbnails/78.jpg)
CMP
Dn An (An) (An)+ -(An) d(An) d(An,i) ASA ALA d(PC) d(PC,i) #n
s s s s s s s s s s s s
d - - - - - - - - - - -
N Z V CX
* * * *-BWL
![Page 79: M68k Arithmetic Instructions](https://reader031.vdocument.in/reader031/viewer/2022012922/56813595550346895d9d0740/html5/thumbnails/79.jpg)
How CMP Effects CCR
X = unchanged. N = 1 if MSB is 1. Z = 1 if all active bits are 0. V = 1 if overflow occurred. C = 1 if borrow occurred.
![Page 80: M68k Arithmetic Instructions](https://reader031.vdocument.in/reader031/viewer/2022012922/56813595550346895d9d0740/html5/thumbnails/80.jpg)
CMP Example D0 = $00001212 D1 = $22221234 CMP.B D0,D1
0 0 0 0 1 2 1 2
2 2 2 2 1 2 3 4
- D0 =
D1 =
X = unchangedN = 0 (MSB = 0)Z = 0 (result non-zero)V = 0 (P – P = P).C = 0 (no borrow).
2 2 2 2 1 2 2 2“D1” =
2 2 2 2 1 2 3 4Actual D1 =
![Page 81: M68k Arithmetic Instructions](https://reader031.vdocument.in/reader031/viewer/2022012922/56813595550346895d9d0740/html5/thumbnails/81.jpg)
Try It Yourself
STARTORG $1000
MOVE.L #$00001212,D0MOVE.L #$22221234,D1CMP.B D0,D1
END START
![Page 82: M68k Arithmetic Instructions](https://reader031.vdocument.in/reader031/viewer/2022012922/56813595550346895d9d0740/html5/thumbnails/82.jpg)
CMP Example
0 1 2 3 4 5 6 7D3 =
CMP.W #$4567,D3
D3.W = $4567- $4567
$0000
*Original D3 value unchanged.
0 1 2 3 4 5 6 7Final D3 =
X = unchangedN = 0 (MSB = 0)Z = 1 (result zero)V = 0 (P – P = P).C = 0 (no borrow).
![Page 83: M68k Arithmetic Instructions](https://reader031.vdocument.in/reader031/viewer/2022012922/56813595550346895d9d0740/html5/thumbnails/83.jpg)
Try It Yourself
STARTORG $1000
MOVE.L #$01234567,D3
CMP.W #$4567,D3
END START
![Page 84: M68k Arithmetic Instructions](https://reader031.vdocument.in/reader031/viewer/2022012922/56813595550346895d9d0740/html5/thumbnails/84.jpg)
CMP Example
0 0 0 0 0 0 5 0D3 =
CMP.B D4,D3
D3.B = $50D4.B = - $60
$F0
0 0 0 0 0 0 6 0D4 =
*Original D3, D4 unchanged.
0 0 0 0 0 0 6 0Final D4 =
0 0 0 0 0 0 5 0Final D3 = X = unchangedN = 1 (MSB = 1)Z = 0 (result nonzero)V = 0 (P – P = N).C = 1 (borrow occurred).
![Page 85: M68k Arithmetic Instructions](https://reader031.vdocument.in/reader031/viewer/2022012922/56813595550346895d9d0740/html5/thumbnails/85.jpg)
CMPA (Compare Address)
Compare address register to source:Doesn’t modify source/destination.Only modifies CCR.Destination must be address register.
Can use WL. Effects all CCR except X.
![Page 86: M68k Arithmetic Instructions](https://reader031.vdocument.in/reader031/viewer/2022012922/56813595550346895d9d0740/html5/thumbnails/86.jpg)
CMPA
Dn An (An) (An)+ -(An) d(An) d(An,i) ASA ALA d(PC) d(PC,i) #n
s s s s s s s s s s s s
- d - - - - - - - - - -
N Z V CX
* * * *-WL
![Page 87: M68k Arithmetic Instructions](https://reader031.vdocument.in/reader031/viewer/2022012922/56813595550346895d9d0740/html5/thumbnails/87.jpg)
CMPA Example A0 = $00002222 D1 = $2222EEEE CMPA.W D1,A0
2 2 2 2 E E E E
0 0 0 0 2 2 2 2
- D1 =
A0 =
0 0 0 0 3 3 3 4“A0” =
X = unchangedN = 0 (MSB is 0)Z = 0 (result nonzero)V = 0 (P – N = P)C = 1 (borrow occurred)
Final A0 = 0 0 0 0 2 2 2 2
![Page 88: M68k Arithmetic Instructions](https://reader031.vdocument.in/reader031/viewer/2022012922/56813595550346895d9d0740/html5/thumbnails/88.jpg)
Try It Yourself
STARTORG $1000
MOVEA.L #$00002222,A0MOVE.L #$2222EEEE,D1CMPA.W D1,A0
END START
![Page 89: M68k Arithmetic Instructions](https://reader031.vdocument.in/reader031/viewer/2022012922/56813595550346895d9d0740/html5/thumbnails/89.jpg)
CMPI (Compare Immediate)
Compares destination to immediate data. Source must be immediate data. Can use BWL. Effects all CCR except X (same as CMP).
![Page 90: M68k Arithmetic Instructions](https://reader031.vdocument.in/reader031/viewer/2022012922/56813595550346895d9d0740/html5/thumbnails/90.jpg)
CMPI
Dn An (An) (An)+ -(An) d(An) d(An,i) ASA ALA d(PC) d(PC,i) #n
- - - - - - - - - - - s
d - d d d d d d d - - -
N Z V CX
* * * *-BWL
![Page 91: M68k Arithmetic Instructions](https://reader031.vdocument.in/reader031/viewer/2022012922/56813595550346895d9d0740/html5/thumbnails/91.jpg)
CMPI Example D4 = $0000AABB CMPI.W #$7ABB,D4
0 0 0 0 7 A B B
0 0 0 0 A A B B
-
D4 =
0 0 0 0 3 0 0 0“D4” = X = unchangedN = 0, MSB = 0Z = 0, result non-zero.V = 1 (N – P = P).C = 0, no borrow.
0 0 0 0 A A B BActual D4 =
![Page 92: M68k Arithmetic Instructions](https://reader031.vdocument.in/reader031/viewer/2022012922/56813595550346895d9d0740/html5/thumbnails/92.jpg)
Try It Yourself
STARTORG $1000
MOVE.L #$0000AABB,D4
CMPI.W #$7ABB,D4
END START
![Page 93: M68k Arithmetic Instructions](https://reader031.vdocument.in/reader031/viewer/2022012922/56813595550346895d9d0740/html5/thumbnails/93.jpg)
CMPM (Compare Memory)
Compare between two memory locations. Can use BWL. Source & destination must be memory. Effects all CCR except X (same as CMP). Only ARI + PI addressing allowed.
![Page 94: M68k Arithmetic Instructions](https://reader031.vdocument.in/reader031/viewer/2022012922/56813595550346895d9d0740/html5/thumbnails/94.jpg)
CMPM
Dn An (An) (An)+ -(An) d(An) d(An,i) ASA ALA d(PC) d(PC,i) #n
- - - s - - - - - - - -
- - - d - - - - - - - -
N Z V CX
* * * *-BWL
![Page 95: M68k Arithmetic Instructions](https://reader031.vdocument.in/reader031/viewer/2022012922/56813595550346895d9d0740/html5/thumbnails/95.jpg)
CMPM Example
$2003 66
$2004 76
$2002 33
$2001 11
$2000 AA
$1003 33
$1004 44
$1002 22
$1001 11
$1000 00
A0 = $001002A1 = $002000CMPM.W (A0)+,(A1)+
11AA(A1) =
3322- (A0) =
ED78Result =
X = unchangedN = 1 (MSB = 1)Z = 0 (Result non-zero)V = 0 (N – P = N)C = 0 (No carry)
*Memory valuesunchanged.* A1, A0 increased by 2
![Page 96: M68k Arithmetic Instructions](https://reader031.vdocument.in/reader031/viewer/2022012922/56813595550346895d9d0740/html5/thumbnails/96.jpg)
Multiply Instructions
![Page 97: M68k Arithmetic Instructions](https://reader031.vdocument.in/reader031/viewer/2022012922/56813595550346895d9d0740/html5/thumbnails/97.jpg)
Available Instructions
Multiply Instructions
MULU
MULS
![Page 98: M68k Arithmetic Instructions](https://reader031.vdocument.in/reader031/viewer/2022012922/56813595550346895d9d0740/html5/thumbnails/98.jpg)
MULU (Multiply Unsigned)
Multiplies two 16-bit unsigned numbers and produces 32-bit unsigned result.
Destination MUST be Dn. Effects all CCR except X.
![Page 99: M68k Arithmetic Instructions](https://reader031.vdocument.in/reader031/viewer/2022012922/56813595550346895d9d0740/html5/thumbnails/99.jpg)
MULU
Dn An (An) (An)+ -(An) d(An) d(An,i) ASA ALA d(PC) d(PC,i) #n
s - s s s s s s s s s s
d - - - - - - - - - - -
N Z V CX
* * 0 0-W x W
![Page 100: M68k Arithmetic Instructions](https://reader031.vdocument.in/reader031/viewer/2022012922/56813595550346895d9d0740/html5/thumbnails/100.jpg)
MULU Example
0 0 C 80 0 0 0D0 =
D0 replaced completely
0 0 0 20 0 6 4 X
16-bit 16-bit
MULU D1,D0
0 0 6 40 0 0 0
0 0 0 20 0 0 0
D0 =
D1 =
100 decimal
2 decimal
100 x 2 = 200 = $C8X = unchangedN = 0 (MSB = 0)Z = 0 (result non-zero)V = 0C = 0
![Page 101: M68k Arithmetic Instructions](https://reader031.vdocument.in/reader031/viewer/2022012922/56813595550346895d9d0740/html5/thumbnails/101.jpg)
Try It Yourself
STARTORG $1000
MOVE.L #$64,D0MOVE.L #$02,D1MULU D1,D0
END START
![Page 102: M68k Arithmetic Instructions](https://reader031.vdocument.in/reader031/viewer/2022012922/56813595550346895d9d0740/html5/thumbnails/102.jpg)
MULS (Multiply Signed)
Multiplies two 16-bit signed numbers and produces 32-bit signed result.
Destination MUST be Dn. Effects all CCR except X.
![Page 103: M68k Arithmetic Instructions](https://reader031.vdocument.in/reader031/viewer/2022012922/56813595550346895d9d0740/html5/thumbnails/103.jpg)
MULS
Dn An (An) (An)+ -(An) d(An) d(An,i) ASA ALA d(PC) d(PC,i) #n
s - s s s s s s s s s s
d - - - - - - - - - - -
N Z V CX
* * 0 0-W x W
![Page 104: M68k Arithmetic Instructions](https://reader031.vdocument.in/reader031/viewer/2022012922/56813595550346895d9d0740/html5/thumbnails/104.jpg)
MULS Example
F 6 3 CF F F FD0 =
D0 replaced completely
0 0 0 5F E 0 C X
16-bit 16-bit
F E 0 C0 0 0 0
0 0 0 50 0 0 0
D0 =
D1 =
MULU D1,D0
-500 decimal
5 decimal
-500 x 5 = -2500 = $F63C X = unchangedN = 1 (MSB is 1)Z = 0 (result non-zero)V = always clearedC = always cleared
![Page 105: M68k Arithmetic Instructions](https://reader031.vdocument.in/reader031/viewer/2022012922/56813595550346895d9d0740/html5/thumbnails/105.jpg)
Try It Yourself
STARTORG $1000
MOVE.L #$0000FE0C,D0MOVE.L #$00000005,D1MULS D1,D0
END START
![Page 106: M68k Arithmetic Instructions](https://reader031.vdocument.in/reader031/viewer/2022012922/56813595550346895d9d0740/html5/thumbnails/106.jpg)
Divide Instructions
![Page 107: M68k Arithmetic Instructions](https://reader031.vdocument.in/reader031/viewer/2022012922/56813595550346895d9d0740/html5/thumbnails/107.jpg)
Available Instructions
Divide Instructions
DIVU
DIVS
![Page 108: M68k Arithmetic Instructions](https://reader031.vdocument.in/reader031/viewer/2022012922/56813595550346895d9d0740/html5/thumbnails/108.jpg)
DIVU (Divide Unsigned)
Divides 32-bit unsigned number by 16-bit unsigned number.
Produces 32-bit result.Lower 16-bits are quotient (hasil).Upper 16-bits are remainder (baki).
Destination MUST be Dn. Effects all CCR except X.
![Page 109: M68k Arithmetic Instructions](https://reader031.vdocument.in/reader031/viewer/2022012922/56813595550346895d9d0740/html5/thumbnails/109.jpg)
DIVU
/Source Divisor
Quotient (Hasil)Remainder (Baki)
Destination
L W
WW
![Page 110: M68k Arithmetic Instructions](https://reader031.vdocument.in/reader031/viewer/2022012922/56813595550346895d9d0740/html5/thumbnails/110.jpg)
DIVU
Dn An (An) (An)+ -(An) d(An) d(An,i) ASA ALA d(PC) d(PC,i) #n
s - s s s s s s s s s s
d - - - - - - - - - - -
N Z V CX
* * * 0-L ÷ W
![Page 111: M68k Arithmetic Instructions](https://reader031.vdocument.in/reader031/viewer/2022012922/56813595550346895d9d0740/html5/thumbnails/111.jpg)
How DIVU Effects the CCR
X = unchanged. N = Set if quotient MSB is 1. Z = Set if quotient is zero. V = Set if division overflow occurs.
V = undefined if divide-by-zero. C = Always cleared.
![Page 112: M68k Arithmetic Instructions](https://reader031.vdocument.in/reader031/viewer/2022012922/56813595550346895d9d0740/html5/thumbnails/112.jpg)
DIVU ExampleD0 = $000186A1 (100,001 decimal)
D1 = $000000C (12 decimal)
DIVU D1,D0
100,001 / 12 = 8333, remainder 5
Decimal 8,333 5
Quotient Remainder
Hex $208D $0005
2 80 DNew D0 = 0 0 0 5
X = unchangedN = 0 (Q MSB is 0)Z = 0 (Q nonzero)V = 0 (no overflow)C = always cleared
![Page 113: M68k Arithmetic Instructions](https://reader031.vdocument.in/reader031/viewer/2022012922/56813595550346895d9d0740/html5/thumbnails/113.jpg)
Try It Yourself
STARTORG $1000
MOVE.L #$000186A1,D0MOVE.L #$0000000C,D1DIVU D1,D0
END START
![Page 114: M68k Arithmetic Instructions](https://reader031.vdocument.in/reader031/viewer/2022012922/56813595550346895d9d0740/html5/thumbnails/114.jpg)
DIVU Example - OverflowD0 = $00186A1 (100,001 decimal)
D1 = $0000001 (1 decimal)
DIVU D1,D0
100,001 / 1 = 100,001 = $186A1
Decimal 100,001 0
Quotient Remainder
Hex $186A1 $0000
8 A6 1New D0 = 0 0 0 1
X = unchangedN = 0 (MSB is 0)Z = 0 (result nonzero)V = 1 (divide overflow)C = always clearedQuotient overflowed to remainder.
![Page 115: M68k Arithmetic Instructions](https://reader031.vdocument.in/reader031/viewer/2022012922/56813595550346895d9d0740/html5/thumbnails/115.jpg)
Try It Yourself
STARTORG $1000
MOVE.L #$000186A1,D0MOVE.L #$00000001,D1DIVU D1,D0
END START
![Page 116: M68k Arithmetic Instructions](https://reader031.vdocument.in/reader031/viewer/2022012922/56813595550346895d9d0740/html5/thumbnails/116.jpg)
DIVS (Divide Signed)
Divides 32-bit signed number by 16-bit signed number.
Division method same as DIVU. Destination MUST be Dn. Effects CCR similar to DIVU.
![Page 117: M68k Arithmetic Instructions](https://reader031.vdocument.in/reader031/viewer/2022012922/56813595550346895d9d0740/html5/thumbnails/117.jpg)
DIVS
Dn An (An) (An)+ -(An) d(An) d(An,i) ASA ALA d(PC) d(PC,i) #n
s - s s s s s s s s s s
d - - - - - - - - - - -
N Z V CX
* * * 0-L ÷ W
![Page 118: M68k Arithmetic Instructions](https://reader031.vdocument.in/reader031/viewer/2022012922/56813595550346895d9d0740/html5/thumbnails/118.jpg)
DIVS Example
D0 = #$00001389 (5,001)D1 = #$0000FFE7 (-25)
5,001 / (-25) = -200, remainder 1DIVS D1,D0
Decimal -200 1
Quotient Remainder
Hex $FF38 $0001
F 3F 8New D0= 0 0 0 1
X = unchangedN = 1 (Q MSB is 1)Z = 0 (Q result nonzero)V = 0 (no overflow) C = always cleared
![Page 119: M68k Arithmetic Instructions](https://reader031.vdocument.in/reader031/viewer/2022012922/56813595550346895d9d0740/html5/thumbnails/119.jpg)
Try It Yourself
STARTORG $1000
MOVE.L #$00001389,D0MOVE.L #$0000FFE7,D1DIVS D1,D0
END START
![Page 120: M68k Arithmetic Instructions](https://reader031.vdocument.in/reader031/viewer/2022012922/56813595550346895d9d0740/html5/thumbnails/120.jpg)
Test Instructions
![Page 121: M68k Arithmetic Instructions](https://reader031.vdocument.in/reader031/viewer/2022012922/56813595550346895d9d0740/html5/thumbnails/121.jpg)
TST (Test Operand)
Allows CCR to be updated based on current destination value: Compares destination to zero. Similar to CMP.s #0,<destination>
Destination not effected: Only changes CCR.
Can use BWL. Effects all CCR except X.
![Page 122: M68k Arithmetic Instructions](https://reader031.vdocument.in/reader031/viewer/2022012922/56813595550346895d9d0740/html5/thumbnails/122.jpg)
TST
Dn An (An) (An)+ -(An) d(An) d(An,i) ASA ALA d(PC) d(PC,i) #n
d - d d d d d d d - - -
N Z V CX
* * 0 0-BWL
![Page 123: M68k Arithmetic Instructions](https://reader031.vdocument.in/reader031/viewer/2022012922/56813595550346895d9d0740/html5/thumbnails/123.jpg)
TST Example
8F 2 3 4 5 6 7D3 =
TST.L D3
D3.L = $F2345678- $00000000
$F2345678
8F 2 3 4 5 6 7Final D3 = X = unchangedN = 1 (MSB is 1)Z = 0 (data nonzero)V = always clearedC = always cleared
*D3 unchanged, CCR updated.
(TST.L D3 = CMP.L #0,D3)
![Page 124: M68k Arithmetic Instructions](https://reader031.vdocument.in/reader031/viewer/2022012922/56813595550346895d9d0740/html5/thumbnails/124.jpg)
Try It Yourself
STARTORG $1000
MOVE.L #$F2345678,D3
TST.L D3
END START
![Page 125: M68k Arithmetic Instructions](https://reader031.vdocument.in/reader031/viewer/2022012922/56813595550346895d9d0740/html5/thumbnails/125.jpg)
TAS (Test & Set Operand)
Similar to TST, but only tests 1 byte:Tests byte and sets CCR.Then set MSB to 1.
Can only use B. Effects all CCR except X.
![Page 126: M68k Arithmetic Instructions](https://reader031.vdocument.in/reader031/viewer/2022012922/56813595550346895d9d0740/html5/thumbnails/126.jpg)
TAS
Dn An (An) (An)+ -(An) d(An) d(An,i) ASA ALA d(PC) d(PC,i) #n
d - d d d d d d d - - -
N Z V CX
* * 0 0-B
![Page 127: M68k Arithmetic Instructions](https://reader031.vdocument.in/reader031/viewer/2022012922/56813595550346895d9d0740/html5/thumbnails/127.jpg)
TAS Example
8F 2 3 4 5 6 7D3 =
TAS D3
D3.B = $78- $00
$78
Only byte tested
8F 2 3 4 5 6 FFinal D3 =
01 1 1 1 1 0 0D3.B =
After testing, bit 7 is set.
F 8
X = unchangedN = 0 (MSB is 0)Z = 0 (result non-zero)V = always cleared.C = always cleared.
1
2
![Page 128: M68k Arithmetic Instructions](https://reader031.vdocument.in/reader031/viewer/2022012922/56813595550346895d9d0740/html5/thumbnails/128.jpg)
Try It Yourself
STARTORG $1000
MOVE.L #$F2345678,D3
TAS D3
END START
![Page 129: M68k Arithmetic Instructions](https://reader031.vdocument.in/reader031/viewer/2022012922/56813595550346895d9d0740/html5/thumbnails/129.jpg)
Other Instructions
![Page 130: M68k Arithmetic Instructions](https://reader031.vdocument.in/reader031/viewer/2022012922/56813595550346895d9d0740/html5/thumbnails/130.jpg)
NEG (Negate)
Converts value to opposite sign:Negative PositivePositive Negative0 – D = D
2’s Complement representation. Can use BWL. Effects all CCR.
![Page 131: M68k Arithmetic Instructions](https://reader031.vdocument.in/reader031/viewer/2022012922/56813595550346895d9d0740/html5/thumbnails/131.jpg)
NEG
Dn An (An) (An)+ -(An) d(An) d(An,i) ASA ALA d(PC) d(PC,i) #n
d - d d d d d d d - - -
N Z V CX
* * * 1*BWL
![Page 132: M68k Arithmetic Instructions](https://reader031.vdocument.in/reader031/viewer/2022012922/56813595550346895d9d0740/html5/thumbnails/132.jpg)
NEG ExampleFind the 2’s Complement value of -10 when D0 is loaded with 10.
D0 = $0000000ANEG.B D0
0 0 0 0 0 0 0 A- D0 =
X = CN = 1 (MSB is 1)Z = 0 (result is nonzero)V = 0 (P – P = N)C = 1 (borrow occurred).
0 0 0 0 0 0 F 6D0 =
0 0 0 0 0 0 0 000 = 0
-10
-10
C is always 1 since the operation always requires a carry operation.
![Page 133: M68k Arithmetic Instructions](https://reader031.vdocument.in/reader031/viewer/2022012922/56813595550346895d9d0740/html5/thumbnails/133.jpg)
Try It Yourself
STARTORG $1000
MOVE.B #10,D0
NEG.B D0
END START
![Page 134: M68k Arithmetic Instructions](https://reader031.vdocument.in/reader031/viewer/2022012922/56813595550346895d9d0740/html5/thumbnails/134.jpg)
What if we negate again?D0 = $000000F6NEG.B D0
0 0 0 0 0 0 F 6- D0 =
X = CN = 0 (MSB is 0)Z = 0 (result is nonzero)V = 0 (P – N = P)C = 1 (borrow occurred).
0 0 0 0 0 0 0 AD0 =
0 0 0 0 0 0 0 000 = 0
-(-10)
+10
![Page 135: M68k Arithmetic Instructions](https://reader031.vdocument.in/reader031/viewer/2022012922/56813595550346895d9d0740/html5/thumbnails/135.jpg)
Try It Yourself
STARTORG $1000
MOVE.B #10,D0NEG.B D0NEG.B D0
END START
![Page 136: M68k Arithmetic Instructions](https://reader031.vdocument.in/reader031/viewer/2022012922/56813595550346895d9d0740/html5/thumbnails/136.jpg)
NEGX (Negate with Extend)
Same as NEG, but subtracts X as well:0 – D – X = D
2’s Complement representation. Can use BWL. Effects all CCR.
![Page 137: M68k Arithmetic Instructions](https://reader031.vdocument.in/reader031/viewer/2022012922/56813595550346895d9d0740/html5/thumbnails/137.jpg)
NEGX
Dn An (An) (An)+ -(An) d(An) d(An,i) ASA ALA d(PC) d(PC,i) #n
d - d d d d d d d - - -
N Z V CX
* * * **BWL
![Page 138: M68k Arithmetic Instructions](https://reader031.vdocument.in/reader031/viewer/2022012922/56813595550346895d9d0740/html5/thumbnails/138.jpg)
NEGX ExampleD0 = $00000011X = 1NEGX.B D0
0 0 0 0 0 0 1 1- D0 =
X = CN = 1 (MSB is 1)Z = 0 (result is nonzero)V = 0 (P – P = N)C = 1 (borrow occurred).
0 0 0 0 0 0 E ED0 =
0 0 0 0 0 0 0 000 = 0
-17
-18
0 1- X = -1
![Page 139: M68k Arithmetic Instructions](https://reader031.vdocument.in/reader031/viewer/2022012922/56813595550346895d9d0740/html5/thumbnails/139.jpg)
Try It Yourself
START ORG $1000
MOVE.B #$11,D0AND.B #$00,CCROR.B #$10,CCRNEGX.B D0
END START
![Page 140: M68k Arithmetic Instructions](https://reader031.vdocument.in/reader031/viewer/2022012922/56813595550346895d9d0740/html5/thumbnails/140.jpg)
EXT (Sign Extend)
Extends sign to remaining upper register bits.
Can use WL only. Checks MSB (sign bit) and extends sign:
If .W used, extended to 16-bits. If .L used, extended to 32-bits.
Effects all CCR except X.
![Page 141: M68k Arithmetic Instructions](https://reader031.vdocument.in/reader031/viewer/2022012922/56813595550346895d9d0740/html5/thumbnails/141.jpg)
EXT
Dn An (An) (An)+ -(An) d(An) d(An,i) ASA ALA d(PC) d(PC,i) #n
d - - - - - - - - - - -
N Z V CX
* * 0 0-WL
![Page 142: M68k Arithmetic Instructions](https://reader031.vdocument.in/reader031/viewer/2022012922/56813595550346895d9d0740/html5/thumbnails/142.jpg)
EXT Example
0 0 0 0 0 0 A AD0 =
EXT.W D0
0 0 0 0 F F A AD0 =
$A = 1010
If .W used, check MSB of byte, then extend to word-length.
MSB is 1
X = unchangedN = 1 (MSB is 1)Z = 0 (result is nonzero)V = always clearedC = always cleared.
![Page 143: M68k Arithmetic Instructions](https://reader031.vdocument.in/reader031/viewer/2022012922/56813595550346895d9d0740/html5/thumbnails/143.jpg)
Try It Yourself
STARTORG $1000
MOVE.B #$AA,D0
EXT.W D0
END START
![Page 144: M68k Arithmetic Instructions](https://reader031.vdocument.in/reader031/viewer/2022012922/56813595550346895d9d0740/html5/thumbnails/144.jpg)
EXT Example
0 0 0 0 0 0 A CD0 =
EXT.L D0
0 0 0 0 0 0 A CD0 =
$0 = 0000
If .L used, check MSB of word, then extend to long-length.
MSB is 0
X = unchangedN = 0 (MSB is 0)Z = 0 (result is nonzero)V = always clearedC = always cleared.
![Page 145: M68k Arithmetic Instructions](https://reader031.vdocument.in/reader031/viewer/2022012922/56813595550346895d9d0740/html5/thumbnails/145.jpg)
Try It Yourself
STARTORG $1000
MOVE.W #$00AC,D0
EXT.L D0
END START
![Page 146: M68k Arithmetic Instructions](https://reader031.vdocument.in/reader031/viewer/2022012922/56813595550346895d9d0740/html5/thumbnails/146.jpg)
Important Note on EXT
If .W is used, EXT checks MSB of byte and extends to word value.
If .L is used EXT checks MSB of word and extends to long value.
![Page 147: M68k Arithmetic Instructions](https://reader031.vdocument.in/reader031/viewer/2022012922/56813595550346895d9d0740/html5/thumbnails/147.jpg)
Conclusion
![Page 148: M68k Arithmetic Instructions](https://reader031.vdocument.in/reader031/viewer/2022012922/56813595550346895d9d0740/html5/thumbnails/148.jpg)
Summary of ADD Instructions
Instruction
ADDA
ADD
ADDI
ADDQ
ADDX
Purpose
Add source to address register
Add together two numbers
Add immediate data to destination
Similar to ADDI, but immediate data 1 8
Add together source, destination and X bit.
Operation
An + S = D
D + S = D
D + <id> = D
D + <id> = D
D + S + X = D
![Page 149: M68k Arithmetic Instructions](https://reader031.vdocument.in/reader031/viewer/2022012922/56813595550346895d9d0740/html5/thumbnails/149.jpg)
Summary of SUB Instructions
Instruction
SUBA
SUB
SUBI
SUBQ
SUBX
Purpose
Subtract source from address register
Subtracts source from destination
Subtract immediate data from destination
Similar to SUBI, but immediate data 1 8
Subtract source and X bit from destination.
Operation
An - S = D
D - S = D
D - <id> = D
D - <id> = D
D - S - X = D
![Page 150: M68k Arithmetic Instructions](https://reader031.vdocument.in/reader031/viewer/2022012922/56813595550346895d9d0740/html5/thumbnails/150.jpg)
Summary of CMP Instructions
Instruction
CMPA
CMP
CMPI
CMPM
Purpose
Compare address register to source. Only updates CCR.
Similar to SUB, but doesn’t modify D. Only updates CCR.
Compare D to immediate data. Only updates CCR.
Compare between 2 memory locations. Only updates CCR.
Operation
An - S = “D”
D - S = “D”
D - <id> = “D”
M1 – M2 = “D”
![Page 151: M68k Arithmetic Instructions](https://reader031.vdocument.in/reader031/viewer/2022012922/56813595550346895d9d0740/html5/thumbnails/151.jpg)
Summary of MUL & DIV Instructions
Instruction
MULS
MULU
DIVU
DIVS
Purpose
Multiplies two signed W data and store in D
Multiples two unsigned W data and store in D
Divides unsigned L data with W data and store in D
Divides signed L data with D data and store in D
Operation
W x W = L
W x W = L
L/W = WQ,WR
L/W = WQ,WR
![Page 152: M68k Arithmetic Instructions](https://reader031.vdocument.in/reader031/viewer/2022012922/56813595550346895d9d0740/html5/thumbnails/152.jpg)
Summary of Instructions
Instruction
TAS
TST
NEG
NEGX
Purpose
Compare DB with zero, update CCR, and set MSB
Compare D to zero, and update CCR
Negates D (2’s complement)
Negates D, then subtract X
Operation
CMP #0,DMSB = 1
CMP #0,D
D = 0 - S
D = 0 – S - X
EXT Sign extends B W, W L N/A
![Page 153: M68k Arithmetic Instructions](https://reader031.vdocument.in/reader031/viewer/2022012922/56813595550346895d9d0740/html5/thumbnails/153.jpg)
The End
Please read:
Antonakos, 69 - 76