News: 11 March 2016 - Forum Rules
Current Moderators - DarkSol, KingMike, MathOnNapkins, Azkadellia, Danke

Author Topic: How do I locate rom offsets by looking at just source code?  (Read 1049 times)


  • Jr. Member
  • **
  • Posts: 52
    • View Profile
How do I locate rom offsets by looking at just source code?
« on: April 10, 2020, 09:13:20 pm »
Is it possible for me to look at the source code of a game, such as SMB Disassembly, and by looking at the source code, identify the rom offset after it is compiled?

I would like to do this without need to refer to extra documents or having to recompile it multiple times to keep checking.

For example, on line 13474:

      .byte $76, $77, $78, $79 ;regular mushroom

Is there anything that would indicate to me on the source where it's offset would be after it's compiled? Or do I have to compile, hunt for that particular string, and just write it down then?

Thank you!


  • Hero Member
  • *****
  • Posts: 3079
    • View Profile
Re: How do I locate rom offsets by looking at just source code?
« Reply #1 on: April 11, 2020, 07:39:57 am »
When you say source code I would think either leaked stuff (see princess maker), remade stuff (mario 64 or more traditional remake from play/disassembly) or released stuff, the latter of which is in very short supply for console games.
Such things in turn typically involve high level language, or a more developer focused assembly.

Many disassembly projects are straight disassembles, maybe with the resources masked off and some labels for known memory locations. Later ones will often attempt to bring order to the madness and may drop the original byte location - hex value - disassembly equivalent - comment type format in favour or something that might assemble into something meaningful.

If it assembles into something meaningful then yes you can force locations in the assembler for most things, or track them down during it/with debug flags.
In practice though few ROM hackers work anything like that and you were onto the right line, though in my case if I am expecting something a bit more variable I will look either side to see if I can find a unique (or near enough that you can check them all) run of instructions that are basic and unlikely to be fiddled with by the assembler/compiler playing optimisation.
If it is high level source code compiled then probably best to not compile fully and play around at the linking stage. Depending upon compiler versions it might line up, or might have changed if said optimisation kicks in (or what level of it is selected).


  • Jr. Member
  • **
  • Posts: 39
    • View Profile
Re: How do I locate rom offsets by looking at just source code?
« Reply #2 on: April 12, 2020, 10:09:49 am »
Some assemblers can generate a list of all labeled addresses, called e.g. a label file or dbg file. You can assemble the project and check the label file directly.

In the general case, for all but the simplest assemblers, it's not possible to know what address a label will have without assembling the entire project. I think knowing this would be equivalent to solving the halting problem.