Log inRegister an accountBrowse CSDbHelp & documentationFacts & StatisticsThe forumsAvailable RSS-feeds on CSDbSupport CSDb Commodore 64 Scene Database
You are not logged in - nap
CSDb User Forums


Forums > C64 Coding > 64tass: labels inside FOR ... NEXT loops
2016-12-01 15:45
ready.

Registered: Feb 2003
Posts: 441
64tass: labels inside FOR ... NEXT loops

hello,
does 64tass have the possibility to use indexed labels, like inside a FOR...NEXT loop?

Something like:
.FOR X=0, X<X_MAX-1, X=X+1
LABEL(X)
LDA #ABC
STA ZXY
.NEXT
so to have X_MAX labels.

Unrolled:

LABEL1
LDA #ABC
STA ZXY
LABEL2
LDA #ABC
STA ZXY
.....
 
... 20 posts hidden. Click here to view all posts....
 
2019-02-21 20:27
soci

Registered: Sep 2003
Posts: 480
Btw. in 1.54 I've added scoped loop directives. Now the second example in post #5 can be simplified to:
        *= $1000

lista   .bfor i = 0, i < 8, i += 1
label   lda #i
        .if i > 3
lbl2    nop
        .fi
        .next

        .word lista.label ; all labels
        .word lista[4].lbl2 ; the one from the 5th run
2019-02-22 07:27
oziphantom

Registered: Oct 2014
Posts: 490
This new feature is handy for avoiding the "I used a" trap ;)

aka

.for a = 0, a < 10 , a += 2

then later

lsr a

.warning Invalid addressing mode
2019-02-22 08:48
soci

Registered: Sep 2003
Posts: 480
The loop related calculations are not scoped. This is so you can update an existing variable created somewhere above and that the loop variable is available later for checks/further continuation loops.

Such unfortunate name choices should be avoided. Using -Wshadow can help with that.
2019-10-02 15:54
ready.

Registered: Feb 2003
Posts: 441
thanks for the replies, they've been really useful.
Now I take it to an even further level.
Let's say I need a multiple index label, so far I only need a vector of labels, thus: LABEL[0], LABEL[1], LABEL[2]....
But how can I implement a matrix of labels, thus
LABEL[0][0], LABEL[0][1],....
LABEL[1][0], LABEL[1][1],...
LABEL[2][0], LABEL[2][1],...
Somthing like:
FRAME := [][][]
.FOR FRAME=0,FRAME<=6,FRAME=FRAME+2
.FOR ZOOM=1,ZOOM<=3,ZOOM=ZOOM+1
FRAME .= [FRAME],[ZOOM]
.binary .....
.NEXT
.NEXT
2019-10-02 17:12
soci

Registered: Sep 2003
Posts: 480
You need to nest them. For the exact style you want:
FRAMES := []
.FOR FRAME=0, FRAME<=6, FRAME += 2
 ZOOMS := []
 .FOR ZOOM=1, ZOOM<=3, ZOOM += 1
  - .binary .....
  ZOOMS ..= [-] ; collect in zooms
 .NEXT
 FRAMES ..= [ZOOMS] ; collect zooms in frames
.NEXT

lda #<FRAMES[2][0]
ldx #>FRAMES[2][0]
However I would do this instead:
FRAMES .BFOR FRAME IN RANGE(0, 7, 2)
 ZOOMS .BFOR ZOOM IN RANGE(1, 4)
  .binary .....
 .NEXT
.NEXT

lda #<FRAMES[2].ZOOMS[0]
ldx #>FRAMES[2].ZOOMS[0]
2020-01-25 22:09
ready.

Registered: Feb 2003
Posts: 441
thanks I got it working, very useful stuff. However I spotted a possible bug with 64TASS 1.54.1900
This is compiles ok:
FRAMES := []
.FOR FRAME=0, FRAME<=6, FRAME += 2
ZOOMS := []
.FOR ZOOM=1, ZOOM<=3, ZOOM += 1
- .binary .....
ZOOMS ..= [-] ; collect in zooms
.NEXT
FRAMES ..= [ZOOMS] ; collect zooms in frames
.NEXT

lda #<FRAMES[2][0]
ldx #>FRAMES[2][0]

while this complains "error: not defined ident 'FRAMES'"
lda #<FRAMES[2][0]
ldx #>FRAMES[2][0]

FRAMES := []
.FOR FRAME=0, FRAME<=6, FRAME += 2
ZOOMS := []
.FOR ZOOM=1, ZOOM<=3, ZOOM += 1
- .binary .....
ZOOMS ..= [-] ; collect in zooms
.NEXT
FRAMES ..= [ZOOMS] ; collect zooms in frames
.NEXT

so basically I am forced to declare the labels in RAM before they are actually used. In my program I call the labels in upper RAM but store the tables with labels definition much further down.
2020-01-25 22:14
ready.

Registered: Feb 2003
Posts: 441
ok just found a workaround which compiles fine:
lda #<support_label
ldx #>support_label

FRAMES := []
.FOR FRAME=0, FRAME<=6, FRAME += 2
ZOOMS := []
.FOR ZOOM=1, ZOOM<=3, ZOOM += 1
- .binary .....
ZOOMS ..= [-] ; collect in zooms
.NEXT
FRAMES ..= [ZOOMS] ; collect zooms in frames
.NEXT

support_label = FRAMES[2][0]

I guess I can live with that :)
2020-01-26 06:17
oziphantom

Registered: Oct 2014
Posts: 490
variables that are defined as := are defined in linear order and reset on each pass. So := before usage is required. By doing
x = variable

x is now a permanent value that remains across passes and hence the assembler can sub it in on the next pass for you.
Previous - 1 | 2 | 3 - Next
RefreshSubscribe to this thread:

You need to be logged in to post in the forum.

Search the forum:
Search   for   in  
All times are CET.
Search CSDb
Advanced
Users Online
Flashback
Bieno/Commodore Plus
DeMOSic/MS^LSD^ONS
Guests online: 91
Top Demos
1 Next Level  (9.7)
2 13:37  (9.7)
3 Mojo  (9.7)
4 Coma Light 13  (9.6)
5 Edge of Disgrace  (9.6)
6 What Is The Matrix 2  (9.6)
7 The Demo Coder  (9.6)
8 Uncensored  (9.6)
9 Comaland 100%  (9.6)
10 Wonderland XIV  (9.6)
Top onefile Demos
1 Layers  (9.6)
2 No Listen  (9.6)
3 Cubic Dream  (9.6)
4 Party Elk 2  (9.6)
5 Copper Booze  (9.6)
6 Rainbow Connection  (9.5)
7 Dawnfall V1.1  (9.5)
8 Onscreen 5k  (9.5)
9 Morph  (9.5)
10 Libertongo  (9.5)
Top Groups
1 Performers  (9.3)
2 Booze Design  (9.3)
3 Oxyron  (9.3)
4 Triad  (9.3)
5 Censor Design  (9.3)
Top Crackers
1 Mr. Z  (9.9)
2 Antitrack  (9.8)
3 OTD  (9.8)
4 Fungus  (9.8)
5 S!R  (9.8)

Home - Disclaimer
Copyright © No Name 2001-2024
Page generated in: 0.044 sec.