<p>Dr Michelle Strout (now at University of Arizona) used this approach when she was at Colorado State University.</p>

<ol>
<li><p>For hardware, the students used <a href="https://shop.evilmadscientist.com/productsmenu/760" rel="nofollow noreferrer">Meggy JR</a>. Students were expected to write simple programs/games using a Java interface to the hardware. Initially, the hardware was purchased as kits and there was a pizza party to assemble it. </p></li>
<li><p>The students then wrote compilers for a subset of Java (MeggyJava), using Java. <a href="https://www.cs.colostate.edu/~cs453/yr2013" rel="nofollow noreferrer">See class web page</a>. The code their compiler created could be executed on the hardware, or in a simulator.</p></li>
<li><p>In another year, the students did the same project, <a href="https://www.cs.colostate.edu/~cs453/yr2015/" rel="nofollow noreferrer">See class web page</a>, but the implementation language was in Haskell.</p></li>
</ol>

<p>The students enjoyed creating simple games and displays and then using their compiler to realize the result on the physical hardware.</p>

<p>For grading, the course used our autograder to compare the "output" of the instructors compiler (i.e. what did the code do to the state of the Meggy JR when the code was executed on the simulator), to that of the code produced by their compiler.</p>

<p>I hope this helps.</p>

CC BY-SA 3.0
2018-03-02T21:59:46.403Z
2018-03-02T21:59:46.403Z
Fritz Sieker
<p>If you want to look at hardware which might also be suitable for programming in C/C++, the BBC <a href="http://microbit.org/" rel="nofollow noreferrer">micro:bit</a> might be a good alternative to an arduino. It has a more self-contained set of peripherals, and is programmed in ARM assembler. It uses drag-drop style programming (you need an ASCII format hex file) over USB. Of course, you need to set up a tool chain to compile the code, unless you want to write raw hex by hand (or analyse compiled code from the online tool chains). Halting debug (single step and modifying registers) is supported, so it's a capable platform to work on if you want hardware.</p>

<p>In terms of a compiler for Cortex-M0 (as in the micro:bit), the educational toolchains support an <a href="https://www.touchdevelop.com/docs/touch-develop-in-208-bits" rel="nofollow noreferrer">in-browser compiler</a> which demonstrates that it's not actually too complicated.</p>

<p>Of course, there is a fair amount of initialisation required if you want to actually turn the LEDs on or look at the push buttons (let alone the SPI accelerometer on board). You might include some assembler within an online compiler C++ project - that ought to work (if you use the ARM mbed toolchain rather than the school specific toolchains).</p>

