| |
Hypnosis
Registered: Mar 2015 Posts: 36 |
Assembler with dynamic symbol creation
I have read some documentation for an assembler that allowed labels or symbols to be created dynamically, basically by concatenating strings. Which assembler was that? |
|
... 15 posts hidden. Click here to view all posts.... |
| |
soci
Registered: Sep 2003 Posts: 480 |
Example of doynax translated:
smc_store .segment name
\{name}_value = *+1
lda #$00
\{name}_addr = *+1
sta @w$0000
.endm
*= $1000
#smc_store test
sta test_value
But don't do it, this is evil ;)
smc_store .macro
value = *+1
lda #$00
addr = *+1
sta @w$0000
.endm
*= $1000
test #smc_store
sta test.value
Somewhat better.
Hypnosis: Later 64tass versions tolerate "wrong" definition and use ordering.
*= $1000
.1000 4c 06 10 jmp $1006 jmp l[0]
.1003 4c 07 10 jmp $1007 jmp l[1]
=[$1006,$1007] l = [b1, b2]
.1006 ea nop b1 nop
.1007 ea nop b2 nop
Unsurprisingly it has suboptimal performance compared to proper ordering.
Slammer: I was thinking about this sort of list generation some time ago for .rept when it was still hard to implement it. Now it'd be much easier, but I can't think of a compelling use for it in my sources (yet). Even if it'd be available now probably I'd still write the above example like this:
*= $1000
count = 25
.for i = 0, i < count, i = i + 1
lda #i
sta (+)+1
.section speedcode
+ lda #0
sta $d020
.send
.next
.dsection speedcode ; right after the modifier
This compiles the two code parts in tandem so an anonymous label is good enough. Results in:
.1000 a9 01 lda #$00 lda #i
.1002 8d 7e 10 sta $107e sta (+)+1
.107d a9 00 lda #$00 + lda #0
.107f 8d 20 d0 sta $d020 sta $d020
.1005 a9 01 lda #$01 lda #i
.1007 8d 83 10 sta $1083 sta (+)+1
.1082 a9 00 lda #$00 + lda #0
.1084 8d 20 d0 sta $d020 sta $d020
...
In case of more labels it'd name them properly and stick in a .block scope to avoid the symbol collisions. |
| |
Hypnosis
Registered: Mar 2015 Posts: 36 |
Interesting use of sections! |
| |
Hypnosis
Registered: Mar 2015 Posts: 36 |
Quoting SlammerScoping solution = you access the scope instance of a given iteration of the loop
Ah, that was the missing part in my puzzle. I haven't seen this before. |
| |
Slammer
Registered: Feb 2004 Posts: 416 |
Soci: I prefer the scoping solution so I will stick to that, but I guess its a matter of taste. And nobody says you can't do both. Seems like we pretty much agree on scoping for macro executions...
.macro smc_store() {
.label value =*+1
lda #$00
.label addr = *+1
sta.a $0000
}
*= $1000
test: smc_store()
sta test.value |
| |
Peacemaker
Registered: Sep 2004 Posts: 275 |
at the moment i doing it like this with kickass:
.const count=25
loop1: .for(var i=0; i<count; i++) {
lda #i
sta loop2+1+i*5
}
loop2: .for(var i=0; i<count; i++) {
color: lda #0
sta $d020
} |
| |
Oswald
Registered: Apr 2002 Posts: 5094 |
Quote: at the moment i doing it like this with kickass:
.const count=25
loop1: .for(var i=0; i<count; i++) {
lda #i
sta loop2+1+i*5
}
loop2: .for(var i=0; i<count; i++) {
color: lda #0
sta $d020
}
lda #i
ldy #$01
sta (fe),y
lda fe
clc
adc #$05
sta fe
bcc *+4
inc ff |
| |
Peacemaker
Registered: Sep 2004 Posts: 275 |
thanks oswald, but that is slower =) |
| |
Oswald
Registered: Apr 2002 Posts: 5094 |
no, thats the generator. just wanted to show how simple is it you macro nerds :) |
| |
Compyx
Registered: Jan 2005 Posts: 631 |
But what are 'fe' and 'ff', macro's? ;) |
| |
chatGPZ
Registered: Dec 2001 Posts: 11386 |
those are not macros, those are labels! |
Previous - 1 | 2 | 3 - Next |