Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
8xC196EA microcontroller user's manual.1998.pdf
Скачиваний:
52
Добавлен:
23.08.2013
Размер:
8.29 Mб
Скачать

CHAPTER 3

PROGRAMMING CONSIDERATIONS

This section provides an overview of the instruction set of the MCS® 96 microcontrollers and offers guidelines for program development. For detailed information about specific instructions, see Appendix A.

3.1OVERVIEW OF THE INSTRUCTION SET

The instruction set supports a variety of data types likely to be useful in control applications (see Table 3-1).

NOTE

The data-type variables are shown in all capitals to avoid confusion. For example, a BYTE is an unsigned 8-bit variable in an instruction, while a byte is any 8-bit unit of data (either signed or unsigned).

Table 3-1. Data Type Definitions

Data Type

No. of

Signed

Possible Values

Addressing

Bits

Restrictions

 

 

 

 

 

 

 

 

BIT

1

No

True (1) or False (0)

As components of bytes

 

 

 

 

 

BYTE

8

No

0 through 28–1 (0 through 255)

None

SHORT-INTEGER

8

Yes

–27 through +27–1

None

 

 

 

(–128 through +127)

 

 

 

 

 

 

WORD

16

No

0 through 216–1

Even byte address

 

 

 

(0 through 65,535)

 

 

 

 

 

 

INTEGER

16

Yes

–215 through +215–1

Even byte address

 

 

 

(–32,768 through +32,767)

 

 

 

 

 

 

DOUBLE-WORD

32

No

0 through 232–1

An address in the lower

(Note 1)

 

 

(0 through 4,294,967,295)

register file that is evenly

 

 

 

 

divisible by four

 

 

 

 

 

LONG-INTEGER

32

Yes

–231 through +231–1

An address in the lower

(Note 1)

 

 

(–2,147,483,648 through

register file that is evenly

 

 

 

+2,147,483,647)

divisible by four

 

 

 

 

 

QUAD-WORD

64

No

0 through 264–1

An address in the lower

(Note 2)

 

 

 

register file that is evenly

 

 

 

 

divisible by eight

 

 

 

 

 

NOTES:

1.The 32-bit operands are supported only in shift operations, as the dividend in 32-by-16 division, and as the product of 16-by-16 multiplication.

2.QUAD-WORD variables are supported only as the operand for the EBMOVI instruction.

3-1

8XC196EA USER’S MANUAL

Table 3-2 lists the equivalent data-type names for both C programming and assembly language.

Table 3-2. Equivalent Data Types for Assembly and C Programming Languages

Data Type

Assembly Language Equivalent

C Programming Language Equivalent

 

 

 

BYTE

BYTE

unsigned char

 

 

 

SHORT-INTEGER

BYTE

char

 

 

 

WORD

WORD

unsigned int

 

 

 

INTEGER

WORD

int

 

 

 

DOUBLE-WORD

LONG

unsigned long

 

 

 

LONG-INTEGER

LONG

long

 

 

 

QUAD-WORD

 

 

 

3.1.1BIT Operands

A BIT is a single-bit variable that can have the Boolean values, “true” and “false.” The architecture requires that BITs be addressed as components of BYTEs or WORDs. The architecture does not support the direct addressing of BITs. (You can, however, test the state of a single bit. For example, the JBC and JBS instructions are conditional jump instructions that test a specified bit.)

3.1.2BYTE Operands

A BYTE is an unsigned, 8-bit variable that can take on values from 0 through 255 (28–1). Arithmetic and relational operators can be applied to BYTE operands, but the result must be interpreted in modulo 256 arithmetic. Logical operations on BYTEs are applied bitwise. Bits within BYTEs are labeled from 0 to 7; bit 0 is the least-significant bit. Alignment restrictions do not apply to BYTEs, so they may be placed anywhere in the address space.

3.1.3SHORT-INTEGER Operands

A SHORT-INTEGER is an 8-bit, signed variable that can take on values from –128 (–2 7) through +127 (+27–1). Arithmetic operations that generate results outside the range of a SHORTINTEGER set the overflow flags in the processor status word (PSW). The numeric result is the same as the result of the equivalent operation on BYTE variables. There are no alignment restrictions on SHORT-INTEGERs, so they may be placed anywhere in the address space.

3-2

PROGRAMMING CONSIDERATIONS

3.1.4WORD Operands