<p>An alternative is to look at something more <strong>low-level</strong>, using a verilog simulator (but there is non-trivial cost involved in the simulator which might put this out of reach to schools - it's more targeted at universities who are teaching embedded hardware, and start-ups). The whole Cortex-M3 processor and a supporting system can be <a href="http://designstart.arm.com/eval" rel="nofollow noreferrer">downloaded from ARM</a> for free. This runs code (and has a model which prints out disassembly as it runs). - disclaimer - I developed this product.</p>

CC BY-SA 3.0
2017-08-20T13:31:33.027Z
2017-08-20T13:31:33.027Z
Sean Houlihane
<p>My first piece of advice would be to avoid any modern hardware (and possibly to avoid hardware itself, as the simulators out there are pretty good). As far as I can tell, all of the very cheap processors out there right now (such as come with Arduino) use languages like asm, and <a href="http://forum.arduino.cc/index.php?topic=37130.0" rel="nofollow noreferrer">do not lend themselves</a> to the kind of conceptually clear assembly programming that would presumably be most helpful for your students.</p>

<p>In a <a href="https://cseducators.stackexchange.com/q/410/27">prior discussion</a>, I talked about the experience I've had teaching with 6502 Assembly, and I would recommend this course as well. This plucky little processor (and, therefore, its assembly language as well) is about as clean, simple, and streamlined as a processor can be. </p>

<p>Additionally, there is a <a href="https://skilldrick.github.io/easy6502/" rel="nofollow noreferrer">lovely simulator</a> for the 6502, a <a href="http://nesdev.com/6502.txt" rel="nofollow noreferrer">complete assembly specification</a>, a <a href="http://6502.org/" rel="nofollow noreferrer">community</a> devoted to it, and </p>

<p>And if you do want to continue on to use actual hardware, the following computers used the 6502, many of which are readily available on eBay and the like:</p>

<ul>
<li>Apple IIe.</li>
<li>Commodore PET.</li>
<li>BBC Micro.</li>
<li>Atari 2600.</li>
<li>Atari 800.</li>
<li>Commodore VIC-20.</li>
<li>Commodore 64.</li>
</ul>

CC BY-SA 3.0
2017-08-19T23:04:54.210Z
Thanks a lot fro you answer Ben. Didn't know about this and sounds like a great idea. Im interested in purchasing one of this computers in eBay. What computer do you recommend us to use? And after we have it. How can we pass assmebly code to it? and through what?  Thanks. Any manual o explanation?
NathanWay
CC BY-SA 3.0
2017-08-19T23:06:55.497Z
I haven't dealt with the hardware myself, though that complete assembly specification goes so far as to give the byte-code for each processor command. I'd guess that each of the machines provides their own way to enter your assembly programs.  (You may need to find a way to transfer files to a 5 1/4 inch floppy disk.)
Ben I.
CC BY-SA 3.0
2017-08-19T23:18:25.550Z
Then that works for me :) Thanks a lot Ben. I'll do a research about this. And I think we will start working in building a compiler for the 6502. Thank you so much for your help :) Greetings.
NathanWay
CC BY-SA 3.0
2017-08-20T21:22:36.473Z
The 6502 ISA, although nice for hand coding, is not the best instruction set target for a modern compiler.  The most popular compilers (UCSD Pascal and others) for 6502 PCs targeted an interpreted P-code instead.
hotpaw2
CC BY-SA 3.0
2017-08-21T02:28:02.630Z
@hotpaw2 I can't find that information anywhere.  Where are you seeing that?  And also, what p-code was used?  Presumably the p-code would be a better match, then, if one were to take this path.
Ben I.
CC BY-SA 3.0
2017-08-24T10:51:19.387Z
The BBC micro has A version of basic with an integrated assembler. This may make it useful for some classes, as a stand alone machine. With all of these old machines, check for display screen comparability.
ctrl-alt-delor
CC BY-SA 3.0
2017-08-19T19:54:15.163Z
2017-08-19T19:54:15.163Z
Ben I.
<p>The 32-bit subsets of ARM assembly language are fairly clean, orthogonal and RISC-like, as well as being a reasonably nice target for a simple compiler.</p>

<p>Inexpensive Raspberry Pi's run 32-bit ARM code, as well as natively supporting a complete compiler development tool set (lex, yak, bison, et.al.)</p>

<p>Almost every student is likely to possess a mobile phone that will also run ARM machine code, and both Apple and Google provide free development tools that allow coding portions of a mobile app (iOS or Android) in ARM assembly language.  </p>

<p>The 6502 and 8051 ISAs were not designed for modern compiler output, even though otherwise suitable for teaching hand-coded assembly language and running it on inexpensive (vintage or microcontroller) hardware.</p>

CC BY-SA 3.0
2017-08-20T18:36:09.423Z
So, Getting Raspberry Pi's (ej Zero cheapest one), can we get the work done for the students on writing assembly code?
NathanWay
CC BY-SA 3.0
2017-08-20T20:40:54.673Z
Likely yes.  A generic web search turns up tons of sites/pages with tutorials on programming a Pi in ARM ASM.
hotpaw2
CC BY-SA 3.0
2017-08-20T18:22:43.877Z
2017-08-20T21:23:43.807Z
2017-08-20T21:23:43.807Z
hotpaw2
<p>This year course includes creating a compiler of course using Syntax Analyzer and Lexical Analyzer, Semantics and of course through all this generate Assembly Code</p>

<p>But also the teaching program includes using at least a little piece of hardware to pass assembly code to it.</p>

<p>Does anyone know a programmable hardware that we can use just for education purposes? </p>

<p>We will pass assembly code to the hardware.</p>

CC BY-SA 3.0
2017-08-18T23:53:39.627Z
Normally assembly code is still symbolic and needs to be further translated to machine code (assembled). But is there a reason that you want to go to actual hardware? Many compiler courses compile for a machine simulator instead. That gives you the chance to use a more rational machine definition than most actual hardware provides. Real machines can be messy.
Buffy
CC BY-SA 3.0
2017-08-19T00:00:42.073Z
Two additional problems you need to solve with real hardware is (a) a link between the development and target machines, and, (b) if the target has an OS, dealing with that as well. The complications are one reason for using pseudo-hardware instead, so the students can focus on the compilation process itself - especially in a first compiler course.
Buffy
CC BY-SA 3.0
2017-08-19T00:27:16.197Z
Also, welcome to [cseducators.se]! I have starred this question as one that I am interested in. In my program, we teach on a simulation of the 6502. The limited number of registers and commands make it pretty manageable. I hope to hear more from you around the site.
Ben I.
CC BY-SA 3.0
2017-08-19T00:52:00.510Z
And the 6502 has a reputation as a pretty clean design. So does the Zilog Z80 if you can find a simulator. Intel hardware tends to be more complicated after the first couple of editions (i.e. 8080). @BenI. have you got a reference for the 6502? Maybe a full answer is warranted.
Buffy
CC BY-SA 3.0
2017-08-19T02:04:10.970Z
Thanks for the answers, Yes the students will build a simple compiler and of course this will generate assembly code (MOV, LOOP, etc). So with this can we play with some hardware or do we need something more?
NathanWay
CC BY-SA 3.0
2017-08-19T12:14:33.640Z
It might be a good idea for you to visit the classroom to chat. I think you can get some good advice there: https://chat.stackexchange.com/rooms/59174/the-classroom
Buffy
CC BY-SA 3.0
2017-08-19T19:00:02.503Z
One idea maybe is to not target hardware but instead target LLVM (which in turn can target all sorts of devices -- even web browsers). Caveat: I've never done this myself, so don't know for certain if this is actually a good idea or not, from a pedagogical point of view.
Michael0x2a
CC BY-SA 3.0
2017-08-19T22:05:49.107Z
The MIPS SPIM simulator is good, that's what I learned on in college.
EJoshuaS - Stand with Ukraine
CC BY-SA 3.0
2017-08-20T23:22:49.593Z
z80 is not very clean, is has a lot of special purposes register, like the x86, so you can spend a lot of instructions just moving data from register to register. 6502 and Arm are nice, so also is this old CPU MC68000.
ctrl-alt-delor
<assembly><hardware>
What hardware can I use when teaching Compiler Language and Assembly Code
# What hardware can I use when teaching Compiler Language and Assembly Code

(Asked by: username_0 on 2017-08-18)

This year course includes creating a compiler of course using Syntax Analyzer and Lexical Analyzer, Semantics and of course through all this generate Assembly Code

But also the teaching program includes using at least a little piece of hardware to pass assembly code to it.

Does anyone know a programmable hardware that we can use just for education purposes?

We will pass assembly code to the hardware.

**Tags:** assembly, hardware

