6502 Machine Language for Beginners
savetz writes "If you've always wanted to learn 6502 assembly language, now's your chance. The full text of the classic, best-selling 1983 book Machine Language for Beginners is now on the Web. It includes examples and program code for Atari 8-bit, Apple ][, PET/CBM, VIC-20, and Commodore 64 computers."
An old eight bit processor is the best tool for understanding how computers work. They are simple enough to avoid discouraging the student, but the core concepts are still the same today. There are free simulators, so students don't have to put up with uncomfortable data entry or long loading times.
Yeah, but you have to clear the carry (CLC), *then* Add with Carry (ADC) to perform what a normal ADD would have done on other processors. Struck me as funny when I first learned 6502.
This isn't "funny" at all. Remember that when working with an 8 bit value, addition operations on single-bite, not to mention multi-byte, values have a high chance of overflowing the 8 bit register -- thus setting the carry. It's no more odd to CLC (Clear Carry) than to load a register with #$00 to start a loop.
In fact, ADC (Add with Carry) is an abstraction that allows the same instruction to be used for both single- and multi-byte additions. The beauty of the ISA is the small number of operators to fit the small number of registers available.
If ADC didn't work in this way, in what way would you have it work? And what would you like to see happen when you added #$FF to #$02? Forty miles in the slow uphill both ways gravel in my boots kids these days...
I've always considered the 6502, more or less, a RISC processor due to it's uh, "simpleness".
.X is __, .Y is __ and the carry flag is set and the Z flag is off were my normal thoughts while writing assembly.
It has 3 register, 8-bit address lines, 1 accumalator and two index registers. That was pretty much it along with 52(I think) opcodes and variants in terms of addressing modes.
The chip was neat in that it was simple enough for someone programming it to be cognizant of everything going on inside the processor: Ok, at this stage the accumalator is __,
I can't speak for any of the other 6502 computers but the way that it was used on the C-64 was an engineer's wet dream. It was coupled with other chips that were simple in their operation but complex in their innards. There was no filtering of bad input data - if you fed it crap, the chip was free to interpret it however it wanted.
This ability to send "crap" data was pretty neat because once you got the timing down right you could do pretty miraculous things - that weren't even listed as features for those chips.
Bonus question: How can you disable the NMI interrupt on the 6502? (Yes, there is a way).
There's a gorilla from Manilla whose a fella that stinks of vanilla and has salmonella.
See also www.cc65.org
...
:-)
Now I shall demonstrate why Ada is a better choice for this sort of thing.
In this bit of documentation, it is suggested that you get better code by putting an extra cast into an expression which keeps everything nicely eight bitted. The C language definition AFAIK requires that the compiler behave in this (odd) way.
The Ada equivalent is this:
A : Octet;
if (A and 15) = 0 then
You don't have to remember to cast, and it's all 8 bit. Ha!
In the future, all new Commodore 64 software will be written in Ada
The earliest religious war I took part in was between the 6502 users (eg PETs) and the good guys, like me, who hacked on the Z80 (eg most/all CP/M machines).
Have to say that the intellectual case for the 6502 looked stronger, but seems to me that the Z80 has lasted the course better (though not as well as the 8080 family which the Z80 was meant to be an improvement on!).