A WORD is an unsigned, 16-bit variable that can take on values from 0 through 65,535 (216–1). Arithmetic and relational operators can be applied to WORD operands, but the result must be interpreted in modulo 65536 arithmetic. Logical operations on WORDs are applied bitwise. Bits within WORDs are labeled from 0 to 15; bit 0 is the least-significant bit.

WORDs must be aligned at even byte boundaries in the address space. The least-significant byte of the WORD is in the even byte address, and the most-significant byte is in the next higher (odd) address. The address of a WORD is that of its least-significant byte (the even byte address). WORD operations to odd addresses are not guaranteed to operate in a consistent manner.

3.1.5INTEGER Operands

An INTEGER is a 16-bit, signed variable that can take on values from –32,768 (–2 15) through +32,767 (+215–1). Arithmetic operations that generate results outside the range of an INTEGER set the overflow flags in the processor status word (PSW). The numeric result is the same as the result of the equivalent operation on WORD variables.

INTEGERs must be aligned at even byte boundaries in the address space. The least-significant byte of the INTEGER is in the even byte address, and the most-significant byte is in the next higher (odd) address. The address of an INTEGER is that of its least-significant byte (the even byte address). INTEGER operations to odd addresses are not guaranteed to operate in a consistent manner.

3.1.6DOUBLE-WORD Operands

A DOUBLE-WORD is an unsigned, 32-bit variable that can take on values from 0 through 4,294,967,295 (232–1). The architecture directly supports DOUBLE-WORD operands only as the operand in shift operations, as the dividend in 32-by-16 divide operations, and as the product of 16-by-16 multiply operations. For these operations, a DOUBLE-WORD variable must reside in the lower register file and must be aligned at an address that is evenly divisible by four. The address of a DOUBLE-WORD is that of its least-significant byte (the even byte address). The least-significant word of the DOUBLE-WORD is always in the lower address, even when the data is in the stack. This means that the most-significant word must be pushed onto the stack first.

DOUBLE-WORD operations that are not directly supported can be easily implemented with two WORD operations. For example, the following sequences of 16-bit operations perform a 32-bit addition and a 32-bit subtraction, respectively.

ADD

REG1,REG3

;

(2-operand

addition)

ADDC

REG2,REG4

 

 

 

SUB

REG1,REG3

;

(2-operand

subtraction)

SUBC REG2,REG4

3-3

8XC196EA USER’S MANUAL

3.1.7LONG-INTEGER Operands

A LONG-INTEGER is a 32-bit, signed variable that can take on values from –2,147,483,648 (–2 31) through +2,147,483,647 (+231–1). The architecture directly supports LONG-INTEGER operands only as the operand in shift operations, as the dividend in 32-by-16 divide operations, and as the product of 16-by-16 multiply operations. For these operations, a LONG-INTEGER variable must reside in the lower register file and must be aligned at an address that is evenly divisible by four. The address of a LONG-INTEGER is that of its least-significant byte (the even byte address).

LONG-INTEGER operations that are not directly supported can be easily implemented with two INTEGER operations. See the example in “DOUBLE-WORD Operands” on page 3-3.

3.1.8QUAD-WORD Operands

A QUAD-WORD is a 64-bit, unsigned variable that can take on values from 0 through 264–1. The architecture directly supports the QUAD-WORD operand only as the operand of the EBMOVI instruction. For this operation, the QUAD-WORD variable must reside in the lower register file and must be aligned at an address that is evenly divisible by eight.

3.1.9Converting Operands

The instruction set supports conversions between the data types (Table 3-3). The LDBZE (load byte, zero extended) instruction converts a BYTE to a WORD. CLR (clear) converts a WORD to a DOUBLE-WORD by clearing (writing zeros to) the upper WORD of the DOUBLE-WORD. LDBSE (load byte, sign extended) converts a SHORT-INTEGER into an INTEGER. EXT (sign extend) converts an INTEGER to a LONG-INTEGER.

Table 3-3. Converting Data Types

To convert

to

Use this

Which performs this function

from …

instruction…

 

 

 

 

 

 

BYTE

WORD

LDBZE

Writes zeros to the upper byte.

WORD

DOUBLE-WORD

CLR

Writes zeros to the upper word.

SHORT-INTEGER

INTEGER

LDBSE

Writes the sign bit to the upper byte.

INTEGER

LONG-INTEGER

EXT

Writes the sign bit to the upper word.

3-4

Соседние файлы в предмете Электротехника