programmer's model of any micro processor/controller, is a mental picture of what basic registers are available. A Miniboard programmer should memorize 8 registers: Here is a picture of what the registers look like:
Programmers Model of a 6811

Registers A and B are general purpose 8 bit registers where the programmer may perform manipulations on data. The D register is the combination of A and B and is therefore 16 bits in size, with A being the high order byte and B being the low order byte in D. These registers are known as accumulators because a programmer will most often uses these registers for mathematical manipulations of data.

Registers X and Y are both 16 bit index registers. Certain addressing modes use values in these registers to calculate offsets. We have not talked about addressing modes yet. But you may think of a 6811 programmers task as having to get data from RAM or from special registers into the accumulators, operate on that data, and store the new data back out of RAM or to special registers. In order to tell the 6811 chip what piece of memory you want to get next, you must address it. There are 6 ways to specify an address of memory and these are the addressing modes. One of the 6 ways to indicate an address of interest is called the Indexed Mode, it involves the use of an Index register, and believe me, it is very useful.

The SP register is the Stack Pointer. A stack Pointer is used to point to the top of a stack in RAM. Arguments to subroutines are sometimes passed on the stack, and temporary variables are sometimes stored on the stack. A programmer must take special care to keep the SP managed. When you put information on a stack, you must at some point later remove that information, and alter your stack pointer which must always point to the top of the stack. Some instructions (like push, pop, and bsr) have some auto SP management built into them. At other times the programmer must alter the value of the stack pointer to implement his/her wishes. For example, suppose that at the beginning of a program the initial stack pointer points at the memory location $ff. If you stored the 8 bit value $40 on the stack (i.e.. at memory location $ff) you should then immediately decrement the stack pointer so that it would point to $fe.

Location       Value
    $f6		$00
    $f7		$00
    $f8		$00
    $f9		$00
    $fa		$00
    $fb		$00
    $fc		$00
    $fd		$00
SP->$fe		$00
    $ff		$40
Stack 1

As your program moves on you may want to store several bits of information onto the stack. Some information you wish to store will be 8bit information and some will be 16 bit information. If you next wished to store the 16 bit value $ff16 on to the stack (assuming $ff16 was in the D register) you could store the B register onto the stack, decrement the stack pointer, store the A register onto the stack (recall that the A and B registers constitute the D register), and decrement the stack pointer again (never leave off this last step for discipline sake).

Location       Value
    $f6         $00
    $f7         $00
    $f8         $00
    $f9         $00
    $fa         $00
    $fb         $00
SP->$fc         $00
    $fd         $ff
    $fe         $16
    $ff         $40
Stack 2

The push command (mnemonic is PSHA for push register A to the stack) will automatically decrement the stack pointer for you. If you now had $70 in the A register and told the 6811 to Push A, then the value in the A register would be placed on the stack and the stack pointer would be auto-decremented.

Location       Value
    $f6         $00
    $f7         $00
    $f8         $00
    $f9         $00
    $fa         $00
SP->$fb         $00
    $fc         $70
    $fd         $ff
    $fe         $16
    $ff         $40
Stack 3

Once you are through manipulating temporary variables and no longer need to store them, you should restore the stack pointer. A pop instruction will move either 8 bits of data from the stack into the A or B register or 16 bits of data into the X or Y register and will Auto increment the Stack Pointer by 1 or 2 accordingly. If you are done with your variables and do not need to restore the information to a register (the info is trash now) you can simply add directly to the stack pointer and forget about the information left there. The important thing is that you manage the Stack Pointer, not necessarily zero out the information on the stack. So from our above example, if we were ready to trash all the temporary variables that we had stored on the stack, we could add 4 to the SP and have a clean stack.

Location       Value
    $f6         $00
    $f7         $00
    $f8         $00
    $f9         $00
    $fa         $00
    $fb         $00
    $fc         $70
    $fd         $ff
    $fe         $16
SP->$ff         $40
Stack 4

The PC register is the Program Counter. A program counter always points to the next instruction to be executed. It may not always point to the next instruction you wish would execute but what ever it points to will be the next thing that the 6811 attempts to interpret as an instruction and attempts to execute. A programmer is never to attempt to alter the PC, instead the 6811 keeps track of what instruction should execute next. The 6811 will figure out how to follow branches, subroutine calls, jumps, interrupts, and simple sequences of instructions and will automatically update the PC. During debugging, you may find that your PC gets "lost". At those times you must find out what you the programmer did wrong to generate an erroneous PC. During a subroutine call, the value of the PC gets automatically pushed onto the stack. At the end of a subroutine, the Return from Subroutine statement is encountered as a value from the stack is popped and placed into the PC so that your program may continue to execute where is left off, before the call to a subroutine. This means of course that during the execution of a sub routine, any values that the programmer places on the stack, he/she must remove them before completion of the subroutine or the PC will get lost.

The CCR is the Conditions Code register. Every time you perform a mathematical operation in an accumulator, the Condition Codes are altered. The carry bit is set if the Arithmetic Logic Unit has just performed a carry or a borrow. The V bit (overflow) is set if the ALU just performed an overflow. If the result of the last ALU operation was zero, then the Z bit is set. The N bit is set if the last ALU result was negative (that is, the high order bit is a one). Any time an interrupt service routine is in execution, the I bit is automatically set. This means that the MCU can no longer be interrupted until this bit is clear. A programmer may also set the I bit if he/she does not want to be interrupted. The X bit is the same as the I bit but is for interrupts arriving on the 6811 XIRQ pin. On the Miniboard this means the IRQ push button. Setting the S bit will halt the MCU and only a reset or power cycle will start it up again.

ieeecs@hal.elee.calpoly.edu
BackBack to Table of Contents