Yahoo Groups archive

Lpc2000

Index last updated: 2026-04-28 23:31 UTC

Message

Re: Example of C and inline ASM in a file?

2006-04-10 by Stephen Pelc

> From: "brendanmurphy37" <brendan.murphy@...>

> I fear I'm repeating myself: the problem isn't that in-line assembler 
> doesn't work, the problem is that it is completely non-standard and 
> non-portable.

Especially in embedded work, device drivers aren't portable 
whatever they are written in.

> If you insist on using it, when you move to a new platform you have 
> to re-write the application (as in the hypothetical example I 
> presented).
> 
> Better by far I think to follow the well-known technique of isolating 
> the platform-specific parts (i.e. the assembler) into a small 
> separate compilation unit (i.e. assembler source file), and providing 
> different versions of that file for different platforms. In other 
> words, rather than mixing portable with non-portable code (as in-line 
> assembler does), separate it out.

That's a consequence of working in C/C++. Other languages handle 
things differently.

When I look at where MPE (as opposed to its clients) uses in-
line assembly, we find it in device-specific drivers, e.g. UART 
and Ethernet drivers, and in CPU specific sections, e.g. 
schedulers, where we are striving for performance. In our world, 
interrupt latency and task-switching speed really matter, 
regardless of CPU performance - the faster the CPU, the more we 
are asked to do with it.

Paul's comment about intrinsics is relevant, but I would really 
hate to have to guarantee that a client won't find another 
useful one that we haven't already provided. Today I had a tech-
support conversation about bank-switched RAM ... he had found 
another way of perverting the hardware/software trade-offs in 
our standard libraries.

In-line assembler isn't evil, you just have to be able to make a 
good case for it, and that case has to include maintenance and 
portability.

Stephen
--
Stephen Pelc, stephen@...
MicroProcessor Engineering Ltd - More Real, Less Time
133 Hill Lane, Southampton SO15 5AF, England
tel: +44 (0)23 8063 1441, fax: +44 (0)23 8033 9691
web: http://www.mpeforth.com - free VFX Forth downloads

Attachments

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.