|   |
![]() |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Home |
This page has not been adapted to SB-Assembler Version 3 yet.
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.
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.
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.
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:
IRQ interrupts are disabled when the I bit is set.
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.
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.
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.
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 don't have anything to do with the SB-Assembler in particular, but I've included them here anyway for easy reference.
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.
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.
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.
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.
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.
You may override this automatic selection of addressing mode by preceding the address field with a < or a > symbol.
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
Set and Clear instructions
Increment and decrement instructions
Stack instructions
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
Apart from the tables above you can also use the 6800 instructions like LDAA instead of LDA, or STAB instead of STB etc.
Three things are set while initializing the 6809 overlay every time it is loaded by the .CR directive.
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.
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.
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.
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!
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.
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||