Monday, January 25, 2010

6502 Assembly Language

My brother Ernie is a little more than a year than I. He was ahead of me in the programming department when we were kids, and my first exposure to assembly language was through a book he had on Z-80 assembly language. I never did have an opportunity to try Z-80 assembly, but when I had my VIC-20 I decided to try 6502 assembly language. I didn't find machine language hard at all to grasp because it seemed very similar to the language used to program calculators, especially the HP-67.

I was a regular reader of COMPUTE! magazine, and in one issue they included source code in BASIC for a 6502 machine code monitor. This was a far cry from an assembler, but it was better than nothing. I wanted to try speeding up a side-scrolling video game, so I decided it made sense to write an assembly language routine to move characters from the right to the left by one character. This is how video game graphics were done on the VIC-20. You could program up to sixty four 8x8 pixel custom characters, and you put these on the screen for some crude graphics.

So, since I didn't have an assembler I needed to be my own assembler. The VIC-20 Programmers Reference Guide included all the information I needed to write my first assembly language program. Once I had the code written, I translated the assembly language instructions into machine code. On the 6502 the instructions are in the form of hexadecimal numbers. I typed these into the machine language monitor to try them out. I don't remember if I got this to work the first time.

When using machine code in BASIC on the VIC-20, you would usually convert the hexadecimal numbers into decimal and then put them in a DATA statement. Then READ the numbers and POKE then into memory and call the routine with the SYS statement.

The great thing about the VIC-20 is that anyone can learn to do these things. It's fun!

Stop reading this right now. Go to and buy a VIC-20. Go to and buy a copy of the VIC-20 Programmers Reference. Try it yourself! Seriously!

No comments: