Back Home

Navigation

Home

Cross-Overlays

Overview
Introduction
Programming Model
System Vectors
Reserved Words
Special Features
Initialization
Extra Directive
Differences

This page has not been adapted to SB-Assembler Version 3 yet.

6809 Cross Overlay Overview
Cross name:6809.sba
Current version:2.00
Models supported:6809
Manufacturers:Motorola (now Freescale), Hitachi
Data format:Big endian model
Directives:One extra directives (.DP)
Instructions:Many extra instructions for compatibility reasons with 6800.
Introduction

The Motorola 6809 processor is a very powerful successor of the 6800. Not only does it have more registers, like an extra index register and a user definable stack pointer, but some very powerful addressing modes were added as well. The direct page addressing mode is changed in a way that the direct page can now be located in any memory page you like.
JMP and JSR instructions are now accompanied by LBRA and LBSR instructions, which enable you to write fully relocatable programs. This becomes possible because all jumps and subroutine calls can now be made relative.

Programming Model

The programming model in the picture below shows the most important registers of the 6809 processor. I only include a little summary about the features of the 6809's programming model here. It is not my intention to make the original documentation obsolete, so please refer to the original documentation for further details.

6809 programming model

The 6809 has a very powerful addressing mode called direct page addressing. This way all 256 bytes of any page in memory can be addressed with only 8 bits. These 256 addresses can be considered the "registers" of the 6809!

The Accumulators A and B

The 6809 is equipped with two 8-bit accumulators. Both Accumulators are technically the same and can both be used for a variety of arithmetic operations.
Both Accumulators can be concatenated to form a 16-bit accumulator, called D. Accumulator A becomes the most significant byte of the double accumulator.

The Condition Code Register

The CC register holds all the system flags. Most flags reflect the status of the machine after mathematical or logical instructions. Other flags are set or cleared under program control.

The CC register contains 8 system flags:

EEntire flag
FFIRQ mask flag
HHalf Carry flag
IIRQ mask flag
NNegative sign flag
ZZero flag
VOverflow flag
CCarry Flag

IRQ interrupts are disabled when the I bit is set.
FIRQ interrupts are disabled when the F bit is set.
When the E bit is set all internal registers were pushed on the stack, as opposed to only PC and CC in case of a FIRQ. The stacked E bit is used by the RTI instruction to determine what is to be pulled from the stack.

The Index registers IX and IY

Both index registers can be used to indirectly point to data in many different ways. The IX and IY registers are identical to each other.
Using index registers as data pointers almost always involves incrementing or decrementing the index register after or before data fetching. Therefore the 6809 allows auto increment or decrement together with indexed addressing modes.

Please refer to the 6809 opcode test file for all possible indexed notations understood by the SB-Assembler.

The Stack Pointers SP and U

The 6809 is equipped with 2 stack pointers. SP is the system stack pointer and is always used to save return addresses during subroutine and interrupt calls. The system stack may also be used for other purposes, exactly like most other microprocessors.
The user stack pointer U is somewhat special. It can be used to push data onto and pull data from it, just like the system stack. However it can never be used to store subroutine or interrupt return addresses.
As a bonus both stack pointers can be used as extra index registers having the same capabilities as the IX and IY registers.

Both stack pointers are 16-bits wide, so the stacks can be located anywhere in RAM memory. Both stacks grow down in memory when data is pushed to them.

There is a large difference between the stack pointers of the 6809 and the stack pointer of the 6800. On the 6800 the stack pointer always points to the first available stack location. But on the 6809 the stack pointer points to the top of the stack.
This means that the stack pointer points to last byte that was saved (if there was one).
Pushing a byte to the stack on a 6809 is done by decrementing the stack pointer first and then the data is stored at the location pointed to by the stack pointer in use.

Words are pushed with their LSB first. Subroutine calls and interrupts push the return address on the stack. This is the address of the instruction that has to be executed when the subroutine or interrupt is completed.

NMI, IRQ and SWI Interrupts save all registers on the stack. The order in which all data is pushed is shown below:

PCL, PCH, UL, UH, YL, YH, XL, XH, DP, B, A, CC

