[Coco] Direct page register question

William Astle lost at l-w.ca
Tue Oct 30 15:50:43 EDT 2018


On 2018-10-30 1:32 p.m., Dave Philipsen wrote:
> For most assemblers, yes, that will be interpreted as direct addressing since you did not use a 16-bit address.  In fact, most assemblers would also interpret LDA   $0085 as direct addressing too since it is assumed that DP is set to $00.
> 
> With a good assembler you will almost never need to force direct addressing as the assembler will figure it out and do it for you.  If you decide to use a direct page different than $00 then most assemblers will allow a SETDP directive that will tell the assembler what the new direct page is.  This is only a directive for the assembler.  It does not actually set the DP register so it should be accompanied with the proper LDA #$xx / TFR   A,DP instructions.

Since Dave didn't mention it explicitly and it might surprise some 
people, I should mention here that if you do use SETDP to something 
other than 0, then "LDA $85" will assemble as extended addressing.

So if you do "SETDP $40", then "LDA $4085" would assemble as direct 
addressing but "LDA $85" would assemble as extended.

Something also to be aware of with this. The assembler can only decide 
to use direct addressing if it knows what the address is. For typical 
two pass assemblers, that means that something like "LDA SYMBOL" where 
SYMBOL is defined to be in the direct page somewhere, may not assemble 
as direct addressing if SYMBOL is defined later in the source than the 
"LDA SYMBOL" instruction. This is because the two pass assembler must 
set the sizes of all instructions on the first pass to avoid phasing 
errors (where symbols change location between passes).

That is:

	LDA SYMBOL
SYMBOL	EQU $85

This will probably use extended addressing because during pass one, the 
assembler hasn't seen the definition of SYMBOL yet when it gets to the 
LDA instruction so it has to assume full 16 bit addressing.

On the other hand:

SYMBOL	EQU $85
	LDA SYMBOL

This will be able to use direct addressing.

This is actually one of the reasons you should define your variables at 
the start of the program, especially if the direct page is going to be used.


More information about the Coco mailing list