assemblymicroprocessorsmotorola68hc11

Can I execute an Assembly code in Motorola 68HC11 and other processors like ARM or x86?


My engineering teacher is a very stubborn man that wants to use a chip that has been gone for ages now. My question is: can I learn Assembly language for my computer and use it in Motorola or do I have to learn Motorola-specific Assembly language?

I searched the internet a bit but didn't come across a specific question like this. So I hope you guys can help.


Solution

  • You can't run 68HC11 machine code directly on a different CPU, or ARM or x86 machine code on 68HC11. You can (and should) install a 68HC11 emulator / simulator on whatever computer you're using, so you can single-step 68HC11 code and watch register values (and memory) change, and see the path of execution like whether branches are taken or not. This is extremely important for learning assembly; doing it without a debugger is like trying to build a robot blindfolded. If code isn't doing what you expected, you just single-step until something surprising happens, instead of having to carefully simulate in your head, where it's hard to avoid making the same mistake that led you to write the code that way in the first place.

    Once you learn asm for one ISA, learning other architectures is much easier, since most of the basic concepts are the same, just different registers and instructions, and probably a different set of addressing modes, etc. But since you need to know 68HC11 assembly for the course you're taking, learn that one first, from manuals and the textbook.

    Even if you never end up doing a real-world project using a 68HC11 microcontroller or one of its successors, a simple 8-bit CPU is a totally reasonable way to learn assembly language. And to get presumably comfortable with hex and binary representations of integer bit-patterns if you aren't already. To get a handle on other ISAs, just look at a diagram of their registers and an ISA quick-reference sheet, or read a quick tutorial or watch a video like Matt Godbolt's CppCon2017 talk ā€œWhat Has My Compiler Done for Me Lately? Unbolting the Compiler's Lidā€ which has a brief intro to x86-64. Especially after you've learned 2 or 3 different ISAs, you'll have a better idea of what things can differ vs. what concepts are the same across mainstream ISAs. (See also How to remove "noise" from GCC/clang assembly output? , although one downside of 68HC11 is that I don't think GCC or Clang can compile for it so you can't use them to make examples of how to do simple things in asm like loading + dereferencing a pointer).

    https://en.wikipedia.org/wiki/Motorola_68HC11 has links to manuals and some other resources. 68HC11 is an accumulator architecture (only a few registers, although 2 of them supposedly work as accumulators, so hopefully can be the destination of instructions like add).

    So your programs will tend to have more store / reload than the same program for modern ISAs like AArch64 or x86-64. But a simple 8-bit ISA is very reasonable. Be glad you're not having to deal with the complexity of 8086 with segmented memory addressing that some students are subjected to, and learning a bunch of obsolete DOS system-call APIs that are significantly different from mainstream POSIX or Windows.

    For real-world programs that might have to deal with numbers larger than 255, an 8-bit machine would be inconvenient to learn on. But hopefully your instructor will start with programs that only use small numbers. (And hopefully doing things that an 8-bit CPU can do without too much trouble.)

    Only two hex digits is less to look at in a debugger than a 32-bit or 64-bit register. Smaller architectural state (registers) can be a good thing for single-step debugging and keeping track of the "live" parts of your program state in your mind, although that means some of your program state might have to be in memory.