> **Comments:**
> **username_1**: Normally assembly code is still symbolic and needs to be further translated to machine code (assembled). But is there a reason that you want to go to actual hardware? Many compiler courses compile for a machine simulator instead. That gives you the chance to use a more rational machine definition than most actual hardware provides. Real machines can be messy.  
> **username_1**: Two additional problems you need to solve with real hardware is (a) a link between the development and target machines, and, (b) if the target has an OS, dealing with that as well. The complications are one reason for using pseudo-hardware instead, so the students can focus on the compilation process itself - especially in a first compiler course.  
> **username_2**: Also, welcome to [cseducators.se]! I have starred this question as one that I am interested in. In my program, we teach on a simulation of the 6502. The limited number of registers and commands make it pretty manageable. I hope to hear more from you around the site.  
> **username_1**: And the 6502 has a reputation as a pretty clean design. So does the Zilog Z80 if you can find a simulator. Intel hardware tends to be more complicated after the first couple of editions (i.e. 8080). @BenI. have you got a reference for the 6502? Maybe a full answer is warranted.  
> **username_0**: Thanks for the answers, Yes the students will build a simple compiler and of course this will generate assembly code (MOV, LOOP, etc). So with this can we play with some hardware or do we need something more?  
> **username_1**: It might be a good idea for you to visit the classroom to chat. I think you can get some good advice there: https://chat.stackexchange.com/rooms/59174/the-classroom  
> **username_3**: One idea maybe is to not target hardware but instead target LLVM (which in turn can target all sorts of devices -- even web browsers). Caveat: I've never done this myself, so don't know for certain if this is actually a good idea or not, from a pedagogical point of view.  
> **username_4**: The MIPS SPIM simulator is good, that's what I learned on in college.  
> **username_5**: z80 is not very clean, is has a lot of special purposes register, like the x86, so you can spend a lot of instructions just moving data from register to register. 6502 and Arm are nice, so also is this old CPU MC68000.  

---

## 4 answers

### Answer by username_2 on 2017-08-19. Score: 4 | Accepted answer

