A first machine-code program

Here is a tiny little assembly code program, five bytes long, that you can run to make the bottom-right corner of your screen flicker. Note that it is position-independent, so you could put it anyplace in memory that you like, and it should run just fine.

			corner	EQU $05FF
	7C 05 FF	loop	INC corner
	20 FB			BRA loop
In case you have not seen assembly code before, here's what it means. The two-digit numbers on the left, like 7C and FB are the actual bytes that the 6809 can execute. The words to their right, like "corner", "loop", "INC", and so on, are the assembly code, and can be (more-or-less) easily translated into machine code.

This program has three statements. The first defines the word "corner" to be the number 5FF, which in a CoCo is the address of the bottom-right character on the video display. This is just a definition for the translator to use. It does not represent any machine instructions, so there are no numbers to the left of it.

The second line is the instruction to increment the byte at that address. This changes the lower-right character on the display. This line is assigned the name "loop", for future reference. The actual increment instruction is 7C, and the next two bytes give the address of the byte to increment - 05FF.

The last line is the instruction to branch back to the previous one. It is actually the branch instruction (20) followed by a representation of negative five (branching by zero bytes would mean to continue with the next instruction, so -5 means five bytes before that: back to the increment).

Here is a BASIC program to POKE that into memory and run it. Note that I just made this up off the top of my head, so I can't guarantee that it will actually work. (Congratulations! You are now a Beta Tester! Let me know how it goes!)

	100 CLEAR 10,3999
	110 POKE 4000,124
	120 POKE 4001,5
	130 POKE 4002,255
	140 POKE 4003,32
	150 POKE 4004,251
	300 EXEC 4000

I have now tested this on a 64K CoCo 2 with Extended Color BASIC, and found that it ran out of memory - OM ERROR IN 100. Extended BASIC wants more than 3999 bytes for itself. It worked when I cranked that up to 7999 bytes, and adjusted the POKE addresses accordingly. Of course, 4K CoCos could not use this new one, so I'm leaving the old one there until I get news on how it works...
	100 CLEAR 10,7999
	110 POKE 8000,124
	120 POKE 8001,5
	130 POKE 8002,255
	140 POKE 8003,32
	150 POKE 8004,251
	300 EXEC 8000
Back to my top-level CoCo page


8-Jun-98
yakowenk@csx.unxc.edu
(remove all "x"s to get a valid address)