It goes without saying that the pull order is just the other way around!

FIRQ interrupts have higher priority than IRQ interrupts and are called "fast" because only the PC and CC are pushed on the stack. It's the programmer's responsibility to save and restore all other affected registers. The push order for FIRQ is: PCL, PCH, CC.

The Program Counter

The program counter PC is normally incremented after fetching each instruction or operand byte during program execution. The only way you can change this behaviour is with the jump, subroutine and return instructions. Also interrupts can change the program counter's value.

System Vectors

System Vectors don't have anything to do with the SB-Assembler in particular, but I've included them here anyway for easy reference.

$FFF0Reserved
$FFF2SWI3
$FFF4SWI2
$FFF6FIRQ
$FFF8IRQ
$FFFASWI
$FFFCNMI
$FFFEReset
Reserved Words

The SB-Assembler 6809 cross overlay has a few reserved words. All reserved words are register names. It is not very likely though that you will run into trouble if you use any of the reserved words as label names. But it is always better to be safe than sorry, so why use them when you have so many alternatives to choose from.

The reserved words are:

A, B, CC, DP, X, Y, U, S, PC, PCR.

Special Features

Stack operation

The 6809 has two stack pointers. One is the system stack (S), used to save return addresses and other data. The other one is a user stack (U), which can be used for any purpose, except for storing return addresses.

The 6809 can push or pull all its registers to or from either one of the stacks with just one instruction. The PSHS, PSHU, PULS, or PULU instructions should be followed by a register list, indicating what registers should be pushed or pulled. The order in which the registers are pushed to the stack is fixed, like shown below:

PC, U/S, Y, X, DP, B, A, CC

The SB-Assembler doesn't care in what order you enter the registers to be pushed or pulled. It's the 6809 that automatically uses the pushing order shown above. Only the registers that are mentioned in the parameter list of the PSH or PUL instruction are really saved or restored. You may duplicate particular registers in your list without any error messages from the SB-Assembler. But each register will only be pushed or pulled once per instruction! So don't use PSHS A,A to push the Accumulator A to the stack twice because A will be pushed only once.
All 16-bit registers are pushed to the stack with their low byte first.
The second register in the list above is U/S. This means that you can either save U or S to the stack. You can save U to the system stack, or S to the user stack. It's no use to save U to the user stack, or S to the system stack.

It goes without saying that the pull order is exactly the reverse order of the push order.

Indexed addressing modes

The official notation of the indexed addressing mode is offset,X, where offset can be up to a 16-bit signed offset value. However usually the offset value is $00 and that can be written in two different ways in the SB-Assembler:

         LDA    $00,X
         LDA    ,X

Both instructions have the same effect and use an offset value of $00.
The SB-Assembler will automatically select the appropriate indexing mode, using no offset, 5-bit signed offset, 8-bit signed offset, or 16-bit signed offset values.

Forced direct page and extended addressing modes

One of the strongest features of the 6809 is its direct page addressing mode. Direct page addressing mode is also called zero page addressing mode on other microprocessors because they always uses the first 256 bytes of memory space. The 6809 takes this concept even further and allows the direct page to be in any specific memory page by storing the page number in the DP register.
With direct addressing mode you specify a memory location that can be addressed with only one byte (instead of 2 for all other memory locations). This way the 6809 can be seen as a microprocessor with 256 sets of 256 registers each.

The SB-Assembler automatically selects direct addressing mode when that mode is available and the high byte of the address is equal to the value stored in the DP register. After a hardware reset the DP register always contains $00, making the 6809 compatible with the 6800. To enable this automatic selection of the direct page addressing mode, the SB-Assembler must know what the currently expected direct page is. The 6809 specific directive .DP tells the assembler what direct page to use.
We only know for sure that the high byte of the address is equal to the currently set Direct Page if there was no unresolved label used in the expression identifying the address. If a forward referenced label is used in an address expression we automatically assume the worst case situation and opt for extended addressing mode (2 bytes address field).

