views:

72

answers:

1

Hi, I have a question about how to store the assembly language in memory,when I compile the C-code in assembly, and run by "step", I can see the address of each instruction, but is there a way to change the start address of the code in the memory?

Second question is, can I break the assembly code into two? That is, how to store the two parts in separate memory sections? is there a way to do that?

I am curious about how the machine store the assembly code. BTW, I am working on a MACBOOK Pro, duo core. /////////////////////

Thank you, Michael! For the first question, can we change the offset value? or the linker and loader can not be controlled by the user? I am a litter confuse with your answer, it seems that we can not change it?

For the second question,I think what you are talking about is "input section", even if your have many ".text" input sections in your codes, after being assembled, they will become one ".text" "output section". And the output section is the actual code stored in memory. And I am wondering if I can control its position.

I think my question is a little tedious, but hope you can help me understand this. I am using the knowledge of DSP assembly, I think the mechanisms are same.

Thank you.

-da /////////////////////

Thank you. -da

A: 

I'm not completely following either of your questions, but I'll guess.

For the first one, you're asking how to change where the executable is positioned in memory? ELF files have a preferred offset that the linker will try to use first, but the loader is usually free to position the sections anywhere if the base offset isn't available. If the image is non-relocatable and the preferred offset is unavailable, the loader will fail and the program won't run

As for your second question, you want to modify the assembly so code will be in different sections? How to do that depends on the assembler you're using; in gas you use the section pseudo-op:

.section new-section-name

The code following that directive will be in the specified section

Michael Mrozek
Hi Michael Mrozek,Seems the Comment has constraints on words limit.I have put my doubt on my original post, hope you can explain.Thank you.
da cheng