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

PROGRAMMING CONSIDERATIONS

3.2.4.4Zero-indexed Addressing

In a zero-indexed instruction, you specify the address as a 16-bit variable; the offset is zero, and you can express it in one of three ways: [0], [ZERO_REG], or nothing. Each of the following load instructions loads AX with the contents of the variable THISVAR.

LD

AX,THISVAR[0]

LD

AX,THISVAR[ZERO_REG]

LD

AX,THISVAR

The following instructions also use zero-indexed addressing:

ADD

AX,1234H[ZERO_REG]

;

AX AX + MEM_WORD(1234H)

POP

5678H[ZERO_REG]

;

MEM_WORD(5678H) MEM_WORD(SP)

;SP SP + 2

3.2.4.5Extended Zero-indexed Addressing

The extended instructions can also use zero-indexed addressing. The only difference is that you specify the address as a 24-bit constant or variable. The following extended instruction uses zeroindexed addressing. ZERO_REG acts as a 32-bit fixed source of the constant zero for an extended indexed reference.

ELD AX,23456H[ZERO_REG]

; AX MEM_WORD(23456H)

3.3CONSIDERATIONS FOR CROSSING PAGE BOUNDARIES

In general, you should avoid creating tables or arrays that cross page boundaries. For example, if you are building a large array, start it at a base address that will accommodate the entire array within the same page. If you cannot avoid crossing a page boundary, keep in mind that you must use extended instructions to access data outside page 00H.

3-11

8XC196EA USER’S MANUAL

3.4SOFTWARE PROTECTION FEATURES AND GUIDELINES

The microcontroller has several features to assist in recovering from hardware and software errors. The unimplemented opcode interrupt provides protection from executing unimplemented opcodes. The hardware reset instruction (RST) can cause a reset if the program counter goes out of bounds. The RST instruction opcode is FFH, so the processor will reset itself if it tries to fetch an instruction from unprogrammed locations in nonvolatile memory or from bus lines that have been pulled high. The watchdog timer (WDT) can also reset the microcontroller in the event of a hardware or software error.

Fill unused areas of code with NOPs and periodic jumps to an error routine or RST instruction. This is particularly important in the code surrounding lookup tables, since accidentally executing from lookup tables will cause undesired results. Wherever space allows, surround each table with seven NOPs (because the longest device instruction has seven bytes) and a RST or a jump to an error routine. Since RST is a one-byte instruction, the NOPs are unnecessary if RSTs are used instead of jumps to an error routine. This will help to ensure a speedy recovery from a software error.

When using the watchdog timer (WDT) for software protection, we recommend that you reset the WDT from only one place in code, reducing the chance of an undesired WDT reset. The section of code that resets the WDT should monitor the other code sections for proper operation. This can be done by checking variables to make sure they are within reasonable values. Simply using a software timer to reset the WDT every 10 milliseconds, for example, will provide protection only for catastrophic failures.

3-12

4

Memory Partitions

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