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 > Kick Assembler - Removal of unused code?
2019-02-05 15:04
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....
 
2019-02-05 20:27
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 :)
2019-02-05 21:12
Compyx

Registered: Jan 2005
Posts: 631
Wow, that's all you need? :)
2019-02-06 10:54
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. :)
2019-02-06 12:42
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?
2019-02-06 12:50
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)

:)
2019-02-06 15:44
Digger

Registered: Mar 2005
Posts: 437
Been trying to ask Mads aka Slammer exactly about the same! ;-)
2019-02-06 15:46
Taskmaster
Account closed

Registered: Feb 2018
Posts: 22
Haha, well, please report back if he helps you. :)
2019-02-06 16:44
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.
2019-02-06 16:47
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?
2019-02-06 18:10
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
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
zscs
Flashback
Steve/Laser, Zenith,..
Alakran_64
Paladin/G★P
Scrap/Genesis Project
Guests online: 100
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 Dawnfall V1.1  (9.5)
7 Rainbow Connection  (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 Organizers
1 Burglar  (9.9)
2 Sixx  (9.8)
3 hedning  (9.7)
4 Irata  (9.7)
5 Tim  (9.7)

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