You may override this automatic selection of addressing mode by preceding the address field with a < or a > symbol.
The < symbol forces the assembler to use direct page addressing mode, even if the address expression contains a forward referenced label.
On the other hand the > symbol will force the assembler to use the extended addressing mode, even if the address could be resolved to a direct address.
As opposed to the 6809 cross overlay, no "*** Range error" will be reported if you try to force to use the direct addressing mode where the high byte of the address isn't equal to the current direct page. This is because the 6809 can have its direct page located anywhere in memory.

Examples:

8000-                     .DP   0             Direct page = zero page
0010-           LABEL     .EQ   $10           A direct page address
8000-96 10                LDA   LABEL         Appears to be direct page
8002-96 11                LDA   <FORWARD      Clearly a forward referenced label
8004-97 12                STA   $12           Is a direct page address
8006-B7 00 11             STA   >$11          Force extended addressing mode
0011-           FORWARD   .EQ   $11           A direct page address 

Compatibility mnemonics

I have added many mnemonics to the 6809 cross assembler to make it software compatible with the 6800. Some of these instructions don't really have an 6800 equivalent, but are added for convenience, like CLRD or ROLD. Normally the assembler isn't supposed to understand all these instructions, but I have added them here for your convenience. If you don't like them, simply don't use them. And if you like the compatibility mnemonics better than the original 6809 once, feel free to use them. But remember, you may run into portability problems when it comes to other assembler makes if you do use them extensively.

Accumulator D compound instructions

NewNative instructionsDescription

ASLDASLB
ROLA
Arithmetic shift left D
ASRDASRA
RORB
Arithmetic shift right D
CLRDCLRA
CLRB
Clear D
COMDCOMA
COMB
Complement D
LSLDLSLB
ROLA
Logical shift left D
LSRDLSRA
RORB
Logical shift right D
ROLDROLB
ROLA
Roll left D
RORDRORA
RORB
Roll right D

Set and Clear instructions

NewNative instructionsDescription

CLCANDCC #$FEClear Carry
CLFANDCC #$BFClear FIRQ flag
CLIANDCC #$EFClear IRQ flag
CLIFANDCC #$AFClear FIRQ and IRQ flags
CLVANDCC #$FDClear Overflow flag
SECORCC #$01Set Carry flag
SEFORCC #$40Set FIRQ flag
SEIORCC #$10Set IRQ flag
SEIFORCC #$50Set FIRQ and IRQ flags
SEVORCC #$02Set Overflow flag

Increment and decrement instructions

NewNative instructionsDescription

DESLEAS -1,SDecrement S
DEULEAU -1,UDecrement U
DEXLEAX -1,XDecrement X
DEYLEAY -1,XDecrement Y
INSLEAS 1,SIncrement S
INULEAU 1,UIncrement U
INXLEAX 1,XIncrement X
INYLEAY 1,YIncrement Y

Stack instructions

NewNative instructionsDescription

PSHAPSHS APush A to system stack
PSHBPSHS BPush B to system stack
PSHCCPSHS CCPush A to system stack
PSHDPSHS A,BPush B to system stack
PSHDPPSHS DPPush A to system stack
PSHPCPSHS PCPush B to system stack
PSHXPSHS XPush B to system stack
PSHYPSHS YPush B to system stack
PULAPULS APull A from system stack
PULBPULS BPull B from system stack
PULCCPULS CCPull A from system stack
PULDPULS DPull B from system stack
PULDPPULS DPPull A from system stack
PULPCPULS PCPull B from system stack
PULXPULS XPull B from system stack
PULYPULS YPull A from system stack

Please note that PSHU and PULU are not included as compound instructions. This is to avoid confusion with the original PSHU and PULU instructions, which require you to specify the registers to be pushed or pulled.

Transfer and miscellaneous instructions

NewNative instructionsDescription

ABAPSHS B
ADDA ,S+
Add B to A
CBAPSHS B
CMPA ,S+
Compare B with A
SBAPSHS B
SUBA ,S+
Subtract B from A
TABTFR A,B
TSTA
Transfer A to B and set flags
TAPTFR A,CCTransfer A to CC
TBATFR B,A
TSTA
Transfer B to A and set flags
TPATFR CC,ATransfer CC to A
TSXTFR S,XTransfer S to X
TXSTFR X,STransfer X to S
WAICWAI #$FFWait for interrupt

