User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Assembly section within the Software Development category of DaniWeb, a massive community of 423,333 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 5,234 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Assembly advertiser: Programming Forums
Views: 510 | Replies: 3
Reply
Join Date: Jun 2008
Posts: 2
Reputation: Phoenix10010 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
Phoenix10010 Phoenix10010 is offline Offline
Newbie Poster

ORG Instruction (NASM)

  #1  
Jun 27th, 2008
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
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Aug 2005
Location: Cologne, Germany
Posts: 108
Reputation: sDJh is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 9
sDJh sDJh is offline Offline
Junior Poster

Re: ORG Instruction (NASM)

  #2  
Jun 27th, 2008
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.
Reply With Quote  
Join Date: Jun 2008
Posts: 2
Reputation: Phoenix10010 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
Phoenix10010 Phoenix10010 is offline Offline
Newbie Poster

Re: ORG Instruction (NASM)

  #3  
Jun 27th, 2008
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
Reply With Quote  
Join Date: Aug 2005
Location: Cologne, Germany
Posts: 108
Reputation: sDJh is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 9
sDJh sDJh is offline Offline
Junior Poster

Re: ORG Instruction (NASM)

  #4  
Jun 28th, 2008
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.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb Assembly Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Other Threads in the Assembly Forum

All times are GMT -4. The time now is 11:36 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC