/var/www/restricted/ssh/stm32/www/stm32circle/ STM CircleOS forum / Assembly on the STM32 cortex-m3

Username:     
Password:     
             

Forum

# 1   2008-03-30 03:33:28 Assembly on the STM32 cortex-m3

graham
Member
Registered: 2008-02-23
Posts: 32

Assembly on the STM32 cortex-m3

This always sets off a hot debate, over which is better, assembly, or C /(pick your personal variant)

Most people are fairly cognizant of the differences, but because more people program in C, the knowledge base available in assembly is annoyingly small, especially for such as these relatively new ARM cortex products.

From the manufacturer's (or in this case the designers(ARM)) point of view, benchmarking is mostly going to happen on code compiled with C, and so the instruction set must work well when the C compiler is written for it.

Certain features, may be great for C, and yet, because they are ultimately there for solving algorithms fast, concisely, and with a minimum of code, the same can often be said for the same processor, but with a non C compiler, or, for low level Assembler.

Among some people, there is a belief that a low level language is beneath them, and a high level language, is one to aspire to.
Certainly, if you want to impress management types, with little technical savy, you may be able to convince them of this theory.

One can put this same theory into a different perspective, by saying that a high level language makes things easy and does most of the work for you, and that with a low level language, you have to do most of the work yourself. This, however, presents a concern to some minority among us, If most of the work is already done for us, then how do we know it's being done properly ? Progressing from this point, you will hear people benchmarking compiler's relative performances, and spouting strange (large) figures for a project's required memory size and processor speed.

Look on manufacturer's websites, and you will see: "does not need to be programmed in assembler"

I think this issue is still critical for those of us who want to make leading edge products, and not merely meet goals set by an administration team.

There are, obviously things that C is quite good at, but it's well known that highest performance comes from processor specific analysis with respect to the required tasks. So, even if your preferred tool is C, now and then, to speed things up, you will need to at a minimum, do some inline assembler.

I once bought a standalone Atmel programmer, and being a curious person, I did a quick look at the PC front end executable file in ASCII format.  Strangely, the exe file had a collection of porn site URLs !

When you use other people's tools, you don't really know what's happening.

I'm still trying to teach myself assembler for the cortex-m3, and it's a frustrating process. Dale Wheat has some on line documents relating to his tests on the Luminary and STM cortex projects, and there is something to be learned from them, but I need more.

For example, looking through the assembly instruction set summary, there branch instructions, but the documentation on stack usage is very sketchy, I can't see obvious ret / return / return from interrupt instructions.

There are branch with link instructions, pop instructions, but I think the closest is the pop registers and PC variant of the POP instruction. This is a RISC processor as I understand it, and I have memories of analysing the AVR instruction set and finding one of the instruction mnemonics was actually a very general instruction, but relating specifically to the PC (program counter)

It used to be normal to tidy these sorts of things up at the ARM/Luminary/ST level, but the closest I can find so far, seems to be a book: ["The Definitive Guide to the ARM Cortex-M3" by Joseph Yiu.], although as I don't have it, I can't say how relevent it is.

As a non C programmer, I look at the very long list of cortex-m3 instructions, and I wonder, how many of them are actually compiled into projects by the current C compilers. We don't always need to use all the features, but a good understanding of the processor makes big differences to code speed and density

Manufacturers are selling their 32 bit products over the 8 bit ones by telling us that we get more MIPs per MHz, but programming in assembler means we do the job in less MIPS anyway ! therefore, a good Assembly programmer can make their project run at lower power than a good C programmer can, in C alone, anyway.

Does anyone know of an on line reference that gives cortex-m3 instruction usage in a format similiar to the olh Motorolla 68HC11 manuals ? i.e. opcode, technical details, example usage, register changes.
?

thanks...
Graham.

Offline

 

# 2   2008-04-08 17:39:57 Assembly on the STM32 cortex-m3

englere
Member
Registered: 2007-12-11
Posts: 11

Re: Assembly on the STM32 cortex-m3

Arm's got a quick reference card with the Cortex M3 instructions. Actually, it's got the Thumb-2 instructions which may include some that aren't supported directly by the M3 variant:

http://infocenter.arm.com/help/topic/co … 01_UAL.pdf

You'll also want the Technical Reference Manual if you don't already have it.

http://infocenter.arm.com/help/topic/co … p1_trm.pdf

I've got to say that they hide this stuff pretty good. The Arm web site has a lot of gold that is hidden behind a terrible menu and search engine.

Also of high interest to assembly language coders is the FFT assembler code that was recently posted in the STM32 forum at the ST website. I don't have a link to the specific message but you can find it easily. I found this code to be easy to follow and it is hand-optimized specifically for the Cortex M3.

http://www.st.com/mcu/forumsid-23.html

Eric

Offline

 

# 3   2008-04-16 06:47:04 Assembly on the STM32 cortex-m3

ThomasScherrer
Member
From: Denmark
Registered: 2007-10-29
Posts: 64
Website

Re: Assembly on the STM32 cortex-m3

>I once bought a standalone Atmel programmer, and being a curious person,
>I did a quick look at the PC front end executable file in ASCII format.
> Strangely, the exe file had a collection of porn site URLs !

prove this please ?


Thomas Scherrer Denmark webx.dk

Offline

 

# 4   2008-04-28 10:13:53 Assembly on the STM32 cortex-m3

graham
Member
Registered: 2008-02-23
Posts: 32

Re: Assembly on the STM32 cortex-m3

ThomasScherrer :

>I once bought a standalone Atmel programmer, and being a curious person,
>I did a quick look at the PC front end executable file in ASCII format.
> Strangely, the exe file had a collection of porn site URLs !

prove this please ?

haha !
It was very embarrasing to the programmer, and was about 6 or 7 years ago.

You will have to track down your own naughty site references in code, I'm not pulling out the specific details to splatter over this forum !

Graham.

Offline

 

# 5   2009-01-07 13:36:49 Assembly on the STM32 cortex-m3

worstell
New member
Registered: 2008-05-31
Posts: 1

Re: Assembly on the STM32 cortex-m3

I use micros from various vendors in my work. Considering adding the ARM cortex family, I find that documentation of the complete instruction set is not to be found - or at least I have not found it in a couple of hours of searching the ARM, STM, and Luminary web sites.

Tis a shame that the micro with the best price and performance is the worst in terms of documentation, compared to the MSP430, Atmel AVR, PIC24, etc etc etc.

Or perhaps I just don't know where to look? Please advise if you are able...

tia,
glen.

Offline

 

# 6   2009-01-07 17:04:18 Assembly on the STM32 cortex-m3

Francis
Administrator
From: France-Grenoble
Registered: 2007-07-09
Posts: 890

Re: Assembly on the STM32 cortex-m3

Search on google for: "ARMv7-M Architecture Application Level Reference Manual"
You will find the ARM page ( http://infocenter.arm.com/help/index.js … hitecture/ ) where you could download the document after registration.

Offline

 

# 7   2009-01-08 04:00:06 Assembly on the STM32 cortex-m3

dalewheat
Member
From: Dallas TX USA
Registered: 2007-10-10
Posts: 43
Website

Re: Assembly on the STM32 cortex-m3

It's sad but true:  Programming in assembly language is considered an exception to the rule, and only necessary in "special circumstances".  Therefore, not as much effort goes into documenting its use.

Yiu's book is excellent.  Buy 2 copies and give one to someone you like:

http://www.amazon.com/Definitive-Guide- … 0750685344

The ARM architecture is different from most other architectures and it simply must be learned and appreciated for the beautiful thing that it is.  There is no point trying to relate it to other architectures as this will only perpetuate incorrect understanding of how it actually performs.  I compare it to learning French (and the French-speaking folks here can mostly likely confirm this) in that you cannot simply substitute one word for another word in French and be said to be speaking French.  It doesn't work that way.

I use your example of return / return from interrupt instructions.  They do not exist.  The "Branch with Link" instruction saves the current program counter in the Link Register, but if the called subroutine subsequently makes its own branch/link, the return value is lost.  Therefore it is up to subroutines to preserve this register value.  This is in contrast to other RISC architectures such as AVR that implement a hardware stack that is intimately wired into the instruction set, sometimes with unintended consequences.  An example is that a RETI (return from interrupt) instruction always (re)enables global interrupts.  That's because global interrupts are always disabled upon entry into a handler routine - again, all done in hardware.  The ARM architecture simply doesn't do it that way.  It lets you define your own way / It forces you to define your own way.

I would suggest playing with either the ARM assembler or the GNU assembler for ARM (not the same thing and not at all compatible with each other) and finding your own path in ARM assembly.  Then look at the optimized output of C compilers and compare your code with that.  Remember that even highly optimized compiler output is generated by a machine and might miss simple improvements.

The first thing that you're going to find is that ARM assemblers are much "smarter" than traditional CISC or even most RISC assemblers, in that they can take psuedo-instructions and figure out the best way to encode them, even selecting the appropriate instructions if need be.  That's a whole different animal than the traditonal assembler where you say, "Here is the instruction mnemonic, now convert that into the right string of ones and zeros for me, please."

Which is better, C or assembly?  It's not even really a valid question.  Which is better, English or French?  I say, why choose?  Why not speak/read/write both?

Dale Wheat
http://dalewheat.com

Offline

 

Board footer