How to compile assembly instructions i LPCXpresso IDE

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

How to compile assembly instructions i LPCXpresso IDE

6,112 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by bonystedt on Fri Feb 05 05:19:43 MST 2010
I'm reading Joseph Yiu's "The Definitive Guide to the ARM Cortex-M3", in the hope that understanding assembly language could make me a better C programmer, when it comes to debugging, writing of I/O routines and so on. And as a pensionist I also have the time for it.
Now to the problem; because I mainly will develop My Cortex-M processors in C, I don't want to spend to much time reading manuals about how to compile Thumb assembly instructions. I just want to find and use a simple (not costly) assembler compiler to put  Joseph Yiu's examples into and learn from playing around with the resulting binaries onto my  LPCXpressos.
Can anybody tell if it's possible to do what I want with  LPCXpresso IDEs, and if so, how to do it. I have tried a lot and I have searched in this forum without results. I have also tested evaluation software like TextPad, CrossStudio for ARM 2.0, ARM Workbench IDE v4.0, and Sourcery G++ Lite Edition. I find them not optimal for my needs.
Can anybody give me a hint? Of special interest for me would a LPCXpresso IDE solution be. Thank you.
0 项奖励
回复
17 回复数

5,439 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by igorsk on Tue Feb 09 16:00:48 MST 2010
The basic difference is that M0 implements Thumb from ARMv6-M which has only 16-bit instructions (with the exception of BL/BLX), while M3 is ARMv7-M with Thumb2 which has equivalents for the vast majority of ARM instructions. M3 also has IT instruction to implement ARM-like conditional execution and nice things like table jumps and hardware divide.
0 项奖励
回复

5,439 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by ktownsend on Tue Feb 09 07:10:30 MST 2010

Quote: CodeRedSupport
These are differences in the instruction set between cm0 and cm3. I don't know of any document that describes these things in the way that you are expecting.

The instruction sets are defined in the architecture reference manuals available from the NXP (or ARM) website.



You'll want to look at the reference manuals on the ARM website ... I doubt there's anything from NXP since it isn't really them developping the cores/command-sets.

There is some helpful information on the differences between the M3 and the M0 discussed in this book, though, which is a good starting point (I'm using the second edition which discussed the M0 ... I don't think the first edition addressed this):

http://www.amazon.com/Definitive-Guide-ARM-Cortex-M3-Second/dp/185617963X/ref=sr_1_1?ie=UTF8&s=books...
0 项奖励
回复

5,439 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by CodeRedSupport on Tue Feb 09 04:45:42 MST 2010
These are differences in the instruction set between cm0 and cm3. I don't know of any document that describes these things in the way that you are expecting.

The instruction sets are defined in the architecture reference manuals available from the NXP (or ARM) website.
0 项奖励
回复

5,439 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by bonystedt on Tue Feb 09 04:10:07 MST 2010

Quote: bonystedt
Perfect! It makes really fun to learn this special Thumb. Thanks!


I see there are essential differences between the assembler code used in M3 compared to what's working in M0.
I would be very interested in getting a tip where to read about these differences in detail, while I'm interested in using both MCUs. Something that explicitly deals with these diffs and why the solutions to get around are chosen. Thanks.
0 项奖励
回复

5,439 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by bonystedt on Mon Feb 08 14:27:06 MST 2010

Quote: CodeRedSupport
Note that the cortex-m0 intruction set is a subset of cortex-m3. Therefore, if you are trying to use examples for Jo Yiu's book, bewere that some of them are not going to work on a cortex-m0.

Here is the cortex-m0 equivalent project. The main things are:
- the project type is now set to LPC1114 (to change, ctrl-click on the type in the bottom right corner of the IDE)
- different instructions in the asm


Perfect!  It makes really fun to learn this special Thumb. Thanks!
0 项奖励
回复

5,439 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by CodeRedSupport on Mon Feb 08 11:45:37 MST 2010
Note that the cortex-m0 intruction set is a subset of cortex-m3. Therefore, if you are trying to use examples for Jo Yiu's book, bewere that some of them are not going to work on a cortex-m0.

Here is the cortex-m0 equivalent project. The main things are:
- the project type is now set to LPC1114 (to change, ctrl-click on the type in the bottom right corner of the IDE)
- different instructions in the asm
0 项奖励
回复

5,439 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by bonystedt on Mon Feb 08 10:56:39 MST 2010

Quote: bonystedt
Thank you very much. Seems to be exactly what I needed. Will come back with more comments (praise of the your Support I hope) after testing.



I have only a LPCXpresso1114 board with M0. It's not possible to write ".cpu cortex-m0", what I suppose is necessary to get it working on my board. By the way it compiles and a binary is built when I don't change your code with .cpu cortex-m3.
Of course i run into problems later on but it starts well anyway.
So, please tell me how to adapt to the right cpu?
0 项奖励
回复

5,439 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by bonystedt on Sat Feb 06 05:14:50 MST 2010

Quote: CodeRedSupport
OK.

Attached is a very simple project that contains an application that has a sum function written in C and an equivalent written in assembler.

To get this into your workspace, save the attachment and then
Quickstart/Import and Export/Import archived projects
Browse to the zip file
Finish



Thank you very much. Seems to be exactly what I needed. Will come back with more comments (praise of the your Support I hope) after testing.
0 项奖励
回复

5,439 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by CodeRedSupport on Sat Feb 06 04:40:30 MST 2010
OK.

Attached is a very simple project that contains an application that has a sum function written in C and an equivalent written in assembler.

To get this into your workspace, save the attachment and then
Quickstart/Import and Export/Import archived projects
Browse to the zip file
Finish
0 项奖励
回复

5,439 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by LPCVictoria on Fri Feb 05 19:11:37 MST 2010

Quote: CodeRedSupport
I am completely confused as to what you are trying to do...

There are 2 ways to write assembler instructions:
- using asm{} blocks in the compiler
- writing a whole assembler module, that is built using the assembler

Regardless of which way your write it, that is exactly what will be generated in the code. There is no "assembler compiler".

You can read about asm blocks in the help. Help->Contents and search for asm



Hi-

Is the problem a confusion of "( )" parentheses with "{ }" curly brackets? 
Above you say asm{}, but the OP used:

Quote:

void test(unsigned int a, unsigned int b)
{
   asm(“.syntax unified”);
   asm(“muls r3,r2;”);
}



David
0 项奖励
回复

5,439 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by CodeRedSupport on Fri Feb 05 10:07:49 MST 2010
I am completely confused as to what you are trying to do...

There are 2 ways to write assembler instructions:
- using asm{} blocks in the compiler
- writing a whole assembler module, that is built using the assembler

Regardless of which way your write it, that is exactly what will be generated in the code. There is no "assembler compiler".

You can read about asm blocks in the help. Help->Contents and search for asm
0 项奖励
回复

5,439 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by bonystedt on Fri Feb 05 09:53:22 MST 2010
Sorry, but I think you at Code_Red Support have not understood what I want.
I 'm interested in – if possible with LPCXpresso IDE – seeing what the assembler compiler generates, when I have written the instructions myself!
I already been looking the whole week long at compiler output from code written in C in the examples accompanying the LPCXpresso pack, so I have seen enough of what the compiler generates, thank you.
I just want to know, if possible with LPCXpresso IDE, how to do it myself.
I have tried this from “whiteco's” post to “Audiomonster” 01-04-2010, 03:46 PM :
<<Now I try to do the same, directly.
<<void test(unsigned int a, unsigned int b)
<<{
<< asm(“.syntax unified”);
<< asm(“muls r3,r2;”);
<<}
But it did not build for me, either!
Any ideas from Code_Red Support?
By the way, where to read more about __asm() or asm() commands?
0 项奖励
回复

5,439 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by CodeRedSupport on Fri Feb 05 09:18:17 MST 2010
It is created when you use the wizard to create an LPC13xx project

Quickstart Panel
  Project and File Wizards
    MCU project Wizards
       NXP LPC1300 project templates
           Create NXP LPC1300 project
0 项奖励
回复

5,439 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by bonystedt on Fri Feb 05 08:30:20 MST 2010
I feel ashamed, but can you please explain the real name and path to lpc13 startup file:
__asm{
...
}.
I have the feeling that everybody but me, knows where to find this so called startup file. But that's how it is.
Thanks for the Home>>LPCXpresso Software Knowledgebase (note29) tip.
0 项奖励
回复

5,439 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by CodeRedSupport on Fri Feb 05 07:59:28 MST 2010
Sorry - look at the lpc13 startup file:
__asm{
...
}

If you *really* want to do everything in assembler, then maybe a good place for you to start would be to see what the compiler generates. See
http://lpcxpresso.code-red-tech.com/LPCXpresso/node/29
(login required).

The tools will automatically call the assembler for any file ending in ".s"
0 项奖励
回复

5,439 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by bonystedt on Fri Feb 05 07:21:47 MST 2010
Stacking and unstacking of registers, passing arguments as well as providing all the assembler pre-amble is exactly what I want to do. So what I'm asking for is examples (understandable) of how to do this. Examples that compiles in LPCXpresso. So if you could be so kind and give me a hint where to find them, I sould be very grateful to Code Red.
I'm sorry, but I don't understand what you mean by directing me to the startup.c files. If you by that mean, for example the cr_startup_lpcx11.c file in the adc project, I can't see any example of how to use inline assembler. For my eyes it's plain C. But perhaps I didn't understand you.
Sorry!
0 项奖励
回复

5,439 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by CodeRedSupport on Fri Feb 05 05:34:20 MST 2010
Programming in assembler is supported in LPCXpresso.

You can either write an entire module in assembler, or you can just use inline assembler within a C module.

The disadvantage of writing your assembler as a whole module is that you have to write your code to obey the procedure call standard (stacking and unstacking of registers, passing arguments etc.). You also have to provide all the assembler pre-amble (setting up sections, defining the syntax to be used, etc etc.)

If you write your code in the inline assembler within a C function, the compiler will handle all of that for you - you just write the assmbler instructions you want.

We have been using Cortex-M processors for a couple of years now, and we VERY rarely write whole modules in assembler. We just write inline assembler, and even then we only do it if we want to provide a highly optimized function.

To see an example of using the inline assembler, see one of the startup.c files in the examples.
0 项奖励
回复