CS255 Syllabus

 The add instruction of the M68000 CPU uses the 2's complement code The add instruction will add 2 bit (binary number) patterns using the rules of the 2's complement code (that we have studied before)

Example of 2's complement code addtition:

 ``` 11111111 (= -110) + 00000010 (= 210) ------------ 00000001 (= 110) ```

• There are 2 add operations in M68000:

1. Add operation that uses a data register as destination register

 The destination of an operation is used to store to result of the operation So the result of the addition in this case is stored in a data register

The nmemonic for this add operation is:

 ``` ADD ```

 The destination of an operation is used to store to result of the operation So the result of the addition in this case is stored in an address register

The nmemonic for this add operation is:

 ``` ADDA (The trailing A stands for Address register) ```

• ADD: add operation that uses a data register as destination register

• There are 3 instruction that add into a data register:

 ``` 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:

• The add instruction using a data register as destination register will use the specified data type in the operation

• In other words:

 ``` ADD.B D0, D1 will: add the byte operands in D0 and D1 and store the byte result in D1 ADD.W D0, D1 will: add the short (= word) operands in D0 and D1 and store the short result in D1 ADD.L D0, D1 will: add the int (= long word) operands in D0 and D1 and store the int result in D1 ```

• The Src operand can be one of the following:

1. A integer cosntant

Example:

 ``` ADD.W #2, D0 or: ADD.W #k, D0 ```

2. A integer value stored in a (data) register

Example:

 ``` ADD.W D1, D0 ```

3. A integer value stored in a (RAM) memory

Example:

 ``` ADD.W 2, D0 or: ADD.W k, D0 ```

Important:

 You must use your knowledge on the address mode (that you have learned previously) to obtain the operand !!!

• Example of the ADD instruction using constant operands

• Example of ADD instruction using constants:

• Example of the ADD instruction using operands in data registers

• Example of ADD instruction using values in a data register:

• Example of the ADD instruction using operands in RAM memory

• Recall how integer (= whole number) values are stored in (RAM) memory:

• Recall also the order in which the bytes are stored:

• Example 1: adding a short typed value using the different add instructions

• Suppose we define a short typed variable x as follows:

 ``` x: dc.w 2 * A short variable containing the value 2 ```

• The memory will contain the following short representation:

• How ADD.B work on a short typed memory variable:

Comment:

 ADD.B used on a short typed variable did not perform correctly !!! (This is a bug !!!)

• How ADD.W work on a short typed memory variable:

Comment:

 ADD.W used on a short typed variable works correctly !!! (We added 2 to -1 and obtained 1 as answer --- use only 16 bits in D0 in your interpretation !!!)

• How ADD.L work on a short typed memory variable:

Comment:

 ADD.L used on a short typed variable did not perform correctly !!! (This is also a bug !!!)

• Example 2: adding a int typed value using the different add instructions

• Suppose we define a int typed variable x as follows:

 ``` x: dc.l 2 * A short variable containing the value 2 ```

• The memory will contain the following short representation:

• How ADD.B work on a int typed memory variable:

Comment:

 ADD.B used on a int typed variable did not perform correctly !!! (This is a bug !!!)

• How ADD.W work on a int typed memory variable:

Comment:

 ADD.B used on a int typed variable did not perform correctly !!! (This is a bug !!!)

• How ADD.L work on a int typed memory variable:

Comment:

 ADD.L used on a int typed variable works correctly !!! (We added 2 to -1 and obtained 1 as answer --- we must use all 32 bits in D0 in your interpretation !!!)

• M68000 has another ADD instruction with the following syntax:

 ``` 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 ```

• Comment:

 The ADD Dn, Dst instruction is similar to the ADD Src, Dn instruction The difference is the M68000 CPU will store the result in the Dst operand (instead of storing the result in the data register Dn)

• Fact:

 When the destination of the add instruction is an address register, the instruction nmemonic gets an a appended to the tail When the destination is an address register, you can only use word size and long word size instructions

 ``` 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) ```

• How the ADDA instruction work:

• Fact:

• An address in M68000 is always a 32 bit binary number

Therefore:

• An operation using an address register as destination will:

 Always be performed in 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 2. ADDA.L Sec, An * Add the int (32 bit) Src to the address reg An * I.e.: An = An + Src(32 bits) (We don't need to perform conversion, because the Src is an int) (We just add the int Src value to the address reg An) ```

• Example 1: the execution of ADDA.W with a (short) constant

• Suppose the address register A0 contains the following:

• ADD.W #2, A0 is executed as follows:

Note:

• Compare this to the ADD.W #2, D0 operation using a data register with the same value (= 11111111 11111111 11111111 11111111):

Notice that the ADD.W operation produces a short typed (16 bits representation) result

The ADDA.W operation always produces a int typed (32 bits representation) result

• Example 2: the execution of ADDA.W with a (short) value in a data register

• Suppose the registers A0 and D1 contains the following:

• ADD.W D0, A0 is executed as follows: