EmbeddedRelated.com
Forums

AVR to ARM

Started by Meindert Sprang October 1, 2007
Hi All,

I am about to port an application from an AVR to an ARM. Most of the code is
written in C but one particular driver is written in AVR assembler. I was
wondering if a converter exists to translate AVR assembler to ARM assembler
code. I find it easier to get to grips with new a new assembler syntax by
starting with an existing piece of code instead of writing it from scratch.

Meindert


"Meindert Sprang" <ms@NOJUNKcustomORSPAMware.nl> writes:

> Hi All, > > I am about to port an application from an AVR to an ARM. Most of the code is > written in C but one particular driver is written in AVR assembler. I was > wondering if a converter exists to translate AVR assembler to ARM assembler > code. I find it easier to get to grips with new a new assembler syntax by > starting with an existing piece of code instead of writing it from scratch.
Just rewrite it in C. If you really want it in assembler, you can then look at the compiler output! But I expect C on the arm will be faster than assembly on the AVR (unless you are deliberately running the ARM at low clock speed). -- John Devereux
Le Mon, 01 Oct 2007 12:28:40 +0200, Meindert Sprang a &eacute;crit:

> Hi All, > > I am about to port an application from an AVR to an ARM. Most of the code is > written in C but one particular driver is written in AVR assembler. I was > wondering if a converter exists to translate AVR assembler to ARM assembler > code. I find it easier to get to grips with new a new assembler syntax by > starting with an existing piece of code instead of writing it from > scratch.
I'm not sure that this kind of translator really exist. I already ported a custom driver (CompactFlash) from AVR to ARM. ARM assembler is much more complex than the AVR's so i resigned to implement it in ARM asm, i did it in C. BTW what sort of driver is it ?
> Meindert
Habib.
"John Devereux" <jdREMOVE@THISdevereux.me.uk> wrote in message
news:87ejgfgkzm.fsf@cordelia.devereux.me.uk...
> "Meindert Sprang" <ms@NOJUNKcustomORSPAMware.nl> writes: > > > Hi All, > > > > I am about to port an application from an AVR to an ARM. Most of the
code is
> > written in C but one particular driver is written in AVR assembler. I
was
> > wondering if a converter exists to translate AVR assembler to ARM
assembler
> > code. I find it easier to get to grips with new a new assembler syntax
by
> > starting with an existing piece of code instead of writing it from
scratch.
> > Just rewrite it in C. > > If you really want it in assembler, you can then look at the compiler > output! But I expect C on the arm will be faster than assembly on the > AVR (unless you are deliberately running the ARM at low clock speed).
I don't know. In my experience, some things are better written in assembler. In this case, the driver consists of an interrupt handler running at 19200 Hz on an 8MHz AVR.On the ARM (running at 30MHz), I want to have it run at 153,600Hz simply because the handler (a software UART) needs to run at 38400 baud instead of 4800 baud. And this driver is written so compact that I cannot believe a C compiler could do any better. A compiler can only make certain generic assumptions while I as a programmer know what the driver is supposed to do and I can for instance reserve certain registers to speed up things. Meindert
Meindert Sprang wrote:
> "John Devereux" <jdREMOVE@THISdevereux.me.uk> wrote in message > news:87ejgfgkzm.fsf@cordelia.devereux.me.uk... >> "Meindert Sprang" <ms@NOJUNKcustomORSPAMware.nl> writes: >> >>> Hi All, >>> >>> I am about to port an application from an AVR to an ARM. Most of the > code is >>> written in C but one particular driver is written in AVR assembler. I > was >>> wondering if a converter exists to translate AVR assembler to ARM > assembler >>> code. I find it easier to get to grips with new a new assembler syntax > by >>> starting with an existing piece of code instead of writing it from > scratch. >> Just rewrite it in C. >> >> If you really want it in assembler, you can then look at the compiler >> output! But I expect C on the arm will be faster than assembly on the >> AVR (unless you are deliberately running the ARM at low clock speed). > > I don't know. In my experience, some things are better written in assembler. > In this case, the driver consists of an interrupt handler running at 19200 > Hz on an 8MHz AVR.On the ARM (running at 30MHz), I want to have it run at > 153,600Hz simply because the handler (a software UART) needs to run at 38400 > baud instead of 4800 baud. And this driver is written so compact that I > cannot believe a C compiler could do any better. A compiler can only make > certain generic assumptions while I as a programmer know what the driver is > supposed to do and I can for instance reserve certain registers to speed up > things. > > Meindert > >
I wrote a 38400 baud software uart for an AVR with a 7.27 MHz clock, with interrupts at 153.6 kHz. With only 48 clock cycles between interrupts, it was worth writing the routing in assembly. But on an ARM using a fast interrupt, it should be practical to write the code in C if you're careful. Using assembly might save a little run time, since you can dedicate registers to specific data instead of loading them at each call to the interrupt. Perhaps your compiler will support allocation of globals directly to registers, which would save that step too. Even if you decide to write the interrupt code in assembly, the original AVR code will be useless except perhaps as inspiration - you cannot translate from assembly on one cpu to a completely different cpu and expect decent results.
"Habib Bouaziz-Viallet" <habib@mizar.systems> wrote in message
news:4700dfec$0$30560$426a74cc@news.free.fr...
> Le Mon, 01 Oct 2007 12:28:40 +0200, Meindert Sprang a &#4294967295;crit: > > > Hi All, > > > > I am about to port an application from an AVR to an ARM. Most of the
code is
> > written in C but one particular driver is written in AVR assembler. I
was
> > wondering if a converter exists to translate AVR assembler to ARM
assembler
> > code. I find it easier to get to grips with new a new assembler syntax
by
> > starting with an existing piece of code instead of writing it from > > scratch. > I'm not sure that this kind of translator really exist. > I already ported a custom driver (CompactFlash) from AVR to ARM. ARM > assembler is much more complex than the AVR's so i resigned to implement
it
> in ARM asm, i did it in C. > > BTW what sort of driver is it ?
A software UART, running four RX channels, including a FIFO per channel and one TX channel. Taking up 40% of processor time on an 8MHz AVR. Meindert
"David Brown" <david@westcontrol.removethisbit.com> wrote in message
news:4700e77c$0$3208$8404b019@news.wineasy.se...
> I wrote a 38400 baud software uart for an AVR with a 7.27 MHz clock, > with interrupts at 153.6 kHz. With only 48 clock cycles between > interrupts, it was worth writing the routing in assembly.
In my case, it is a software UART running four RX channels, including a FIFO per channel and one TX channel. Taking up 40% of processor time on an 8MHz AVR. Meindert
"Meindert Sprang" <ms@NOJUNKcustomORSPAMware.nl> writes:

