Author Topic: Assembler tools for CB  (Read 28671 times)

Offline scarphin

  • Lives here!
  • ****
  • Posts: 644
Assembler tools for CB
« on: March 07, 2014, 10:08:32 pm »
There has been an ongoing discussion about assembler tools for CB in the topic:
http://forums.codeblocks.org/index.php/topic,19026.msg130238.html#msg130238

A fork named emblocks claims to have some good features which I think can be summarized below:
1- Assembler options (a tab dedicated to assembler options next to compiler and linker) to pass assembler specific options directly to assembler (i.e as).
2- Native assembler support to edit (syntax highlighting would be nice) and assemble the assembly files (.s, .S, .asm whatever) with designated options from feature 1 maybe by intervening between the compiler and linker and then let the linker link them all. As far as I know gcc compiles c/c++ files into assembly first then lets the assembler do its job so this feature doesn't look much unnatural at all. ;)

These 2 options would be a nice enhancement to cb imo, so here they are to discuss.

Offline stahta01

  • Lives here!
  • ****
  • Posts: 6546
    • My Best Post
Re: Assembler tools for CB
« Reply #1 on: March 07, 2014, 10:35:00 pm »
Another thing the E::B has is a location in the tool chain setting for the hex tool.
The hex tool is needed by many Embedded Compilers.

Hex tool converts object code (Binary) to hex code (ASCII).
Link to images http://community.silabs.com/t5/32-Bit-Discussion/Em-Blocks-IDE-with-EnergyMicro-support/td-p/107147

I think adding the assembler and hextool to the toolchain.
Along with the assembler options would be a good idea.

I have download the open source part of E::B; will look at the SDK changes needed to do the above items I posted.

Tim S.
« Last Edit: March 07, 2014, 10:58:03 pm by stahta01 »
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 32 bit.
On Debian Stretch, compiling CB Trunk against wxWidgets 3.0.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 11820
    • Travis build status
Re: Assembler tools for CB
« Reply #2 on: March 07, 2014, 10:41:25 pm »
As far as I know we have syntax highlight for asm files.
Syntax highlight is a job of scintilla, so if your asm variant isn't supported then post a bug report to them.
After they make a lexer for it we can easily expose it in the options.
If it is supported by scintilla and it is not exposed, please say so and I'll expose it (it is pretty trivial task).

About separate options:
What king of options?
Do you want to have check boxes with the most common options?
We could probably add another tab in Build options -> Compiler settings (next to the tab "Other options").
How often do you edit asm files by hand in the embedded world?
In the desktop/server world people (almost) never need to do it.

As far as you probably know it is not problem to add asm files to the build system http://wiki.codeblocks.org/index.php?title=Adding_support_for_non_C/C%2B%2B_files_to_the_build_system
Probably we can add asm support for specific compilers in the trunk version of C::B.
Can you provide patches for the compilers you're using?
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 11820
    • Travis build status
Re: Assembler tools for CB
« Reply #3 on: March 07, 2014, 10:47:15 pm »
Adding the hextool would be a bit more complex and would require more options as far as I can see.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline stahta01

  • Lives here!
  • ****
  • Posts: 6546
    • My Best Post
Re: Assembler tools for CB
« Reply #4 on: March 07, 2014, 11:04:09 pm »
oBFusCATed is likely right in the amount of work for only a small gain might be the result.

So, I will look at the features wanted and how easy it is to solve the problem in another way.

The ToolPlus plugin could likely do the hex convertor operation.

And, a special file property would likely be enough to set assembly file options.

Tim S.
 
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 32 bit.
On Debian Stretch, compiling CB Trunk against wxWidgets 3.0.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline scarphin

  • Lives here!
  • ****
  • Posts: 644
Re: Assembler tools for CB
« Reply #5 on: March 08, 2014, 12:14:56 am »
Another thing the E::B has is a location in the tool chain setting for the hex tool.
The hex tool is needed by many Embedded Compilers.

