Help for Motorola 6809 EXG instruction
See original GitHub issueI am currently defining a slaspec for the Motorola 6809 CPU. I would need some help for the EXG instruction (It exchanges the contents of two registers). A good documentation for EXG instruction You will find here: 6x09 Instruction Sets on page 66.
There are three challenges I can find no solution accepted by sleigh parser:
- The two registers are defined in a separate data byte.
- The two registers may have 8- or 16-bit which may not be mixed. If mixed => invalid instr.
- There are “invalid” registers possible. If used => invalid instr.
Here my current approach:
# sleigh specification file for Motorola 6809
define endian=big;
define alignment=1;
define space RAM type=ram_space size=2 default;
define space register type=register_space size=1;
define register offset=0 size=1 [ A B DP ]; # 8-bit registers A, B, DP
define register offset=0 size=2 [ D ]; # 16-bit D reg. (Same addr. as A/B)
define register offset=8 size=1 [ CC ]; # 8-bit condition code register
define register offset=16 size=2 [ PC X Y U S ]; # 16-bit registers:
define token opbyte (8)
op = (0,7)
;
define token data8 (8)
reg01= (4,7)
reg02= (4,7)
reg11= (0,3)
reg12= (0,3)
;
# register set for EXG instruction 8-bit registers
attach variables [ reg01 ] [ _ _ _ _ _ _ _ _ A B CC DP _ _ _ _ ];
attach variables [ reg11 ] [ _ _ _ _ _ _ _ _ A B CC DP _ _ _ _ ];
# register set for EXG instruction 16-bit registers
attach variables [ reg02 ] [ D X Y U S PC _ _ _ _ _ _ _ _ _ _ ];
attach variables [ reg12 ] [ D X Y U S PC _ _ _ _ _ _ _ _ _ _ ];
# Exchange two 8-bit registers
# Test with registers A, B
:EXG reg01,reg11 is op=0x1E; (reg01=8 | reg01=9) & (reg11=8 | reg11=9)
{
local tmp = reg01;
reg01 = reg11;
reg11 = tmp;
}
# Exchange two 16-bit registers
# Test with registers D, X
:EXG reg02,reg12 is op=0x1E; (reg02=0 | reg02=1) & (reg12=0 | reg12=1)
{
local tmp = reg02;
reg02 = reg12;
reg12 = tmp;
}
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (4 by maintainers)
Top Results From Across the Web
6x09 Instruction Sets - Color Computer Archive
The EXG instruction requires a postbyte in which the two registers that are involved are encoded into the upper and lower nibbles. See...
Read more >MC6809-MC6809E Microprocessor Programming Manual ...
This section contains a general description of the Motorola MC6809 and MC6809E Microprocessor Units (MPU). Pin assignments and a brief description of each...
Read more >M6809PM.rev0_May83.pdf - Bitsavers.org
MOTOROLA. (3). MC6809-MC6809E. Microprocessor Programming Manual. 8 BIT. M6809. M6809PM/AD ... Postbyte Usage for EXG/TFR, PSH/PUL Instructions.
Read more >The MC6809 CookBook.pdf
defined by Motorola. (For further information, consult the M6800 microprocesor applications manual). • The 6809, µP, housed in a 40-pin package, ...
Read more >MC6809 MC6809E Microprocessor Programming Manuial 1981
manual to refer to both the MC6809 and MC6809E processors. When a topic relates to ... assembled using the Motorola MC6809 Macro Assembler....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
This should do what you want. Also for the 6309 which has a slightly different set of semantics. The approach is a little brute force and there are probably other clever ways, but this lays out all the subtle cases, and the cases when an operand is invalid which have specifically called out semantics.
Also note the GOTO semantics when the PC is one of the targets.
Looking forward to the full language!
Now there is a PR #1201 for M6809 😃