CS255 Syllabus

### Data Register Operands

• The data registers of M68000

• Recall:

• The M68000 CPU has 8 data registers, named:

 D0, D1, D2, D3, D4, D5, D6, D7, D8

• Each data register contains 32 bits

• Facts:

• Data registers are used to store the operands for computer instructions

• There are many different types of operands:

 byte typed that are 1 byte in size short typed that are 2 bytes in size int typed that are 4 bytes in size And so on...

• Use of data registers

• Use of data registers"

 Data registers can provide source operands of any data type for use computer operations Data registers can be used as destination to store results of any data type produced by computer operations

• Common practice: in assembler programming:

• When you perform calculations of variables (that are stored in memory), you will always:

 Make a copy of the variable in some data register Then perform the operations on the copy in the data register When the computations are done, you must store/save the result in the data register to the variable in memory !!!

Example:

• When you compute:

 ``` x = x + 1; ```

The variable x is stored in memory

• You need to make a copy of x in a data register first

Then add 1 to obtain x + 1 in a data register

You must store the value x + 1 in the data register back to the variable in memory to complete the computation !!!

Warning:

 If you do not store the result back to the variable in memory, you will lose all the computational work that you have done !!!!

• How to use data register for different types of operands

• Didactical comment:

 We will only use (different) integer data types to learn assembler programming (Floating point data types follows a similar logic)

• A data register of M68000 can store 3 different integer type values:

• byte data type:

 A byte typed value in a data register is stored in the right most 8 bits of the data register

• short data type

 A short typed value in a data register is stored in the right most 16 bits of the data register

• int data type

 A int typed value in a data register is stored in the entire (= all 32 bits) of the data register

Graphically:

Example:

 ``` Before executing the MOVE instruction: +----------+----------+----------+----------+ D0: | 10101010 | 00001111 | 11110000 | 01010101 | +----------+----------+----------+----------+ +----------+----------+----------+----------+ D1: | 11111111 | 11111111 | 11111111 | 11111111 | +----------+----------+----------+----------+ After executing MOVE.B D0, D1: +----------+----------+----------+----------+ D0: | 10101010 | 00001111 | 11110000 | 01010101 | +----------+----------+----------+----------+ +----------+----------+----------+----------+ D1: | 11111111 | 11111111 | 11111111 | 01010101 | +----------+----------+----------+----------+ The byte operand in D0 is copied into the byte operand location of D1 !!! After executing MOVE.W D0, D1: +----------+----------+----------+----------+ D0: | 10101010 | 00001111 | 11110000 | 01010101 | +----------+----------+----------+----------+ +----------+----------+----------+----------+ D1: | 11111111 | 11111111 | 11110000 | 01010101 | +----------+----------+----------+----------+ The word operand in D0 is copied into the word operand location of D1 !!! After executing MOVE.L D0, D1: +----------+----------+----------+----------+ D0: | 10101010 | 00001111 | 11110000 | 01010101 | +----------+----------+----------+----------+ +----------+----------+----------+----------+ D1: | 10101010 | 00001111 | 11110000 | 01010101 | +----------+----------+----------+----------+ The long word operand in D0 is copied into the long word operand location of D1 !!! ```