CMPE12, Spring 2012, Section 01: Lab 7: Blind the zombie with light patterns

Lab Objective

Programming the HC11 microkit is great fun! Not only do we get to learn a new assembly language, but also we get to make lights blink! The cool things about the HC11 Microkit are

  1. It's a totally custom piece of hardware, designed and built a long time ago by students in CE121!
  2. You can interact directly with the hardware via memory-mapped I/O!
  3. A CISC processor, there are tons of really complicated instructions which all do the same thing!

You are stuck in a room with a zombie. This zombie blurts everything you say back at you into its rot-13 equivalent (described below). The only way to escape is to blind the zombie with three light patterns!

Lab tutors: Go over these topics

A listing of the HC11 Instruction Set is available here!

A pdf version of the Reference Manual is available here!

Your lab tutor will cover the following topics in the first 40 minutes of lab.

  • How to set up your HC11 microkit
  • How to modify, assemble, download, and run a program on the HC11
  • How to look up assembly language instructions in the reference books
  • How to use the CMP instruction prior to a branch

Lab 7: Blind the zombie: ROT-13 with light patterns

The HC11 has three ways to display output: to the console via the serial port; to the 16-character, two-line LCD; and to the eight LEDs.

For this lab, you will create three (3) interesting light patterns to blind the zombie and to escape the room. For extra credit: You will accept character input from the keyboard and convert it into its rot-13 equivalent.

What's required

A checkoff, lab7.asm, and the write-up

A checkoff really is required this time to ease the grading necessary. You must come to lab on the second day of lab sessions.

More specifically, your program must...

  • Be written in HC11 assembly language and run on the HC11 microkit.
  • Loop forever without crashing.
  • Contain 3 different, distinct light patterns generated by dissimilar code. They must be toggled by the interrupt buttonas described below.


  • ...And no, a light pattern created with INCA and one with DECAare not different (nor can you use either one of them: the zombie will eat your brains). Be more creative.
  • Not contain the example light pattern shown in Figure 1 (below). Make your own.

Procedure (basic requirements)

Here is how your program should run.

  1. Display a greeting to the LCD.
  2. Start your first light pattern, and keep it going indefinitely.
  3. Light patterns must be toggled with the interrupt button. Basic interrupt button code is provided in the lab description below. The light pattern program flow is as follows. * Light pattern 1 until interrupt button is pressed (then: start light pattern 2) * Light pattern 2 until interrupt button is pressed (then: start light pattern 3) * Light pattern 3 until interrupt button is pressed (then: start light pattern 1) If you were displaying the first pattern, switch to the second light pattern (and vice versa), and keep it going indefinitely.


Procedure (extra credit requirements)

For students that have already started the rot-13 part (or just really like the HC11), rot-13 is 6 points extra credit when implemented as follows.

  1. Display a greeting to the LCD.
  2. Start your first light pattern, and keep it going indefinitely.
  3. The switches are a "mode" toggle for the program. That is: if SWITCHES == 0, program behaves as light pattern program, as in the basic requirements section above. Otherwise (if SWITCHES != 0) the program behaves as a rot-13 converter, accepting input from the keyboard indefinitely. There is no "exit" character.
    • Alphabetic characters (A-Z, a-z) must be converted to their rot-13 equivalent (by adding or subtracting 13, as needed).
    • Numbers, punctuation, and special characters are not transformed (they are echoed back to the user).
    • As soon as SWITCHES changes from 0 to nonzero, the program must switch from the LIGHTS mode to the ROT-13 mode.
    • As soon as SWITCHES changes from nonzero to 0, the program must switch from the ROT-13 mode to the LIGHTS mode.

