[Coco] Mod10 Suggestions

William Astle lost at l-w.ca
Thu Feb 16 23:19:54 EST 2017


On 2017-02-16 08:57 PM, Arthur Flexser wrote:
> I don't believe STB #RESULT is a legal 6809 addressing mode;  it's trying
> to store something into a constant, like STB #5.  Should be STB RESULT.  Or
> STB RESULT,PC if you want position independence.  Same with STA #STATUS.

TL;DR: ",PCR" is the correct syntax. Don't use ",PC" - it won't do what 
you expect on many assemblers.

Warning: pedantry ahead.

As a point of information, "RESULT,PC" is incorrect. The correct syntax 
is "RESULT,PCR". Any assembler that accepts ",PC" as synonymous with 
",PCR" is technically broken. Officially, there is a difference between 
the two notations which is explained below. In case anyone wondered, 
this is why lwasm requires a pragma to get the ",PC as a synonym to 
,PCR" behaviour.

SYM,PC: use the absolute value of SYM as the offset from PC
SYM,PCR: calculate the proper offset to SYM from the current address

The difference is illustrated as follows. Suppose you have the following 
completely pointless code:

	ORG 0
	LEAX SYM,PC
	LEAX SYM,PCR
	RTS
SYM	EQU *

The above code would assemble to something like this:

0000: 30 8C 07
0003: 30 8C 01
0006: 39
0007: <address of SYM>

The "30 8C" bits are LEAX with an 8 bit offset from PC. Note the first 
one uses "7" as the offset, which is, in fact, the actual address of 
SYM. Note that the second uses "1" as the offset. That is because PC 
would have 6 in it after parsing the LEAX SYM,PCR instruction. The value 
that needs to be added to PC to get to SYM at that point is 1.

If you change the ORG statement to, say, $50, then the first instruction 
would assemble to "30 8C 50" instead, but the second would be unchanged.

Basically, the first variant uses the specified offset exactly as 
written while the second causes the assembler to calculate the correct 
offset.

Generally speaking, the "SYM,PC" variation is not useful when writing 
code. It is, however, useful on occasion during disassembly when you do 
not want to bother with calculating the resulting address. Thus, marking 
something as "...,PC" means that the "..." is not the target address but 
is the offset to be added to PC while "...,PCR" means that "..." *is* 
the actual address desired.




More information about the Coco mailing list