en en en pt es en en en en cv en en en en en en en en en en en es en en en en en en en en en en en en en en en en en en en en en en en en en en ca es en es ne en en en en en en en en en en fi en fr en en en en en en en en en en en uk en en fr en en en fr en en en en en en en en en en en en en en en fr en zh nl en en en en en en en en en en en en en en it en en en en en en en pt en en en en en en en en en en en en en en en en
I would like to say that I’m not suggesting the teaching of assembly should replace teaching of high-level languages. What I would like to do with assembly, is give students a short 2-4 week introduction to computers and programming. Fundamental concepts such as integer arithmetic, branching, the run-time stack, recursive function calls and arrays would be exposed in a very concrete, hands-on manner. Ideally, students should then be able to move on to higher-level languages with more confidence, and perhaps even learn more advanced material at a faster pace.
The positive responses to my post have motivated me to go ahead and develop an online emulator for simplified assembly, and perhaps even build a series of tutorials around it (help with the writing would be appreciated). I don’t necessarily think that this system will be the perfect learning platform for everybody, some people might learn better with other teaching methods, but I certainly think it’s worth at least putting it out there and letting people try it. If just a few people learn something, I’ll be happy. I, for one, think I would have loved such a system when I was 9-10 and started getting interested in computers!
Some people have asked why I’d want to design my own assembly and emulator when there are other existing assembly options out there, some of which already have browser-based emulators. It has been suggested, for example, that I could instead use (from most to least practical):
Notch’s DCPU-16 architecture (in-browser emulators exist)
6502 (NES, C64, Apple II) assembly (in-browser emulators exist)
A subset of ARM assembly
Physical microcontroller devices (Atmel, PIC)
I’ll go right ahead and confess that I do like the idea of rolling my own, and I feel very confident in my own ability to do so. This isn’t the only motivating factor, however. While it may not have as much SWAG as a physical computer, there is clearly a definite teaching advantage to having an in-browser emulator that can be accessed from anywhere at a cost of zero dollars and can’t be broken by accident. As for other assembly languages, I feel they generally have arbitrary restrictions that will hinder teaching. My goal is not really to simulate a retro computer, it’s to make the language as accessible as possible, and things like having only three usable 8-bit registers can get in the way.
As is usually the case when I start getting excited about a project, I had a flood of ideas for my emulated system. I’ve been giving some thought to architectural considerations, trying to strike a balance between realism, simplicity and ease of use by novices. The following is largely a brain dump of my thoughts on the design of the system:
The instruction set will have the standard arithmetic (add, sub, mul, div, mod) and bitwise (and, or, xor, not, shift) operations, as well as multiple conditional branching instructions. The goal is not to make the instruction set as small as possible. It is to make it somewhat realistic, very easy to grasp, while demonstrating important concepts.
I’m thinking a 16-bit architecture might be best at this point. All registers would be 16-bit, and the memory space would contain 64K words (either 8 or 16-bit each). As someone pointed out, 16-bit registers can easily be displayed on one page, showing all the bits. A 64K memory space is small enough that one can easily visualize it and see the stack pointer move, while being large enough to allow useful programs to be written.
There will most likely be 16 registers in total. 12 fully general-purpose registers, a flags register, the stack pointer, the instruction pointer, and another register currenty reserved for future uses. All registers will be usable in any operation that can take a register argument.
The instruction encoding will be fairly naive. Variable length. One opcode byte, one operand format byte, extra bytes for operands (register indices or constants). The point is not to have a realistic ARM or x86-like encoding, but rather that the instructions have an encoding in memory, and that this encoding be easy to decode if desired.
I’m unsure at this point if the RAM should be byte-addressable, or addressable only by 16-bit words. The latter has the advantage that we get twice the ram (128K!) and we can probably offer better visualization of values in the RAM, as they couldn’t be unaligned. The disadvantage is that real-world systems are usually byte-addressable (sort-of?).
I was initially thinking of memory mapping (DMA) all the display memory. This is problematic because even at 256×192 and 8 bits per-pixel, that’s 48KBs, most of the RAM. I think I will instead rely on a virtual display adapter that responds to simple commands (draw a square, draw a circle, draw a line, draw a sprite) and has its own memory spaces for the frame buffer and sprites. This will allow me to “cheat”. RAM will be freed, people will be able to plot individual pixels if they so desire, but they will also be able to do fast rendering of decent-resolution graphics in 24bpp glory.
I’m thinking the sound chip should probably be a simple 16-voice subtractive synthesizer, with the standard waveforms, an LFO and a filter, all able to follow individual envelopes. The possibility of playing raw audio data would be trivial to support as well.
For some realism, virtual devices will be interacted with through a simulated parallel master-slave bus (the CPU being the master, all devices being slaves). Communication will be in the form of 16-bit words. Library routines will be provided to wrap all the gory (not that bad, actually) details and provide simple calls that satisfy most use cases.
The library code will be browsable (read-only), and possibly indexed with a doxygen/javadoc-like system, allowing you to get a description of all available routines and even see their implementation if you so desire. The library should be fairly extensive and allow you to get started writing useful programs right away.
I’m not sure if it’s best to grow the stack up or down. Is there a disadvantage to growing it upwards?
I’ve been thinking of a name for the system. Right now I’m leaning towards toyCPU (short and sweet).
I’ll look into possibly using Google AppEngine to store user-created programs online, and perhaps allow users to rate them, comment on them and fork their own version. This should help grow a user base.
I already started working on the implementation. I decided to use the CodeMirror library to give the code a nice display with line numbers and syntax highlighting. I think I might start to have something working this weekend, but I probably won’t make it publicly available until it’s closer to complete. I figure it’s best to wait until the implementation is relatively stable and there is a mechanism to share your code online so that people don’t waste effort or lost interest before the system is ready. I may, however, be willing to share a link with a few people early (beta testing, anyone?).
If you’re interested in helping, I could use help at various stages:
Setting up an AppEngine platform for code sharing and community building.
Writing virtual devices, such as the graphics adapter, the sound adapter and the system clock.
Writing the standard library.
Writing cool demo programs (simple games, music, basic/scheme interpreter, demoscene, etc.)
Promoting the platform and tutorials.
If you’re interested in helping, please let me know. I will warn you that I’m somewhat of a code nazi, but I do my best to be friendly.
From → Assembly, Compilers, Microprocessors, Programming
I can find a close resemblance of the architecture you described with the Intel 8085. Although I do not have much experience of programming in different old architectures, but I can tell that Intel 8085 is a pretty simple one to grasp. Its instruction set is also pretty simple and easy to make an emulator. I made one, which required machine code to be entered after hand assembly, the design was very simple, though lengthy code to emulate each instructions. For starting assembly and get the feel of the underlying hardware I think it would be easier, as the architecture is easy to understand than modern CPUs therefore I think the Intel 8085 instruction set is worth to have a look.
“I will warn you that I am a code nazi” That’s the end of this project. Every software engineer HATES code nazis!!!!! Even code nazis hate each other because that can’t agree on coding styles.
The software engineering field is a sellers market, Most software engineers have now trouble moving away from annoyances like code nazis. Management learns very quickly that when the code nazi is placed on their project that all the good engineers move on. Then they are left with the bag trying to explain to upper management why the project failed. There are only two situations where the programers have to listen to the code nazi. A) They are an indentured servant laboring under an H1-B Visa. b) They are an indentured servant laboring under a major professor in grad school.
Rarely if any program is written by one person. Just about every program is written as a collaborative effort. Everybody needs to get along. Part of that is respecting the work of other team members. Lambasting former team members work is acceptable. But being a code nazi and criticizing the style of somebody else code get’s you no where. Any criticism needs to be universally viewed by other team members as constructive.
I try to keep my criticism relevant and constructive. I don’t really criticize people on their coding style, although I do encourage people to try to follow the style of the project, and follow good practices like documenting their code using doxygen/javadoc/jsdoc and not leaking a million things into the global namespace.
My coding effort is progressing fairly well so far. I’m already using other people’s code in there (I chose the CodeMirror js lib for my code editor). I will probably end up putting the code on github under a BSD license when I feel I have something worth showing (hopefully just a few days from now). Hopefully, if I can get the attention of some programmers, some people might be willing to help me add features. I have a long list of cool things I’d like to implement, probably too long for just one person.
“Every software engineer HATES code nazis!!!!!”
Well, that’s your opinion but that doesn’t make it a universal truth.
I, for one, prefers contributing to projects with strong code guidelines and will make sure to respect them to the best of my capacities. It’s not about criticizing others for the fun of it but instead aiming for more homogeneity through defined rules.
I’m also the main developer (ie. code nazi) behind an open source project written on my spare time that grew over the last few years to a not-so-big but decent 180k lines of code.
There have been quite a few contributors in the community and they’ve all very strictly followed the code guidelines/style.
Those are not even written anywhere! They simply achieved it by mimicking the code already present and no one ever complained.
It’s actually quite the contrary, many (contributors or users) have praised the consistency of the code finding it was much more accessible and readable than the average.
Maxime, I don’t currently have much spare time but I’ll be following your progress closely as soon as you make your work public and will happily contribute later on, if you still need it. =)
The code is progressing well so far. I hope to have enough to show within a week or so. I minimally need to have some graphical output capability and the beginnings of a standard library. I will likely put the code on github and post an update on this blog, along with a list of tasks I could use help with.
toyCPU Project Update « Pointers Gone Wild
…and so it begins | SIDWIB
Leave a Reply Cancel reply
Enter your comment here...
Fill in your details below or click an icon to log in:
Email (required) (Address never made public)
You are commenting using your WordPress.com account. ( Log Out /  Change )
You are commenting using your Twitter account. ( Log Out /  Change )
You are commenting using your Facebook account. ( Log Out /  Change )
Notify me of new comments via email.
Notify me of new posts via email.
« toyCPU Project Update
A Radical Introduction to Programming »
Typed vs Untyped Virtual Machines
Minimalism in Programming Language Design
Democracy, Dictatorships and Access to Information
Code that Doesn’t Rot
The Internet Changed My Life
What’s Could You Use Tesla Bot For?
NoiseCraft: a Browser-Based Visual Programming Language for Sound & Music
Art Artificial Intelligence Artificial Life Assembly Biology Compilers Creativity D Language Electronics Future Game Development Genetic Algorithms Grad studies Graphics Higgs JavaScript Microcontrollers Microprocessors Music Programming Programming Languages Psychology Rant Robotics Tachyon Technology Uncategorized work x86 Zeta
Archives Select Month June 2022  (1) May 2022  (1) March 2022  (1) February 2022  (2) January 2022  (2) December 2021  (1) June 2021  (1) February 2021  (2) December 2020  (1) September 2020  (1) January 2020  (1) November 2019  (2) October 2019  (2) June 2019  (1) January 2019  (1) December 2018  (1) May 2018  (2) February 2018  (1) January 2018  (1) December 2017  (1) October 2017  (1) June 2017  (1) April 2017  (1) January 2017  (1) December 2016  (1) November 2016  (2) September 2016  (2) May 2016  (1) March 2016  (1) February 2016  (2) January 2016  (1) November 2015  (4) October 2015  (1) September 2015  (3) August 2015  (2) July 2015  (3) June 2015  (1) May 2015  (3) April 2015  (2) March 2015  (1) February 2015  (1) December 2014  (1) November 2014  (2) October 2014  (2) September 2014  (3) July 2014  (3) May 2014  (1) April 2014  (1) March 2014  (1) February 2014  (1) January 2014  (3) December 2013  (3) October 2013  (2) September 2013  (1) August 2013  (2) July 2013  (3) June 2013  (2) May 2013  (3) March 2013  (2) February 2013  (1) January 2013  (3) December 2012  (4) November 2012  (1) October 2012  (1) September 2012  (3) July 2012  (4) June 2012  (2) May 2012  (2) April 2012  (4) March 2012  (2) February 2012  (3) January 2012  (6) December 2011  (2) November 2011  (3) October 2011  (8) September 2011  (4) August 2011  (3)