Well I took a crack at creating a program to increment a number up to a maximum value of 99. While I did create visuals for the first number, I did not get around to displaying the second number. I did however program a means for both digits to increase in a way that looked like it was counting up to 99. My approach was a bit of a cheat in that I was not actually counting to 99, but instead would only increase each digit independently. The left most digit would increase every 10 button presses, and the right most digit would increase for every button press. I stored values to count these input presses, in two separate addresses: $13 and $14. When you run my program in the 6502 Emulator, if you enable the “monitor” feature, you should see these addresses increasing and decreasing in value accordingly. O’ I should mention that the keys to change the values are the up arrow key and the down arrow key. The assignment stated to use the plus and minus keys, but I used the arrow keys for the sake of ease when testing.
Now I mentioned that I was tracking the numbers independently, however while this approach was adequate, there is a better way. That is of course decimal mode! For the non technical, it is exactly as it sounds in that the values used in a program can be a decimal.
How do they do this? Well a byte consists of 8 bits: 11000010
Now the first four to the left are called the “high byte” and will represent anything left of a decimal. The low bytes are the remaining four to the right, and represent anything right of a decimal. Now I could enable decimal mode, separate the individual values through an anding process using the “AND” opcode. Now you may be wondering what is anding, well if you skipped the hyperlink then the easiest way to explain it is a test of a true or false, but with a bias for false. All maybe or 0.5/0.5 results will always be considered false with this test so only a 1/1 situation will be considered true. For example I am doing an anding operation on 10110011:
00001111
10110011
________
00000011
Now here is the result after the AND. You may have noticed that only 1 and 1 matches remained! Also, in this particular case I we managed to save only the last four values in 10110011. This is how one could separate the value of the low byte. Ok, so what about the high byte? well we could then do a dividing operation with a logical shifting the bits to the to the right so:
10110011
—–>
00001011
This is how we can get the high byte value. Now the great thing about this setup is that you are actually counting properly, and the numbers displayed have an actual computational value. This means you can do standard math operations on them should you choose to implement it. With my cheat method, such a thing would be extremely complicated to do.
Well I believe this was the last of the 6502 assembly labs, which was unfortunate since I now understand the appeal of this chip. Even though it’s assembly language, its pretty straight forward, not to mention that it’s low memory capacity forces you to keep thing simple and not complicate things. I guess also growing up as an NES kid may have something to do with it, as I know have a better appreciation for the amount of effort, and incredible skill game developers of that era had. Getting this chip to do anything is pure wizardry, and I can totally see the magic in it!
That being said, I’ll probably still try to program some things in 6502. As a side not, I kind of feel as though 6502 is one of those things that should be taught before even touching C or C++, since you get a better understanding of how memory is stored and managed in a computer. That’s my humble opinion of course.