XA: playing with tables

Here you can ask questions or provide insights about how to use efficiently 6502 assembly code on the Oric.
User avatar
Symoon
Archivist
Posts: 2307
Joined: Sat Jan 14, 2006 12:44 am
Location: Paris, France

XA: playing with tables

Post by Symoon »

Hi,

So I'm using OSDK's XA and I'm trying to tell him I want to read a table, but starting 56 bytes before its start address (Y will be set accordingly with +56 of course).

I did this:

Code: Select all

#define VPYMAX_INV    56
Then tried this:

Code: Select all

lda ScreenAddressLow-#VPYMAX_INV,y
and this:

Code: Select all

lda (ScreenAddressLow-#VPYMAX_INV),y
But both generate an error: "lda ScreenAddressLow-#56,y" 099c Syntax Error
What would be the correct syntax to do this, is it possible?
Thanks!
User avatar
Symoon
Archivist
Posts: 2307
Joined: Sat Jan 14, 2006 12:44 am
Location: Paris, France

Re: XA: playing with tables

Post by Symoon »

Ok, just found it seems to work with:

Code: Select all

lda ScreenAddressLow-VPYMAX_INV,y
\o/
User avatar
Dbug
Site Admin
Posts: 4444
Joined: Fri Jan 06, 2006 10:00 pm
Location: Oslo, Norway
Contact:

Re: XA: playing with tables

Post by Dbug »

One thing to remember, is that # and () have very specific meanings in 6502, tied to the addressing mode, so you can't just put them at any random place:
  • 6502 only support one expression, so no matter what you enters it has to make sense as something that can be evaluate to something that matches an existing addressing mode for this specific instruction
  • # is ALWAYS used to denote an immediate value, and when used for that it's always the first character of the expression, you can't put it in the middle.
  • Parenthesis are most of the time used with ,x and ,y addressing mode, if you try to use parenthesis in an expression which has ,x or ,y in it, you are basically making the whole line ambiguous to the assembler
If you look on the documentation, you can see the following:
Valid expressions are, e.g.:

LDA base+number*2,x

For Addressing modes that do not start with a bracket, you can even use a bracket at the beginning of an expression. Otherwise try this:

LDX (1+2)*2,y ; Wrong!
LDX 2*(1+2),y ; Right!
In your case, it means that this one is fine: lda ScreenAddressLow-VPYMAX_INV,y
but that one is not: lda (ScreenAddressLow-VPYMAX_INV,)y

The reason is that the assembler assumes that if it starts by a parenthesis, then it is a zero page address containing a pointer which is indexed through the Y register.

But, you can cheat by removing the ambiguity, which makes that one valid: lda 0+(ScreenAddressLow-VPYMAX_INV),y
User avatar
Symoon
Archivist
Posts: 2307
Joined: Sat Jan 14, 2006 12:44 am
Location: Paris, France

Re: XA: playing with tables

Post by Symoon »

Dbug wrote: Sun Aug 21, 2022 5:57 pm [*]# is ALWAYS used to denote an immediate value, and when used for that it's always the first character of the expression, you can't put it in the middle.
Thanks, that's what I was missing!
(it's a bit confusing for a beginner to have to use #ZERT if it's at the beginning, or ZERT if it's inside a formula !)
User avatar
Dbug
Site Admin
Posts: 4444
Joined: Fri Jan 06, 2006 10:00 pm
Location: Oslo, Norway
Contact:

Re: XA: playing with tables

Post by Dbug »

Symoon wrote: Sun Aug 21, 2022 6:07 pm
Dbug wrote: Sun Aug 21, 2022 5:57 pm [*]# is ALWAYS used to denote an immediate value, and when used for that it's always the first character of the expression, you can't put it in the middle.
Thanks, that's what I was missing!
(it's a bit confusing for a beginner to have to use #ZERT if it's at the beginning, or ZERT if it's inside a formula !)
It's not the same thing. The # is not part of the formula ("expression" is the proper term).

lda #expression -> expression is an immediate value
lda expression -> expression is an absolute address which point to the place where the value is located, and that one can be absolute long or zero page
User avatar
Symoon
Archivist
Posts: 2307
Joined: Sat Jan 14, 2006 12:44 am
Location: Paris, France

Re: XA: playing with tables

Post by Symoon »

Dbug wrote: Sun Aug 21, 2022 6:47 pm
Symoon wrote: Sun Aug 21, 2022 6:07 pm
Dbug wrote: Sun Aug 21, 2022 5:57 pm [*]# is ALWAYS used to denote an immediate value, and when used for that it's always the first character of the expression, you can't put it in the middle.
Thanks, that's what I was missing!
(it's a bit confusing for a beginner to have to use #ZERT if it's at the beginning, or ZERT if it's inside a formula !)
It's not the same thing. The # is not part of the formula ("expression" is the proper term).

lda #expression -> expression is an immediate value
lda expression -> expression is an absolute address which point to the place where the value is located, and that one can be absolute long or zero page
Mmmmh, I got that for simple instructions, but this time I think I got it regarding my more complex syntax. Thanks ;)
The way I would explain it to newbies like me, is that # actually rather belongs to the instruction (LDA or LDA #), to know the type of addressing (or non-addressing) it is using, rather than belonging to the values that follow. What I wrote had no meaning in this regard.
Which is what you told me in your 1st reply, but I'm a rather painful student ;)
Post Reply