| |
Taskmaster Account closed
Registered: Feb 2018 Posts: 22 |
Kick Assembler - Removal of unused code?
I'm trying out Kick Assembler and I'm wondering if it has a feature I used a lot in my own assemblers over the years.
I like to collect useful subroutines and keep them in an external ASM file that I include at the top of my code. Is there a way that I can do that BUT have the assembler not compile code that I don't actually call?
I hate to eat the memory space for stuff that I won't be calling in that specific app.
How do you guys handle this sort of thing? Am I over engineering? :) |
|
... 20 posts hidden. Click here to view all posts.... |
| |
Digger
Registered: Mar 2005 Posts: 437 |
Interesting problem... I've found this article on Macros (http://wilsonminesco.com/StructureMacros/index.html) but it seems a little bit over the top for me to code like that, code is more readable but longer and slower.
It's possible to do purely with KickAss macros:
// Address for all compiled macros
.var libAddrOffset = $2000
// Address (plus flag) for the compiled macro
.var setColorsUsedAddr = null
// Here comes the proc
.macro setColors() {
// Store current program address
.var currentAddr = *
// Check if macro was used before
.if (setColorsUsedAddr == null) {
// Not yet, compile at lib address
* = libAddrOffset
// Mark the macro as used and store its address
.eval setColorsUsedAddr = libAddrOffset
stx $d020
sty $d021
rts
// Update the library address (for additional macros)
.eval libAddrOffset = *
}
// Restore program address
* = currentAddr
// Call the proc
jsr setColorsUsedAddr
}
// Example: Proc called twice, compiled once
// If not used, won't compile
* = $1000
ldx #2
ldy #4
setColors()
ldx #7
ldy #8
setColors()
jmp *
Here's the result:
(C:$100e) d 1000
.C:1000 A2 02 LDX #$02
.C:1002 A0 04 LDY #$04
.C:1004 20 00 20 JSR $2000
.C:1007 A2 07 LDX #$07
.C:1009 A0 08 LDY #$08
.C:100b 20 00 20 JSR $2000
.C:100e 4C 0E 10 JMP $100E
.C:1011 00 BRK
(C:$1029) d 2000
.C:2000 8E 20 D0 STX $D020
.C:2003 8C 21 D0 STY $D021
.C:2006 60 RTS
.C:2007 00 BRK
This could be even abstracted out in a more elegant fashion, i.e. store addresses as List() and create a macro called .proc() that would wrap just the macro code. Let me know if you need help with that :) |
| |
Compyx
Registered: Jan 2005 Posts: 631 |
Wow, that's all you need? :) |
| |
Taskmaster Account closed
Registered: Feb 2018 Posts: 22 |
That's really cool! Complex but cool.
I actually understand what's going on there so that's a good sign.
Kick has a lot of power, apparently. Thanks for that, I'll give it some thought. :) |
| |
Taskmaster Account closed
Registered: Feb 2018 Posts: 22 |
I've been trying to build on that awesome example by Digger. I'm stuck on something I'm sure is simple but I don't know enough about Kick scripting yet.
How can I create a string and then drop it into the source code, as if I had typed it? You know, for dynamic labels and things like that?
Take this code...
.macro DeclareIt( _name_ )
{
lda #0
rts
.eval _name_ + "_Var:"
.byte 0
}
Main:
DeclareIt( "MyMacro" )
lda MyMacro_Var
rts
What I want is for "MyMacro_Var:" to become a real label but while I can build the string, I can't drop it into the source for compilation ...
What am I missing? |
| |
Taskmaster Account closed
Registered: Feb 2018 Posts: 22 |
What I'm getting at is, once this expands out and hits the assembler, I want it to look like this:
lda #0
rts
MyMacro_Var:
.byte 0
lda MyMacro_Var
rts
(NOTE : yes, the code is total nonsense, I'm just trying to get a successful compilation at this point)
:) |
| |
Digger
Registered: Mar 2005 Posts: 437 |
Been trying to ask Mads aka Slammer exactly about the same! ;-) |
| |
Taskmaster Account closed
Registered: Feb 2018 Posts: 22 |
Haha, well, please report back if he helps you. :) |
| |
Digger
Registered: Mar 2005 Posts: 437 |
You can target macro vars with dot, i.e. LDA MyMacro._Var AFAIR ;-) Don’t need dynamic labels for that. |
| |
Taskmaster Account closed
Registered: Feb 2018 Posts: 22 |
Right, but my question isn't about that.
I want to dynamically create, say, label names from strings being passed in.
Like ...
DeclareIt( "MyMacro" )
DeclareIt( "MySecondMacro" )
DeclareIt( "MyMacroThird" )
Gives me 3 macros using that base string as the root of their names and variable labels. Essentially, using the scripting language to generate source code from what is effectively a template ...
Does that make sense? |
| |
Oswald
Registered: Apr 2002 Posts: 5094 |
Quote: Right, but my question isn't about that.
I want to dynamically create, say, label names from strings being passed in.
Like ...
DeclareIt( "MyMacro" )
DeclareIt( "MySecondMacro" )
DeclareIt( "MyMacroThird" )
Gives me 3 macros using that base string as the root of their names and variable labels. Essentially, using the scripting language to generate source code from what is effectively a template ...
Does that make sense?
describe what your ultimate goal is maybe there is a simpler better another solution to it. |
Previous - 1 | 2 | 3 - Next |