Hex tool converts object code (Binary) to hex code (ASCII).
Link to images http://community.silabs.com/t5/32-Bit-Discussion/Em-Blocks-IDE-with-EnergyMicro-support/td-p/107147
I think inclusion of the hex tool won't be a good idea because it doesn't have a standard among compilers. Take AVR for example, there are many post processing steps to separate the object file (.elf) into output files program, eeprom, fuses, lock bits, signature etc... That is not the case for i.e. PICs so how would the hex tool behave for each compiler will complicate the things much more than it should imo. I vote on post processing for hex tool.

As far as I know we have syntax highlight for asm files.
Syntax highlight is a job of scintilla, so if your asm variant isn't supported then post a bug report to them.
After they make a lexer for it we can easily expose it in the options.
If it is supported by scintilla and it is not exposed, please say so and I'll expose it (it is pretty trivial task).
I think that would be more than enough for the editor support of assembler files.

About separate options:
What king of options?
Do you want to have check boxes with the most common options?
We could probably add another tab in Build options -> Compiler settings (next to the tab "Other options").
How often do you edit asm files by hand in the embedded world?
In the desktop/server world people (almost) never need to do it.
For separate options I was thinking about the lines of assembler flags (yeah checkboxes would be nice) to be inserted directly into the assembler command line.
For the tab position why not add it next to 'Compiler settings' and 'Linker settings' as 'Assembler settings' in 'Build options'? It would be nice to make use of flags, other options and defines for the assembler too just as the compiler.
I edit assembler files for a couple of reasons in my embedded work. First to see what the compiler is generating in case I suspect a compiler bug, second to create optimized routines in case I am in a very narrow time window to perform that routine, third to code general purpose hand optimized libraries specific to my needs. These are some usages I can think of in the first place but as I mentioned in the other topic, I don't think assembler usage is that little in the desktop world judging by the fact that even I know a couple of assembler gurus from school and work despite me being a no desktop programmer at all. ;)

As far as you probably know it is not problem to add asm files to the build system http://wiki.codeblocks.org/index.php?title=Adding_support_for_non_C/C%2B%2B_files_to_the_build_system
Probably we can add asm support for specific compilers in the trunk version of C::B.
Can you provide patches for the compilers you're using?
I am aware of that method to add support for non C/C++ files in the build system and I've been using it if needed. But I don't think that would be a comparison to native support of assembler files because it is hard to use and customize.
Please forgive my ignorance, what kind of patches do you need and for which compilers? Patches for compilers that have an assembler included?

Offline stahta01

  • Lives here!
  • ****
  • Posts: 6546
    • My Best Post
Re: Assembler tools for CB
« Reply #6 on: March 08, 2014, 01:10:31 am »
I am looking at the E::B SDK (modified from CB SDK).

Thinking of trying a patch to add these things.

ASM
ftAssembler
ctAssembleObjectCmd
$assembler

Those are in 14 files in the SDK, 2 in the src folder, and 1 script binding file.

I figure all the other possible changes will require this one; that looks bigger than I would have guessed.

Tim S.
« Last Edit: March 08, 2014, 01:21:01 am by stahta01 »
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 32 bit.
On Debian Stretch, compiling CB Trunk against wxWidgets 3.0.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 11820
    • Travis build status
Re: Assembler tools for CB
« Reply #7 on: March 08, 2014, 01:35:20 am »
@scarphin:
1. Is syntax highlighting working for your assembler files or not? Does scintilla support them?
2. I'd prefer to give you just a field where you can type all the options for assembler compilation, everything else seems, too complex. Also there are too many tabs in this dialog already.
3. Do you need to specify different linker flags for the asm files?
4. Desktop people use inline asm or intrinsics. (Almost) No one would bother to write pure asm for more then couple of routines in a project.
5. The options for every compiler are stored in options_*.xml files. I thought that it would be possible to add the asm commands there, but looking at the code this is not the case. So a modification is needed.

@alpha01: Am I correct about 5 or not?
@stahta01: The compiler/sdk in E::B is probably using the old non generic/xml based compilers, so patches taken from there won't work.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline scarphin

  • Lives here!
  • ****
  • Posts: 644
Re: Assembler tools for CB
« Reply #8 on: March 08, 2014, 04:16:47 am »
@obfuscated:
1- Syntax highlighting can only distinguish comments, numbers and punctuation (equal sign, comma etc...), I don't get a special color on keywords if that's what you are asking. I never delved into this as it's clear that every mcu's assembler is specific to itself. I do get syntax highlighting for assemblers on the list at 'settings->editor->syntax highlighting->syntax highlighting for', masm for example. Btw I found the link below that makes it possible to introduce other languages to notepad++:
http://sourceforge.net/apps/mediawiki/notepad-plus/?title=User_Defined_Language_Files#P
2- Assembler compilation options would be a good start but I believe locating the assembler settings tab under the compiler settings tab will make it look like assembly step is a sub-process of compilation step, don't you think?
3- I didn't need to but I've never done any C++ work with any embedded compiler either. So I can't judge on this.
4- I completely agree but it's that a couple of routines that makes the usage. ;)
5- I think you're right.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 11820
    • Travis build status
Re: Assembler tools for CB
« Reply #9 on: March 08, 2014, 09:18:06 am »
1. We have something similar. See here http://wiki.codeblocks.org/index.php?title=Creating_a_custom_lexer_for_Code::Blocks_editor
2. I don't think, so. Probably we should even make it the same for C and C++ (add separate tabs for them).
3. I think that if you need to you can pass the settings in the current options. Because I suppose that the asm file will be compiled to object file (.o) and then linked as other object files in a single commands. So I don't think there will be a need for it.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline stahta01

  • Lives here!
  • ****
  • Posts: 6546
    • My Best Post
Re: Assembler tools for CB
« Reply #10 on: March 08, 2014, 12:49:57 pm »
@stahta01: The compiler/sdk in E::B is probably using the old non generic/xml based compilers, so patches taken from there won't work.

I agree, I am just looking for the files that needed changed in the SDK/src.
I would guess the same files still need changed; maybe, in different ways.

Edit: Decided adding assembler support is premature; will work on adding $device support to C Compiler instead.
http://forums.codeblocks.org/index.php/topic,19044.msg130362.html#msg130362

Tim S.
« Last Edit: March 10, 2014, 03:15:56 pm by stahta01 »
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 32 bit.
On Debian Stretch, compiling CB Trunk against wxWidgets 3.0.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org


Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 11820
    • Travis build status
Re: Assembler tools for CB
« Reply #12 on: March 09, 2014, 07:51:45 pm »
This is already supported Debug -> Debug windows -> Disassembly and enable the Mixed mode.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 2370
Re: Assembler tools for CB
« Reply #13 on: March 09, 2014, 08:05:46 pm »
This is already supported Debug -> Debug windows -> Disassembly and enable the Mixed mode.
wow thanks! i somehow missed this!

Offline scarphin

  • Lives here!
  • ****
  • Posts: 644
Re: Assembler tools for CB
« Reply #14 on: March 10, 2014, 04:59:35 am »
@obfuscated:
1- That should be enough to achieve syntax highlighting for assembler files imo. I'll try to implement one when I find the time. There is a slightly bigger problem though. Afaik most gcc based embedded compilers use the same file extension for assembler files (.s, .S) so for different gcc based mcu compilers, assembler file extensions becomes the same. I can think of 2 options here, one being the renaming of the assembler files' extension to something specific to the mcu (which I don't know if it will work but quite probably it will) and second choosing a keyword group somehow. Maybe there is a better option.
2- Separating C and C++ options is a good idea as C/C++ files are compiled and thus fit under compiler settings but assembler files are assembled by assembler into object code thus they don't fit under compiler settings. I get the feeling that you don't want to squeeze the main settings tabs to fit an assembler settings tabs there ;) but I think there are other areas of cb quite cluttered too like right-click menu, tabs in Global compiler settings etc... It's your decision in the end but please be aware that pure assembler projects are not that uncommon in embedded world which involve no compilation at all.
3- Assembler files are always assembled into object files for all gcc-based and most other compilers, no doubt with that. What I had in mind was if the C++ function call conventions would be of trouble or not in the linkage stage.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 11820
    • Travis build status
Re: Assembler tools for CB
« Reply #15 on: March 10, 2014, 10:29:17 am »
1. Do you know if all assembler variants use the same lexer? We could probably add some smarter detection mechanism in the editor.
2. As far as I'm concerned an asm file is compiled to an object file and I don't see how this is different to c++ to object file translation. If there is not conceptual difference then the settings should go in the compiler's tag.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline scarphin

  • Lives here!
  • ****
  • Posts: 644
Re: Assembler tools for CB
« Reply #16 on: March 10, 2014, 01:25:45 pm »
1- I don't know if they all use the same lexer but considering the simplicity of assembler syntax (usually in the form -> label: instruction operand(, operand) ;comment), a specific lexer should perform quite well for another assembler with correct keywords.
2- My point is assembler files are not compiled rather assembled into object files with an assembler but I now see your point. You are thinking in the 'end product' concept and I'm thinking in the 'process' http://nixchun.pixnet.net/blog/post/12331954-basic-introduction---gcc concept. Both are valid imo, just 2 different approaches. But if I needed to look for assembler settings as a first time user, compiler settings wouldn't be the first place I'd look. Maybe that's the reason emblocks maintainer implemented them next to compiler settings.

« Last Edit: March 10, 2014, 01:29:37 pm by scarphin »

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 11820
    • Travis build status
Re: Assembler tools for CB
« Reply #17 on: March 10, 2014, 10:29:08 pm »
1. I'm waiting for you to test and probably provide some missing lexers. Are you willing to do this job?
2. By looking at the E::B screenshot I see that there you can pass defines separately to the ASM compiler (assembler in your term) and C/C++ compiler. Do you need this capability? I think this might be annoying in most cases.
 
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline scarphin

  • Lives here!
  • ****
  • Posts: 644
Re: Assembler tools for CB
« Reply #18 on: March 11, 2014, 03:31:55 am »
1- I'll try. I have some urgent things to do at the moment, I'll let you know if I make progress.
2- I never had to make separate defines for assembler but I can think of many ways assembler programmers can benefit from it especially for debugging and testing. So it would be nice to have this capability imo. May I ask which part do you think is annoying? The implementation or the usage?

Btw do you think extra search paths for assembler under search directories can be implemented too?

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 11820
    • Travis build status
Re: Assembler tools for CB
« Reply #19 on: March 11, 2014, 08:15:58 am »
May I ask which part do you think is annoying? The implementation or the usage?
For me it will be annoying if I have to enter the same defines at two places.

Btw do you think extra search paths for assembler under search directories can be implemented too?
It is possible, but is it needed? The question is same as the one for defines: would they be different than C/C++ ones most of the times?
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline scarphin

  • Lives here!
  • ****
  • Posts: 644
Re: Assembler tools for CB
« Reply #20 on: March 11, 2014, 09:53:38 am »
May I ask which part do you think is annoying? The implementation or the usage?
For me it will be annoying if I have to enter the same defines at two places.
Ok, I got your point. As I previously mentioned, pure assembler projects are not uncommon in the embedded world. Considering that, how convenient it would be to enter the defines to be used with assembler into C/C++ defines? I think that wouldn't be good practice. I agree there may be times to enter same defines in both places but not all the time.

Btw do you think extra search paths for assembler under search directories can be implemented too?
It is possible, but is it needed? The question is same as the one for defines: would they be different than C/C++ ones most of the times?
I think you should consider library paths here. I can't think of a reason why C/C++ and Assembler libraries (or hand-crafted routines) should be kept in the exact same folder. In the current cb implementation, it's impractical and error prone to enter the library paths in the command line for non C/C++ files to assemble the assembler files. So what I do is to copy the library file to the source folder and then include it. If search paths for assembler were available that would be way too much practical and convenient. ;)

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 11820
    • Travis build status
Re: Assembler tools for CB
« Reply #21 on: March 11, 2014, 08:10:22 pm »
What do you mean by pure assembler project? Can you post a listing of an example real-world project?

Because if you have a project made only of asm files, then you can use both defines and search paths for the c/c++.
The only point to have separate options for asm and c/c++ is when you have a mixed source project and you need to specify different options for different files.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline scarphin

  • Lives here!
  • ****
  • Posts: 644
Re: Assembler tools for CB
« Reply #22 on: March 12, 2014, 10:08:20 am »
By 'pure assembler project' I mean a project consisting of only assembler files. By 'listing' do you mean a listing file (.lst)? If yes, there is one with C source in the link below for avr-gcc:
http://www.avrfreaks.net/index.php?name=PNphpBB2&file=viewtopic&t=73133
If you were talking about something else, please elaborate.

Because if you have a project made only of asm files, then you can use both defines and search paths for the c/c++.
Then is there a specific reason not to merge the compiler and linker search paths too?

The only point to have separate options for asm and c/c++ is when you have a mixed source project and you need to specify different options for different files.
Mixed source projects has a percentage in the embedded world, that's the main reason I was asking for assembler support in the beginning.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 11820
    • Travis build status
Re: Assembler tools for CB
« Reply #23 on: March 12, 2014, 08:29:55 pm »
If you were talking about something else, please elaborate.
On unix the command is find <root_of_project> on windows dir /s <root_of_project>. I just want to see a real world project structure. I want to see the layout on disk.

Then is there a specific reason not to merge the compiler and linker search paths too?
Yes, because 99% of the times they are different, because headers and library files are stored in different locations.

Mixed source projects has a percentage in the embedded world, that's the main reasonI was asking for assembler support in the beginning.
Okay.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline scarphin

  • Lives here!
  • ****
  • Posts: 644
Re: Assembler tools for CB
« Reply #24 on: March 13, 2014, 03:19:29 am »
If you were talking about something else, please elaborate.
On unix the command is find <root_of_project> on windows dir /s <root_of_project>. I just want to see a real world project structure. I want to see the layout on disk.
Sry doesn't compute. ;) An assembler library or a mixed source or a project for some other software or...?

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 11820
    • Travis build status
Re: Assembler tools for CB
« Reply #25 on: March 13, 2014, 08:41:52 am »
Something that is common...
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline scarphin

  • Lives here!
  • ****
  • Posts: 644
Re: Assembler tools for CB
« Reply #26 on: March 16, 2014, 04:02:09 am »
Sorry for the delay, been busy. Link below is a TCP/IP stack implementation for AVR mcus.
https://github.com/adamdunkels/uip

Offline stahta01

  • Lives here!
  • ****
  • Posts: 6546
    • My Best Post
Re: Assembler tools for CB
« Reply #27 on: March 16, 2014, 04:49:25 am »
Sorry for the delay, been busy. Link below is a TCP/IP stack implementation for AVR mcus.
https://github.com/adamdunkels/uip


Is that project supposed to have assembly only files in it?
My quick look saw no assembly files.

Tim S.
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 32 bit.
On Debian Stretch, compiling CB Trunk against wxWidgets 3.0.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline scarphin

  • Lives here!
  • ****
  • Posts: 644
Re: Assembler tools for CB
« Reply #28 on: March 16, 2014, 07:01:56 am »
No, I don't think so.

Something that is common...
I just thought he wanted to see the directory structure, nothing special about asm. As far as asm files are concerned, I put them besides the C source files not in a special folder dedicated to them. Only my libraries are in different folders than C libraries.

I'm really puzzled here what he's trying to work out. Obfuscated more info please!

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 11820
    • Travis build status
Re: Assembler tools for CB
« Reply #29 on: March 16, 2014, 02:55:41 pm »
I want to see the structure of a common project, that's it...
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline scarphin

  • Lives here!
  • ****
  • Posts: 644
Re: Assembler tools for CB
« Reply #30 on: March 17, 2014, 05:45:24 am »
Ok. Did the link I provided satisfy you then?