Week 7 – October 28, 2009 – Motorola 68k Simulator
Just FYI, I haven’t totally forgotten about these weekly projects. It’s just that two weeks ago I was super busy, so I couldn’t do any projects. Last week, however, I started working on something. However, even after ten hours of development, it’s not even close to finished. I am going to try to get it to at least a publishable state by the end of this week. And until then… I will let the anticipation keep you up at night!
Purpose:
In my Computer Architecture class, we’re learning Assembly by going over the relatively basic processor called the Motorola 68k. This processor was very popular Easy68k stands out for the Windows platform.
However, I figured it would be a nice learning experience (and simultaneously help me study for the class) if I were to create my own. I figured I didn’t want to reinvent the wheel and create a desktop application, since Easy68k does everything I wanted mine to do plus a million times more (like having support for running real 68k assembled program… which means it understands the actual instruction -> machine code translation, which I currently have zero interest in implementing due to the tedium). That narrowed it down to either a web application or an iPhone application, and I decided to make it for iPhone so I could have it with me anywhere.
iPhone Notes:
I decided right off the bat that I wasn’t going to try to make a full emulator with video hardware emulation and such (which Easy68k does, by the way – I am very impressed by what they did), but instead I would just have a way to look at all the registers and memory, and then enter instructions one at a time.
I decided to set up memory using a character array of 0x2000 bytes (really 8192 bytes), with the stack starting at 0x2000 and everything from 0-2000 addressable by the user. Internally the registers are strings which are 8-character hex values.
Since I wasn’t planning on assembling the instructions, I set the Program Counter to 0x4000 which is the imaginary area in memory where the machine code would go. All it really does it just increment by 1 each time an instruction is run, like it should, but it doesn’t point to anywhere real.
As far as the actual instructions go, I have the MOVE instruction (almost) fully implemented. See the “Missing Features” listed below for some of the things it can’t do. However, it DOES support all of the addressing modes on the M68k, including the post-increment, pre-decrement, and the xxx(An, Xn.S) type. It supports all three types of numbers (binary %, hex $, or decimal). It has pretty decent error-checking if the syntax is wrong or illegal things are attempted (for example, if you try to use an immediate value like #5 as a destination).
I plan on implementing ADD next. It shouldn’t be that bad since I have the addressing modes are done, but it will require me to start working with the status register (SR) for overflow and carry and such.
As I update the program with features, I will describe them here. Unlike my other projects, this is one that I plan to actively add to as this semester goes on. In fact, it may stand in as my project for the next few weeks.
You can download the source code and run the program in the iPhone Simulator (if you have XCode and iPhone SDK installed) here.
Known Bugs/Missing Features:
This is both for me and anyone who wants to test/use the application. If you find a bug/unexpected quit/problem that is not listed here, please let me know what you did to cause it so I can take a look.
- Moving less than long word into an address register doesn’t yet extend sign appropriately
- There is no special addressing mode for PC register
- The status register does nothing right now (not like MOVE can really cause status things anyway — or can it?)
- “move.l $11(a0, a6.w), d4” type of instruction only moves Word (2 bytes) from resulting memory address