Getting address of ASM routine by label in C code

Post Reply
sgjava
Member
Posts: 22
Joined: Thu Feb 22, 2024 9:25 pm

Getting address of ASM routine by label in C code

Post by sgjava »

I've built an application that uses Z80 IRQ (C128 raster IRQ) to do a split screen. I'm wondering if there's a way to get the address of a ASM label? Right now I scan for the code signature:

https://github.com/sgjava/c3lz/blob/049 ... plit.c#L23
https://github.com/sgjava/c3lz/blob/049 ... plit.c#L67

Which is kind of clumsy and brute force. The ASM function sets configuration values used by the IRQ code, but to kick it off I need to call:

https://github.com/sgjava/c3lz/blob/049 ... cr.asm#L74
https://github.com/sgjava/c3lz/blob/049 ... mo_i.c#L45

So basically I'd like to get irq1 label address without having to scan for a code signature.
User avatar
dom
Well known member
Posts: 2140
Joined: Sun Jul 15, 2007 10:01 pm

Re: Getting address of ASM routine by label in C code

Post by dom »

My usual way is this:

* Rename irq1 to _irq1
* Make _irq1 PUBLIC
* extern void *irq1;
* Use &irq1

Fiddle with casts to get rid of the warnings as desired.
sgjava
Member
Posts: 22
Joined: Thu Feb 22, 2024 9:25 pm

Re: Getting address of ASM routine by label in C code

Post by sgjava »

Cool, I'll try that, thank you.
User avatar
dom
Well known member
Posts: 2140
Joined: Sun Jul 15, 2007 10:01 pm

Re: Getting address of ASM routine by label in C code

Post by dom »

But actually in this case it's a bit simpler, the final steps (3,4) can be:

Code: Select all

extern void irq1(void);
And then just use irq1 as you'd expect to.
Post Reply