Setup: How to Begin

  1. Read Section 3 in the Lab Manual for an introduction to HC11. Section 3.3.1 tells you how to build and run HC11 executables.
  2. Use the SSH client to connect to
  3. Set up your HC11 environment in UNIX. You will only need to do this once after your shell has been changed.
    • Change your shell to bash (if it's not bash or tcsh already). If you don't know what this means, ask your lab tutor. Type chsh at the command line, and then, when prompted, enter /usr/bin/bash
    • It will take about 2 hours for your shell to be changed. In the meantime, type bash at the command line to spawn a bash shell.
    • Verify that hc11build is in your path. Type hc11buildon the command line and see that you get compiler errors.
    • Investigate the example program, echo.asm. You will need the include file (v2_18g4.asm).
    • You can use hc11build to build your HC11 assembly files (.asm) into s19-record files (.s19).
  4. Assemble the example program (with the include file) and run it on the HC11 microkit. There are instructions on how to do this in the Lab Manual (linked above).

On Light Patterns

Start with some example light patterns.

  • Investigate the example light pattern in Figure 1.
  • Assemble and run the example light pattern. What is it doing?
  • Check out the light patterns in Figure 2. How would you implement them? What are they doing?
  • Add an interrupt service routine.

You can download and run this example light pattern s-record file to see how pressing the interrupt button would toggle between two light patterns. The program prints an 'a' to the console when in the first light pattern loop, and 'b' when in the second.

counting light pattern
/* A simple light pattern



#include <v2_18g4.asm>

	.sect .text

main:	ldaa	#0	// initialize pattern,

pattern:		// all lights on.


	coma		// complement lights

	staa	LEDS 



	ldd	#0x80	// .5 sec delay 

	jsr	WAIT 


	jmp	pattern 

Figure 1: Counting light pattern using INCA. For space reasons, only the first 15 bits of the pattern are shown.

example light pattern example light pattern

Figure 2:Two example light patterns. One is formed by using logical shifting, and the other uses a secret method. Which is which, and what's the secret?

Light pattern hints

A few notes on the light patterns...

  • The lights are active low -- so writing a 1 to a light makes it turn off.
  • Another light pattern idea: See Figure 3
  • Another light pattern idea: accelerating (decreasing/increasing) the delays as the pattern moves forward
  • See Figure 4 for an example interrupt service routine.

Night rider scannerFigure 3:Night Rider scanner light pattern uses 3 lights going back and forth.

/* A simple interrupt routine


#include <v2_18g4.asm>

	.sect .text

// intialize user-defined interrupt vector

main:	ldx	#my_interrupt

	stx	ISR_JUMP15	

loop: jmp	loop 		// does nothing

// my_interrupt is triggered when the user

// presses the IRQ button the HC11 kit.

// side-effects: displays 'Hi' to LCD


	ldd	#0x4869		// 'Hi'





Figure 4:An example interrupt service routine (triggered when you press the IRQ button)

What is ROT-13?

Rot-13 is a simple cypher which rotates each character by 13 places. That is, A becomes N, B becomes O, and so on. You can read more about it on Wikipedia's ROT13 page. See Figure 5 for a graphical representation of rot-13.

rot-13 Figure 5:The graphical representation of rot-13

You can think of rot-13 as the following piece-wise function.









                   Input letter + 13, if input letter is a-m | A-M

Output letter =  { Input letter - 13, if input letter is n-z | N-Z

                   Input letter,                         otherwise

Another way to look at the algorithm is this pseudocode.

// Convert: returns rot-13-ified input

convert (input) {

    // Letters A-Z

    if (input >= 'A' && input <= 'Z') {

        if (input >= 'N') {

            // N - Z

            output = input - 13;

        } else {

            // A - M

            output = input + 13;



    // Letters a-z

    else if (input > 'a' && input <= 'z') {

        if (input >= 'n') {

            // n - z

            output = input - 13;

        } else {

            // a - m

            output = input + 13;



    else {

        output = input;


    return output;


For our purposes, rot-13 affects only alphabetic characters (that is, letters A-Z and a-z). It does not affect special characters (punctuation) nor numbers (0-9). The user is expected to enter an entire sentence -- all sorts of characters. Newline ('\n') by itself (as the first character of input) indicates the change of light pattern.

Rot-13 converter

This rot-13 converter is released under the GNU General Public License (GPL) and requires JavaScript. You will find it on this linked page.

ROT-13 Hello!

References and other useful things

The Programmers' Reference Guide (PRG) will be your bread, and the Motorola Reference Manual (MRM) will be your butter for the rest of the CE12 class. Or the MRM will be your bread, and the PRG will be your butter. Or wait -- the PRG your bread, and the MRM your -- well, the PRG and MRM will be your various breads and butters.

Grading template

This is a suggested grading rubric. Your tutor may or may not use this rubric to grade by, but it is a good general guideline before submitting your code to check off these points.

Coding requirements

  • (10 points) Correctly assemble; contain comments; be readable; follow assembly programming convention
  • (5 points) Display a greeting to the LCD
  • (25 points) Show three distinct light patterns, and toggle with the interrupt button
  • (5 points) Loop forever and do not crash
  • (5 point) Miscellaneous errors

    Total: 50 points

  • Extra credit (10 points): In addition to basic requirements above, convert alphabetic characters to their rot-13 equivalents; do not convert non-alphabetic characters (numbers, punctuation, special characters - try back-tick (`), bang (!), tilde (~), the delete key, and other edge cases); toggle mode with switches input as described

Lab write-up requirements

Don't forget about the write-up, which is still worth 50 points.