> "John Devereux" <jdREMOVE@THISdevereux.me.uk> wrote in message > news:87ejgfgkzm.fsf@cordelia.devereux.me.uk... >> "Meindert Sprang" <ms@NOJUNKcustomORSPAMware.nl> writes: >> >> > Hi All, >> > >> > I am about to port an application from an AVR to an ARM. Most of the > code is >> > written in C but one particular driver is written in AVR assembler. I > was >> > wondering if a converter exists to translate AVR assembler to ARM > assembler >> > code. I find it easier to get to grips with new a new assembler syntax > by >> > starting with an existing piece of code instead of writing it from > scratch. >> >> Just rewrite it in C. >> >> If you really want it in assembler, you can then look at the compiler >> output! But I expect C on the arm will be faster than assembly on the >> AVR (unless you are deliberately running the ARM at low clock speed). > > I don't know. In my experience, some things are better written in assembler. > In this case, the driver consists of an interrupt handler running at 19200 > Hz on an 8MHz AVR.On the ARM (running at 30MHz), I want to have it run at > 153,600Hz simply because the handler (a software UART) needs to run at 38400 > baud instead of 4800 baud.
Well, you may be right. But I think my advice stands, write it in C first and try it. Look at the assembly output, do some timings.
> And this driver is written so compact that I cannot believe a C > compiler could do any better. A compiler can only make certain > generic assumptions while I as a programmer know what the driver is > supposed to do and I can for instance reserve certain registers to > speed up things.
ARMs have the FIQ - I was able to get this running at >1MHz, using C, on a ~40MHz device. I don't know what ARM variant you are using, but the fastest is usually ARM mode (vs thumb) running out of on-chip RAM. As for being able to do better than the compiler - all I know is that gcc is better at ARM assembly than *I* am! -- John Devereux
Meindert Sprang wrote:
> Hi All, > > I am about to port an application from an AVR to an ARM. Most of the code is > written in C but one particular driver is written in AVR assembler. I was > wondering if a converter exists to translate AVR assembler to ARM assembler > code. I find it easier to get to grips with new a new assembler syntax by > starting with an existing piece of code instead of writing it from scratch. >
Such converters are common, and they're available in nearly every town that has any high-tech activity at all. They're called "good assembly language programmers". Sorry for being a smart-ass, but that's the best you're going to do, particularly since "driver" implies "close to the hardware", and the hardware is going to be different. -- Tim Wescott Wescott Design Services http://www.wescottdesign.com Do you need to implement control loops in software? "Applied Control Theory for Embedded Systems" gives you just what it says. See details at http://www.wescottdesign.com/actfes/actfes.html
On Mon, 1 Oct 2007 14:45:14 +0200, "Meindert Sprang"
<ms@NOJUNKcustomORSPAMware.nl> wrote:

>"Habib Bouaziz-Viallet" <habib@mizar.systems> wrote in message >news:4700dfec$0$30560$426a74cc@news.free.fr... >> Le Mon, 01 Oct 2007 12:28:40 +0200, Meindert Sprang a &#4294967295;crit: >> >> > Hi All, >> > >> > I am about to port an application from an AVR to an ARM. Most of the >code is >> > written in C but one particular driver is written in AVR assembler. I >was >> > wondering if a converter exists to translate AVR assembler to ARM >assembler >> > code. I find it easier to get to grips with new a new assembler syntax >by >> > starting with an existing piece of code instead of writing it from >> > scratch. >> I'm not sure that this kind of translator really exist. >> I already ported a custom driver (CompactFlash) from AVR to ARM. ARM >> assembler is much more complex than the AVR's so i resigned to implement >it >> in ARM asm, i did it in C. >> >> BTW what sort of driver is it ? > >A software UART, running four RX channels, including a FIFO per channel and >one TX channel. Taking up 40% of processor time on an 8MHz AVR. >
Just be aware that overall an AVR is much better than an ARM at bit banging. Some variants of ARM MCUs are very slow at bit banging. Regards Anton Erasmus