Apart from the tables above you can also use the 6800 instructions like LDAA instead of LDA, or STAB instead of STB etc.

Overlay Initialization

Three things are set while initializing the 6809 overlay every time it is loaded by the .CR directive.

  • Big endian model is selected for 16-bit addresses and for the .DA and .DL directives. This means that words or long words are stored with their high byte first.
  • The assumed direct page is set to $00, which reflects the way the 6809 will wake up from reset.
  • The maximum program counter value is set to $FFFF.
.DP    Direct Page

Syntax:

        .DP  expression

Function:

The .DP directive is used to tell the SB-Assembler what the currently selected Direct Page is. Knowing this enables the SB-Assembler to automatically select between direct addressing mode and extended addressing mode. The SB-Assembler will use direct addressing mode whenever the address and the instruction both allow it.

Explanation:

The direct page of a 6809 may be located in any memory page, as opposed to the direct page of the 6800 which is fixed to page 0. You must be able to tell the SB-Assembler what the expected direct page is to allow it to select the direct page addressing mode whenever possible. This is done with the .DP directive.
Please note that you only tell the SB-Assembler what memory bank is supposed to be selected. It is the programmer's responsibility to effectively set the 6809's DP register to the proper value to make it really happen! The SB-Assembler has no way of checking this and is therefore unable to warn you about it. So the .DP directive is in no way a substitute for the loading of the DP register to really select the direct page on the processor!
Page 0 is selected when a 6809 comes out of reset and that is also the default expected direct page after loading or reloading the cross overlay.

The expression must evaluate to a value from 0 to 255 and may not contain forward referenced labels. Other values will result in a "*** Range error".

The SB-Assembler will automatically select the direct addressing mode whenever it can. This is when the instruction allows it and when the upper byte of the operand address is equal to the value set by the latest .DP instruction.
The destination address must be resolved completely, otherwise the worst case situation is expected and the SB-Assembler will opt for extended addressing mode. So the SB-Assembler will use extended addressing mode if the destination address contains a forward referenced label.

You can force the use of direct addressing mode by preceding the destination address with the < symbol. The direct addressing mode will then be used regardless of forward referenced labels and regardless of the destination address' high byte value.
This differs a little with e.g. the 6800 assembler because on the 6809 the high byte of the address may be any value, not only 0.
You can also force the SB-Assembler to use extended addressing mode by preceding the destination address by the > symbol.

Example:

8000-                  .DP    $00         Tell assembler to use DP $00
8000-86 00             LDA    #$00        Tell 6809 to use
8002-1F 8B             TFR    A,DP         direct page $00
8004-96 12             LDA    $12         Use direct mode automatically
8006-B6 12 34          LDA    $1234       Don't use direct mode
8009-
8009-                  .DP    $12         Tell assembler to use DP $12
8009-86 12             LDA    #$12        Tell 6809 to use
800B-1F 8B             TFR    A,DP         direct page $12
800D-BC 00 12          LDA    $12         Don't use direct mode
8010-96 34             LDA    $1234       Use direct mode automatically

Please note that the assembler would still generate the same code when the LDA #$12 and TFR A,DP instructions at address $8009 were omitted. But in real life the last program line would point to address $0034 instead of the intended address $1234!

Differences With Other Assemblers

There are some differences between the SB-Assembler and other assemblers for the 6809 processor. These differences require you to adapt existing source files before they can be assembled by the SB-Assembler. This is not too difficult though, and is the (small) price you have to pay for having a very universal cross assembler.

  • Not all assemblers are as forgiving when it comes to entering register names with push and pull instructions.
  • Not all assemblers will understand all the compatibility instructions.
  • Not all assemblers will understand forced direct page and extended addressing modes.
  • The obvious differences in notation of directives and radixes common to all SB-Assembler crosses.
  • Don't forget that the SB-Assembler does not allow spaces in or between operands.
 

© 2002, San Bergmans, Oisterwijk, The Netherlands
http://www.sbprojects.com