Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

What does .section do in Assembly file?

Status
Not open for further replies.

arvind053

Newbie level 4
Newbie level 4
Joined
Jun 23, 2004
Messages
7
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
69
.section .reset,4,1,6

I have the following code snippet in my Assembly file (.asm file) :

.section .reset 4,1,6 # Put this code in ".init" section

Can anyone tell me what this means ?

When I compile with this I get the following Warning:

No linker command file input for section .reset. .reset will be input for output section .init

Thanks
 

Re: What does .section do ?

A .section directive is used to tag bits of code (following the directive upto the next .section) with a section name. The linker will collect all code in a particular named section together, so it is concatenated into one area of memory, and the linker is usually given a command file which tells it which sections to combine, the properties of each section (code, read-only, read-write, initialised,...), and where/which order to put them in the binary generated by the linker. When you compile and link on Windows/Linux/.., the compiler driver generates thr linker command file automatically (or generates sections corresponding to the linker defaults), so that the linker produces the what the c startup code expects.

In your case, it appears that the linker is doing what you want (because it is putting the .reset section with the .init section). If you want to eliminate the warning, you should either change the section name in the directive to .init, or tell the linker to combine the .reset section with the .init section. How you do this depends on your linker: you need to RTM.

For it to work sensibly, if you are collecting code into a section you need to make sure that each tagged part it is complete function with start and return, because the linker will simply concatenate the bits of code tagged with one name together in some arbitrary order. While this would be fine for data, it isn't a generally a successful strategy to assume that a randomly assembled sequence of little bits of code will always work together correctly.

Assuming this is going to be put into ROM, something like the .init section should probably have code located at wherever your processor reset vector is, setup hardware, and either start your RTOS or jump to your c initialisation routine then to main().

HTH
Barny
 

Re: What does .section do ?

Hi barny451,
I say, can you share your knowledge of Assembly programming or point us to some location? I had to deal with assembly some weeks back and it made my head spin. Can you tell me if there is a single format of assembly now in vogue? (I always thought that assembly instructions were different for different CPUs)?
 

Re: What does .section do ?

I don't have a specific pointer, but a quick google for .section assembler leads to, for example:

http://publibn.boulder.ibm.com/doc_link/en_US/a_doc_lib/aixassem/alangref/csect.htm

which describes the csect directive which appears the same as .section. Read and learn.

In most cases you won't need to worry about sections, put everything in the default section by not specifying one. Times when you do need to worry are possibly e.g. wen combining assembly with C/C++, when specifying startup code which has to be linked at a particular address, when defining data which has to be at specific addresses (e.g. to initialise interrupt vectors).
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top