6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Sat Nov 16, 2024 6:49 pm

All times are UTC




Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: Fri Aug 12, 2022 8:37 am 
Offline

Joined: Wed Feb 17, 2021 6:54 am
Posts: 69
Like the ORG (or *=) in assembly, is there anything similar for C, to specify that from this point on, start compiling opcodes at this address, until it is specified again later?

(I am of course experimenting with C for 65xx)


Top
 Profile  
Reply with quote  
PostPosted: Fri Aug 12, 2022 9:24 am 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10981
Location: England
If you’re using cc65 then it’s the linker which puts code at addresses - check your machine description or linker control script or command line.


Top
 Profile  
Reply with quote  
PostPosted: Fri Aug 12, 2022 3:47 pm 
Offline
User avatar

Joined: Sun Jun 30, 2013 10:26 pm
Posts: 1949
Location: Sacramento, CA, USA
There definitely is a method to bind a hard-coded address to an ISR or an I/O port using a somewhat convoluted cast, but I haven't done so in over 30 years, and the details elude me at the moment (the applicable program listings are stashed somewhere in my attic).

_________________
Got a kilobyte lying fallow in your 65xx's memory map? Sprinkle some VTL02C on it and see how it grows on you!

Mike B. (about me) (learning how to github)


Top
 Profile  
Reply with quote  
PostPosted: Fri Aug 12, 2022 5:30 pm 
Offline
User avatar

Joined: Sun Nov 07, 2021 4:11 pm
Posts: 101
Location: Toronto, Canada
It might be helpful if you could tell us a bit more about what you're trying to do.

One possible solution is to use a trampoline written in a separate assembler file, where you can specify the origin, that simply jumps to the address of your C function; that way, you can just rely on the the linker to figure out where your code should go.

So if you have this code in, say, myfunc.c:
Code:
void __fastcall__ myFunction()

You could write something like this (from memory and untested, but hopefully you get the gist) in myfunc_trampoline.s:
Code:
.proc _myFunctionTramponline:
  .org $C000
  jmp _myFunction
.endproc

The problem, however, is that defining the origin of any piece of code doesn't mean that it will be automatically relocated there when loaded from media; it just makes the compiler generate code that is pinned to a specific location for the purpose of calculating absolute addresses. It is then your responsibility (or your OS's, if it supports dynamic loading) to place it in a particular location in memory.

Hope this helps!


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC


Who is online

Users browsing this forum: John West and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: