Basically I'm going into my final year and an interesting proposed project idea was to create a cross assembler in C++ for Arm Cortex M-

All the information on the web states how to cross compile in C++ for arm but not how/where the source code is for the cross compiler itself.

What specifics should I be searching for? And do you have any tips to avoid major trip ups?

Thanks in advance!

有帮助吗?

解决方案

Assuming you just want to write an ARM Assembler in C++, since being cross compiling would just depend on where you would compile that project. Here are some pointers.

First you need to decide on the syntax. It is best to use an existing one since that

  1. will make your work easier
  2. provide users who already are used to that
  3. can verify your project using existing tools. Like you can use a standard compiler to produce assembly for a piece of snippet and run your own assembler to produce a binary out of that.

Concluding from these, I would use GNU's syntax, just focusing on ARM part and leaving out other bits.

Then you need to write a parser for that syntax. You can use a parser generator but on the other hand if might be just easier to write one hand crafted yourself since assembly syntax isn't that complicated except some cases.

If you can finalize a parser, then you need to be able to take in all instructions and encode them into write binary values. You also need to take care of supporting language structures like being able to save a string or any data somewhere in your app and allowing instructions to act on that (address).

As last part if you want to produce standard binaries you need to study and be able to produce binaries in that form so other systems like loaders, operating systems can use binary produced by your assembler successfully.

其他提示

The equivalence of a cross*assembler* would be GAS compiled (on host H) to run on target X, but assemble code for target Y.

GCC is your implementation language of your assembler. But since your cross assembler will probably run on the same platform as the GCC++, it is just like any program. The program merely generates foreign asm.

Cross compilers are commonly based on GCC and binutils. I think these two guides might be helpful:

http://sourceware.org/ml/crossgcc/2005-08/msg00114/l-cross-ltr.pdf

http://www.rockbox.org/wiki/CrossCompiler

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top