9

I am looking for an inexpensive single board computer that I could program in assembly language, using limited facilities to load the object code from a PC and simple I/O peripherals.

Ideally I would like to be able to write in a reasonable time all the code on the machine myself. I don't want an OS in the way, as I want to have a program that writes in RAM some code and then branches to execute it. Arduino would probably be my best choice, as far as system simplicity suitable for assembly programming goes, but it has a Harvard architecture and it won't allow me to execute from RAM.

Years ago I was using a Von Neumann architecture 8-bit CPU that could branch execution to any address, no matter whether it was mapped to ROM, RAM or whatever. This is what I would like to do now.

I probably could write and load in Flash memory an interpreter of op codes written in RAM, but it is a very complex and time-consuming solution, unless virtual machines of this kind exist already.

Any suggestions on other workarounds with Arduino or of other micro-controllers I might use?

Thanks!

Pierre

dda
  • 1,588
  • 1
  • 12
  • 17
pierre
  • 91
  • 2
  • 3
    The PIC32 is a Princeton (Von Neumann) architecture chip. It's a MIPS CPU so is well documented and standardized, though somewhat more complex than a lowly AVR. The chipKIT boards may be more to your liking. – Majenko Jul 04 '15 at 14:05
  • 2
    Although optimized as a Harvard Architecture, the ARM Cortex-M series can execute from RAM at a tolerable efficiency loss and would still be a lot faster than an AVR when doing so. At least a half dozen chip companies make widely used offerings based on licensing this core, and while many people use vendor and/or semi-standard libraries, it is entirely possible to do it all yourself based on the data sheets. I went with STM32 first as their discovery boards are very cheap, work on Linux/OSX with open source tools, and can program chips on custom boards, but have now used Kinetis as well. – Chris Stratton Jul 04 '15 at 14:13
  • The main question is Why? Why do you require ASM execution from RAM? And what kind of assembly do you want to use? Since every architecture has its own language... Do you do this for learning purposes? Or you have a specific target? – frarugi87 Jan 30 '17 at 11:40
  • 2
    I beg to differ, why I wished to do this is irrelevant to the question I asked at the time as this is not a workaround to some other issue. Incidentally, I followed Majenko's advice and I currently have a Uno32 plus external interfaces running assembly (and calling C functions from assembly), writing its own modified asm code in RAM and executing it. – pierre Jan 30 '17 at 19:11
  • Forth is what you are looking for :) – Mikael Patel Jul 31 '17 at 13:23
  • @ChrisStratton putting code in RAM, instead of Flash, can actually result in faster code, at least in those processors, in which part of the internal RAM is in the code region. (address up to 0x1FFFFFFF) . Flash is typically slow, and, despite the "memory accelerator/buffer" (which is simply a small cache), you never get a true 1-cycle access. Therefore you'll have a lot of penalties, especially if the code has a lot of jumps (the buffer must be refilled) and it's executing from Flash instead of RAM. Different thing is the external RAM, which might be very slow (e.g. due to bus constraints). – next-hack Aug 31 '17 at 08:40
  • @next-hack if you have RAM optimized for code access, yes. But many basic micros that permit code access to RAM are only optimized for data access to it - while you can run them from RAM, it's slower than running them from flash as the instruction fetch and data access have to share the same memory bus, when ordinarily they would not. But if you have one specifically designed for this, then sure, go ahead. And that might explain why (if I recall correctly) in some of the Kinetis parts the RAM sizes grow symmetrically around 0x20000000, rather than linearly above it as in say STM32's. – Chris Stratton Aug 31 '17 at 15:41

1 Answers1

1

In my opinion the interpreter idea is much more feasible. The notion of writing, in assembler, code that itself generates machine code, in RAM, and then executes it, is itself incredibly complex.

You haven't said why you want to do this, so this is somewhat of an X-Y problem.

I don't want an o.s. in the way ...

The normal Arduinos do not have an OS in the way - basically the code you write is what gets loaded onto the chip.

Nick Gammon
  • 38,184
  • 13
  • 65
  • 124
  • 2
    In a word, no. The inability to execute modifiable memory is a rather unusual limitation in this day and age, where most other nominally Harvard architecture devices are modified to be able to avoid that limitation. Writing a software interpreter is both going to be a lot more work, and a lot less efficient, than dealing with one of the many inexpensive, high performance, and easy to use chips that has the necessary internal connections to simply execute code from RAM. The slightly less efficient pipeline operation in that mode is still far, far ahead of software interpretation. – Chris Stratton Jul 05 '15 at 00:35
  • I think you are underestimating the requirement to have "a program that writes in RAM some code and then branches to execute it". Now if the question said "load some code from disk and execute it" well yes, that would be trivial on the architectures that support loading code into RAM. But to have code that generates machine code? A compiler/assembler in other words? Maybe I misunderstood the question as meaning "generate code" rather than "load code". But the OP said " I would like to be able to write in a reasonable time all the code on the machine myself." Sounds like code generation to me. – Nick Gammon Jul 05 '15 at 04:42
  • 1
    No. If you are going to do runtime code modification, it is by far easier to directly generate machine code than to generate high level code and also have to create a compiler or interpreter as in your recommendation. It might be worth spending some time hand-writing instructions to get some perspective. And no, "write all the code on the machine myself" does not refer to run time code generation to begin with, but rather merely to creating original work vs. relying on other authors for supporting components. – Chris Stratton Jul 05 '15 at 05:47
  • I think this answer could be improved with a link to a list of interpreters that already run on Arduino. Is there a more complete list than http://playground.arduino.cc/CommonTopics/InterpretedLanguages ? – David Cary May 05 '16 at 02:10
  • 1
    Here is a simple forth style shell for the Arduino that executes code from any of the memory storages (SRAM, EEMEM, EEPROM). Not the fastest interpreter but shows how the instruction fetch (memory access) and instruction pointer (call/return addresses) can be abstracted. https://github.com/mikaelpatel/Arduino-Shell – Mikael Patel Sep 02 '16 at 08:33
  • 1
    I'm impressed, Mikael. I wrote a Forth interpreter for the Apple II years ago. I doubt I can even find the code these days. Good old Forth, still alive and kicking! :) – Nick Gammon Sep 03 '16 at 01:21
  • 1
    @NickGammon I recently wrote a more traditional forth virtual machine (fvm) for the Arduino. It allows embedding a byte instruction interpreter in an Arduino sketch as it is multi-tasking (allows yield of the fvm). https://github.com/mikaelpatel/Arduino-FVM. There is a token compiler (runs on the Arduino :) and a traditional forth interactive interpreter. Please see the example sketches. – Mikael Patel Mar 01 '17 at 16:28
  • @MikaelPatel - well that's impressive! I used token mapping in my Pascal compiler years ago, and tail call reduction as well, mainly to squeeze the code into the available space. :) – Nick Gammon Mar 01 '17 at 20:11