lda simplification of relative y index value ?

Here you can ask questions or provide insights about how to use efficiently 6502 assembly code on the Oric.
Post Reply
User avatar
goyo
Officer Cadet
Posts: 39
Joined: Sat Jan 12, 2019 10:16 am

lda simplification of relative y index value ?

Post by goyo »

Hi,

is it possible to replace

Code: Select all

dey
dey
dey
lda (sprite_address),y
by

Code: Select all

lda (sprite_address),y-3
?

User avatar
Chema
Game master
Posts: 2754
Joined: Tue Jan 17, 2006 10:55 am
Location: Gijón, SPAIN
Contact:

Re: lda simplification of relative y index value ?

Post by Chema »

Not sure what you mean. lda(zpadd),y-3 does not exist as an asm instruction and it is not standard. It would probably create ambiguity (what is the value of y after that instruction?) or about the code to create (y-20 would create 20 dey instructions, a loop, or maybe a pha:tya:sec:sbc #20:tay:pla?).

Another different and more standard approach would be using a macro such as DECY(3), that could expand as dey:dey:dey but I am not sure such kind of code could be created with the simple preprocessor-like macros (unless using something such as #define DECY(X) .dsb X,$88 with $88 being the opcode of dey... would that make sense?)

User avatar
Dbug
Site Admin
Posts: 3577
Joined: Fri Jan 06, 2006 10:00 pm
Location: Oslo, Norway
Contact:

Re: lda simplification of relative y index value ?

Post by Dbug »

I would personally recommend that you get yourself a book about the 6502 (there are plenty in PDF) and read about the addressing modes, there's not much about it, and that's all you can use.

User avatar
jbperin
Flying Officer
Posts: 216
Joined: Wed Nov 06, 2019 11:00 am
Location: Valence, France

Re: lda simplification of relative y index value ?

Post by jbperin »

goyo wrote:
Fri Dec 11, 2020 6:47 pm

Code: Select all

lda (sprite_address),y-3
Cette instruction n'est pas possible en assembleur.

Il est possible, en certaines circonstances, de mettre des expressions arithmétiques dans des instructions assembleur.
Par exemple:

Code: Select all

__auto_1
    lda $245
    sta jmp_old_handler+1
__auto_2
    lda $246
    sta jmp_old_handler+2
ou bien:

Code: Select all

#define SCREEN_WIDTH 40
#define ADR_BASE_LORES_SCREEN 48040  
    sta ADR_BASE_LORES_SCREEN+SCREEN_WIDTH*4 , x
ou encore:

Code: Select all

#define DISPLAY_ADRESS $BB80
ScreenAdressLow
	.byt <(DISPLAY_ADRESS+40*0)
Ce qu'il faut comprendre, c'est à quel moment l'évaluation de l'expression est faite.

Dans tous les exemples ci-dessus, les grandeurs manipulées dans l'expression arithmétique sont des constantes (valeurs en dur, ou via des #define ou adresse mémoire).
L'assembleur peut donc les évaluer au moment de fabriquer le code machine.
Il produira une instruction en langage machine contenant le résultat de l'opération. Ce n'est pas le processeur 6502 qui va faire l'opération.

Dans le cas que tu montres, le "y-3" ne peut pas être évaluer au moment de l'assemblage car le résultat dépend de y au moment de l'exécution de l'instruction. l'assembleur ne peut donc pas produire une instruction en langage machine qui contienne le résultat de l'opération.

Le seul moyen consiste donc à faire faire l'opération au 6502 comme tu le fais avec les dey.

User avatar
Dbug
Site Admin
Posts: 3577
Joined: Fri Jan 06, 2006 10:00 pm
Location: Oslo, Norway
Contact:

Re: lda simplification of relative y index value ?

Post by Dbug »

Please, stick to English, other people can benefit from that!

User avatar
goyo
Officer Cadet
Posts: 39
Joined: Sat Jan 12, 2019 10:16 am

Re: lda simplification of relative y index value ?

Post by goyo »

thanks to you Jedi Masters of the Oric. ! 8)

I understood thanks to you :)

I go to level 2 of the 6502 assembler .... :idea:

sam
Officer Cadet
Posts: 56
Joined: Sun Jul 09, 2017 3:28 pm
Location: Brest (France)
Contact:

Re: lda simplification of relative y index value ?

Post by sam »

goyo wrote:
Fri Dec 11, 2020 6:47 pm

Code: Select all

lda (sprite_address),y-3
Did you meant

Code: Select all

lda (sprite_address-3),y
?

But you might have issue with y values 0,1,2 as there will not be the expected "wrap around" that "dey;dey;dey" produces.

sam (my 2 cents)

User avatar
jbperin
Flying Officer
Posts: 216
Joined: Wed Nov 06, 2019 11:00 am
Location: Valence, France

Re: lda simplification of relative y index value ?

Post by jbperin »

Dbug wrote:
Sun Dec 13, 2020 1:57 pm
Please, stick to English, other people can benefit from that!
Yes sorry,


I was just saying that, unlike structured languages, assembly language doesn't make it possible to use arithmetic expression except for expression involving only constant values because such expression can be evaluated by the pre-processor or the assember. :wink:

Post Reply