|
Example of 2's complement code addtition:
11111111 (= -110)
+ 00000010 (= 210)
------------
00000001 (= 110)
|
|
1. ADD.B Src, Dn // Add the 8 bits 2's complement values in Dn + Src
// and store the 8 bits sum in Dn
2. ADD.W Src, Dn // Add the 16 bits 2's complement values in Dn + Src
// and store the 16 bits sum in Dn
3. ADD.L Src, Dn // Add the 32 bits 2's complement values in Dn + Src
// and store the 32 bits sum in Dn
|
Effect:
|
|
Important:
|
|
|
|
|
|
|
1. ADD.B Dn, Dst // Add the 8 bits 2's complement values in Dn + Dst
// and store the 8 bits sum in destination Dst
2. ADD.W Dn, Dst // Add the 16 bits 2's complement values in Dn + Dst
// and store the 16 bits sum in destination Dst
3. ADD.L Dn, Dst // Add the 32 bits 2's complement values in Dn + Dst
// and store the 32 bits sum in destination Dst
|
|
|
|
|
Example:
add.w d0, d1 is same as: ADD.W D0, D1
|
|
Example:
Correct use of labels:
add.l x, D0
...
x: ds.l 1
|
|
int x, y, z; (We assumed x,y,z have been defined)
z = x + y;
In assembler code:
move.l x,D0 * Get 32 bits representation of x in D0
move.l y,D1 * Get 32 bits representation of y in D1
add.l D0,D1 * Add the two 32 bits representations together
* The sum is stored in D1
move.l D1,z * Store the 32 bits representation in z
|
short x, y, z; (We assumed x,y,z have been defined)
z = x + y;
In assembler code:
move.w x,D0 * Get 16 bits representation of x in D0
move.w y,D1 * Get 16 bits representation of y in D1
add.w D0,D1 * Add the two 16 bits representations together
* The sum is stored in D1 (16 bits)
move.w D1,z * Store the 16 bits representation in z
|
|
1. ADDA.W Src, An * Add the 16 bit value Src to the address reg An
* I.e.: An = An + Src(16 bits)
2. ADDA.L Sec, An * Add the 32 bit value Src to the address reg An
* I.e.: An = An + Src(32 bits)
|
|
In other words:
1. ADDA.W Src, An * Add the short (16 bit) Src to the address reg An
* I.e.: An = An + Src(16 bits)
is executed as follows:
Step 1: convert the short (16 bit) Src to an int (32 bits)
Step 2: add the (converted) result to address register An
|
SUB.B Src, Dn * Subtract the 8 bits values: Dn = Dn - Src
SUB.W Src, Dn * Subtract the 16 bits values: Dn = Dn - Src
SUB.L Src, Dn * Subtract the 32 bits values: Dn = Dn - Src
|
|
SUBA.W Src, An * Subtract the 16 bits values: An = An - Src
SUBA.L Src, An * Subtract the 32 bits values: An = An - Src
|
|
|
Example:
short B[10; (We assumed array B have been defined)
===> Get the value of B[3] into register D0
In assembler code:
/* =========================================================
We want to access B[3]:
==> put base address in address register
========================================================= */
movea.l #B,A0 * A0 = base address of array B
* An address is 32 bits, so we use .l !!!
/* =========================================================
We put the values B[3] in data register D0
========================================================= */
move.w 6(A0),D0 * Get short (16 bits) variable B[3] into register D0
* We use an address register A0 because the
* indirect addressing mode 6(A0) NEEDS to use
* an address register
* We put the value into a data register D0
* because we want use the value in B[3] in computations !!!
|