Thank you, for pointing that out. I thought the register number is encoded in BCD format. Also the "not working" ST D0,$1218 instruction was actually working. I had a bug in my memory read function which only read 24 bit and worked due to alignment when storing from a 32-Bit register.
An additional problem came up, maybe you have a explanation or hint for that too:
At branches with negative offsets (where the target location address is lower than the actual Instruction address) the PC seems to be loaded with an invalid location due to wrong calculation of offset.
When I modify the program so that JMP instructions are used (absolute jump addresses) instead of a negative branch everything works as expected.
As far as I can see the assembler does always use the branch Instructions with REL_SIZE bit set when using labels. Even at branches with offsets in range to PC-64. This should not be a problem to me in general, but i don't know why the twos complement offset is not calculated correctly.
This is a listing of my sample program.
Abs. Rel. Loc Obj. code Source line
---- ---- ------ --------- -----------
63 63 ORG RAM_MAIN
64 64 startup:
65 65 a001220 1B03 0011 LD S,#RAM_STACK
001224 FF
66 66 a001225 0F00 0000 MOV.l #0,retError
001229 0012 10
67 67 a00122C 9411 LD D0,#$11
68 68 a00122E BA00 1243 JMP test
69 69
70 70 branch:
71 71 a001232 9155 66 LD D3,#$5566
72 72 a001235 9677 8899 LD D6,#$778899AA
001239 AA
73 73 a00123A 97BB CCDD LD D7,#$BBCCDDEE
00123E EE
74 74 a00123F BA00 124B JMP done
75 75
76 76 test:
77 77 a001243 9522 LD D1,#$22
78 78 a001245 2092 32 BRA branch
79 79 a001248 9033 44 LD D2,#$3344
80 80
81 81 done:
82 82 a00124B 00 BGND
With my debugger I read the following register values when program stops execution:
D0: 11
D1: 22
D2: 0000
D3: 0000
D4: 0000
D5: 0000
D6: 00000000
D7: 00000000
X: 000000
Y: 000000
SP: 0011FF
PC: 002478
In line 78 you can see that PC will increase by 0x1232 -> PC = 0x1232 + 0x1245 = 0x2477
0x2477 Is not a valid memory location so PC is incremented by one and CPU Halts
If I change the the binary with "20 FF ED" instead of "20 92 32" which is the correct twos complement instruction for "BRA -19" the program works expected and the register values are correct.
Also if I use the "BRA -19" it'll be encoded to the correct twos complement and even the short form with REL_SIZE bit cleared.
Is there something i'm doing wrong, or is that a bug?
Edit: I noticed that it's the actual address of the marker if it's at a lower address. In case of a positive offset the assembler correctly uses the offset, and not the address of the marker. So it seems like a real bug...