There is no USPS pickup on Monday Feb 15th, 2016 because of President's Day. USPS orders placed after 11am EST Fri February 12th will go out Tuesday February 16. UPS orders will ship as normal.

Can any microcontrollers compile code into RAM?
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Can any microcontrollers compile code into RAM?

by chuckz on Fri Feb 08, 2013 10:11 am

I have a friend who has a question about the various microcontrollers. Can someone please answer this for different microcontrollers?

Can any of them compile their own code into RAM, and execute it from RAM? The PICs I'm familiar with definitely cannot. Every little change in the code requires powering down and re-programming the program flash memory, and then powering back up. IOW, every itty bitty change presents a total disruption in what the µC was doing.

Posts: 177
Joined: Mon May 30, 2011 11:54 am

Re: Can any microcontrollers compile code into RAM?

by adafruit_support_rick on Fri Feb 08, 2013 11:45 am

That's a pretty broad question - there are lots of microcontroller architectures out there.

I can start answering it by telling you that most microcontrollers use what is known as a "Harvard architecture", which means that program space and data space are on different internal memory buses. This is a speed optimization which allows instructions and data to be accessed in parallel (i.e., simultaneously). It also means that the processor cannot execute instructions from data space.

Desktop and other general-purpose computers typically use what is known as a "Von Neumann architecture", which has a single address space for both instructions and data.

Von Neumann architectures are much more flexible, and so they are well-suited to general computing where many different programs can be loaded and executed dynamically. But they are also subject to errors caused by bugs which lead to the execution of data as instructions. Viruses exploit this weakness by disguising their code as data and then causing the processor to execute it.

Microcontrollers, on the other hand, are not intended for general computing. They are designed to be embedded in a purpose-built device, and committed to a specific set of tasks. Harvard architectures are well-suited to this, since a non-volatile, read-only program space is highly desirable - programming errors (or viruses) cannot modify or damage the program, power failures cannot erase the program, etc.

There are far too many microcontrollers for me to catalog, but off the top of my head I can tell you that the Atmel AVR family and the Intel 8051 family are both Harvard architecture.

Posts: 24920
Joined: Tue Mar 15, 2011 11:42 am
Location: Buffalo, NY

Re: Can any microcontrollers compile code into RAM?

by westfw on Fri Feb 08, 2013 1:35 pm

The TI msp430 CPUs are Von Neumann, and can execute code from ram.
unfortunately, they don't usually have much ram.
User avatar
Posts: 1377
Joined: Fri Apr 27, 2007 1:01 pm
Location: SF Bay area

Re: Can any microcontrollers compile code into RAM?

by franklin97355 on Sat Feb 09, 2013 1:54 am

The Parallax Propeller also can compile into RAM and run the code until powered down.

Posts: 11188
Joined: Mon Apr 21, 2008 2:33 pm
Location: Lacomb, OR.

Re: Can any microcontrollers compile code into RAM?

by thefatmoop on Sun Feb 17, 2013 5:21 pm

Yeah Frank beat me to it. the parallax propeller can have the compiled code tossed directly into ram which is seriously fast and convenient.

but that's about the only plus to the propeller. I'd suggest you avoid it

now if he means compile it's own code that sounds more like an os and you're not going to find that in a micro. raspberry pi is an option
User avatar
Posts: 337
Joined: Tue Aug 19, 2008 4:36 pm

Please be positive and constructive with your questions and comments.