Hello,

I'm working on a C++ application that executes binary files, so I'm using NASM to create them.
Example:

org 0 ; I don't know this value yet

start:

jmp start

Since I will execute that code later, I don't know the start address (ORG) at this time.
Is there any program that allows me to change the start address by patching the whole file afterwards?

Thanks in advance,

Phoenix10010

ORG just leaves empty space before the assembled hex. So if you just code your stuff in NASM and then later want to place your C-code before, your can use the DOS-Funktion copy (cp in UNIX?). This function merges two files (your c-bin and your asm-bin). You don't have to bother about the length of one of the files.

Hello,

thanks for your answer.

I'm loading the binary file into dynamically allocated memory at run time and execute it, but when I want to use variables (e.g. db str "Text", 0), the program doesn't know where they are stored (org 0).
Since I'm using dynamic memory, the addresses may change any time. Jump instructions work fine, though.

Phoenix10010

okay.
you have to export the offsets of each var. You can do it with a macro (does NASM hav a direct way to do so?) that does basically:
-> get called at the top of the file with the pointer to the var parsed
-> just saves 4Bytes for the Pointer

You can then write a function in C that reads the vector-table and accesses the data.