0

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

2
Contributors
3
Replies
6
Views
9 Years
Discussion Span
Last Post by sDJh
0

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.

0

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

0

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.