My first piece of advice would be to avoid any modern hardware (and possibly to avoid hardware itself, as the simulators out there are pretty good). As far as I can tell, all of the very cheap processors out there right now (such as come with Arduino) use languages like asm, and [do not lend themselves](http://forum.arduino.cc/index.php?topic=37130.0) to the kind of conceptually clear assembly programming that would presumably be most helpful for your students.

In a [prior discussion](https://cseducators.stackexchange.com/q/410/27), I talked about the experience I've had teaching with 6502 Assembly, and I would recommend this course as well. This plucky little processor (and, therefore, its assembly language as well) is about as clean, simple, and streamlined as a processor can be.

Additionally, there is a [lovely simulator](https://skilldrick.github.io/easy6502/) for the 6502, a [complete assembly specification](http://nesdev.com/6502.txt), a [community](http://6502.org/) devoted to it, and

And if you do want to continue on to use actual hardware, the following computers used the 6502, many of which are readily available on eBay and the like:

* Apple IIe.
* Commodore PET.
* BBC Micro.
* Atari 2600.
* Atari 800.
* Commodore VIC-20.
* Commodore 64.

> **Comments:**
> **username_0**: Thanks a lot fro you answer Ben. Didn't know about this and sounds like a great idea. Im interested in purchasing one of this computers in eBay. What computer do you recommend us to use? And after we have it. How can we pass assmebly code to it? and through what?  Thanks. Any manual o explanation?  
> **username_2**: I haven't dealt with the hardware myself, though that complete assembly specification goes so far as to give the byte-code for each processor command. I'd guess that each of the machines provides their own way to enter your assembly programs.  (You may need to find a way to transfer files to a 5 1/4 inch floppy disk.)  
> **username_0**: Then that works for me :) Thanks a lot Ben. I'll do a research about this. And I think we will start working in building a compiler for the 6502. Thank you so much for your help :) Greetings.  
> **username_8**: The 6502 ISA, although nice for hand coding, is not the best instruction set target for a modern compiler.  The most popular compilers (UCSD Pascal and others) for 6502 PCs targeted an interpreted P-code instead.  
> **username_2**: @username_8 I can't find that information anywhere.  Where are you seeing that?  And also, what p-code was used?  Presumably the p-code would be a better match, then, if one were to take this path.  
> **username_5**: The BBC micro has A version of basic with an integrated assembler. This may make it useful for some classes, as a stand alone machine. With all of these old machines, check for display screen comparability.  

---

### Answer by username_8 on 2017-08-20. Score: 5

The 32-bit subsets of ARM assembly language are fairly clean, orthogonal and RISC-like, as well as being a reasonably nice target for a simple compiler.

Inexpensive Raspberry Pi's run 32-bit ARM code, as well as natively supporting a complete compiler development tool set (lex, yak, bison, et.al.)

Almost every student is likely to possess a mobile phone that will also run ARM machine code, and both Apple and Google provide free development tools that allow coding portions of a mobile app (iOS or Android) in ARM assembly language.

The 6502 and 8051 ISAs were not designed for modern compiler output, even though otherwise suitable for teaching hand-coded assembly language and running it on inexpensive (vintage or microcontroller) hardware.

> **Comments:**
> **username_0**: So, Getting Raspberry Pi's (ej Zero cheapest one), can we get the work done for the students on writing assembly code?  
> **username_8**: Likely yes.  A generic web search turns up tons of sites/pages with tutorials on programming a Pi in ARM ASM.  

---

### Answer by username_6 on 2018-03-02. Score: 2

Dr Michelle Strout (now at University of Arizona) used this approach when she was at Colorado State University.

1. For hardware, the students used [Meggy JR](https://shop.evilmadscientist.com/productsmenu/760). Students were expected to write simple programs/games using a Java interface to the hardware. Initially, the hardware was purchased as kits and there was a pizza party to assemble it.
2. The students then wrote compilers for a subset of Java (MeggyJava), using Java. [See class web page](https://www.cs.colostate.edu/~cs453/yr2013). The code their compiler created could be executed on the hardware, or in a simulator.
3. In another year, the students did the same project, [See class web page](https://www.cs.colostate.edu/~cs453/yr2015/), but the implementation language was in Haskell.

The students enjoyed creating simple games and displays and then using their compiler to realize the result on the physical hardware.

For grading, the course used our autograder to compare the "output" of the instructors compiler (i.e. what did the code do to the state of the Meggy JR when the code was executed on the simulator), to that of the code produced by their compiler.

I hope this helps.


---

### Answer by username_7 on 2017-08-20. Score: 1

If you want to look at hardware which might also be suitable for programming in C/C++, the BBC [micro:bit](http://microbit.org/) might be a good alternative to an arduino. It has a more self-contained set of peripherals, and is programmed in ARM assembler. It uses drag-drop style programming (you need an ASCII format hex file) over USB. Of course, you need to set up a tool chain to compile the code, unless you want to write raw hex by hand (or analyse compiled code from the online tool chains). Halting debug (single step and modifying registers) is supported, so it's a capable platform to work on if you want hardware.

In terms of a compiler for Cortex-M0 (as in the micro:bit), the educational toolchains support an [in-browser compiler](https://www.touchdevelop.com/docs/touch-develop-in-208-bits) which demonstrates that it's not actually too complicated.

Of course, there is a fair amount of initialisation required if you want to actually turn the LEDs on or look at the push buttons (let alone the SPI accelerometer on board). You might include some assembler within an online compiler C++ project - that ought to work (if you use the ARM mbed toolchain rather than the school specific toolchains).

An alternative is to look at something more **low-level**, using a verilog simulator (but there is non-trivial cost involved in the simulator which might put this out of reach to schools - it's more targeted at universities who are teaching embedded hardware, and start-ups). The whole Cortex-M3 processor and a supporting system can be [downloaded from ARM](http://designstart.arm.com/eval) for free. This runs code (and has a model which prints out disassembly as it runs). - disclaimer - I developed this product.


---

