I think my approach to trying to learn 6502 Assembly language programming has been all wrong so far.
Pretty much every book or guide I’ve come across that was written back in the 80′s (all of ‘em?) starts off with a very basic – and wholly inadequate – primer on binary and hexadecimal math. This is immediately followed up with dire warnings that to continue without understanding is to court disaster. Consider the following quote from Software Masters’ ‘The Visible Computer: 6502′ manual in the opening chapter on alternate numbering systems:
“If you are fuzzy on the hex and binary numbering systems, do not skip this chapter. Learning machine language is a cumulative process and skipping a critical part of the foundation is a good way to build an unstable building.”
The other manuals have similar dark prophecies of disaster for those who would careen headlong into the Apple II mini-assembler without knowing how to add 1011 0110 1010 to 0011 0011 1001 by hand, or convert $EA into binary and then to decimal and back again without the aid of a calculator.
But here’s the thing. Those calculators are everywhere today. Online Javascript calculators and converters abound — heck, even the little freeware calc app on my Android phone will do it easily and quickly. So the question becomes, is it necessary at this point to digest this material before I move on? My instinct is that it is not, though I could be wrong. If ever I were stuck on a deserted island with my Apple II, an intense desire to program in assembly, and lacking a calculator, I would admittedly be in trouble. But this scenario only happens to me once every three weeks or so, so I feel confident that I could settle for playing Lode Runner while I wait for rescue.
Sure, there’s probably some geek cred points to be awarded for being able to handle such calculations using only the evolution-given wetware that exists between our ears, but to be honest, this has been the one sticking point for me every time I’ve tried to dive into learning assembly. ‘VC:6502′s opening chapter, and the similar text that appears in other manuals of the day has been a formidable gate-keeper for me and, I imagine, many curious would-be programmers just like, for too long now.
To be clear, this is the fault neither of the books themselves or their (mostly) excellent authors, rather it is a quirk in my learning skills that I don’t easily extrapolate new illuminations from basic ideas, no matter how well laid out.
And so I decide to take the ultimate risk and sally forth into the unknown of the ‘language of the computer gods’ without the aid of a binary math net. Wish me luck, dear friends and should I not survive the night and meet my grisly fate at the hands of a grue in a dark corner somewhere, or more likely suffer synapse failure fall trying to understand the vagaries of bit shifting, hoist a flagon of ale in remembrance.
In the meantime, I’ll be over here.
After decade and a half of math taught using decimal, the value of hex numbers isn’t really intuitive. On the other hand, after many years of programming, “computery math” like working with pointers or masks doesn’t make sense in decimal either.
I personally find that I use the different bases for different things and leave it at that. The only time I really need help is converting hex values to something I want to see in decimal when debugging as it’s a little tedious. Fortunately with two extra keystrokes GDB does it for me.
You don’t need to have an innate ability to “see” bit patterns in your head and convert from hex to decimal to binary, but it does help. Especially when you get into esoteric situations where you’re doing bit shifts or rotates, for example – and what that does to the resulting digits. Similarly for knowing what the effect of ANDing or ORing stuff when you’re trying to mask off or isolate a bit. It won’t keep you from being successful at machine language, but it will cause you to wonder why the other programmers are so smart and savvy with their ridiculously simple and elegant solutions that take you pages and pages to accomplish. It happens to me all the time.
Thanks for the comments. I should point out that I’m not intending to avoid/ignore the minutiae of binary and hexadecimal math, just that I’m no longer willing to let that be a sticking point to diving in and learning assembly.
Heck, at some point, I expect I’ll encounter a problem I want to solve using assembly that will require more of me than I can solve with a Javascript calculator. Until then however, it’s onward and upward.
Hi Mike,
Thanks for your post! I studying the 6502 Assembly too, and I’m enjoying it very much. I love the Apple II since the early 80′s and now I’m having the opportunity to dig deeper into this amazing machine.
After buying many books from the 80′s on the subject, including the Visible Computer that you mentioned, I also have the feeling that for us today learning Assembly would be “easier”, considering the myriad of available tools online and in our smartphones.
I’m a professional iPhone and Mac programmer and I think that most books about coding have a difficult approach for the student, specially those trying to learn their first high level language. And by reading the books from late 70′s and forward, I still have the same feeling. It’s always hard to teach, and even harder to learn, no matter how much they say that “this language is easier to learn that that one”.
But, the most important thing in our journey learning the 6502 Assembly language, in my opinion, is not giving up, having in mind that we’re doing it for pleasure and fun, without the pressures of the past when people were competing for a share in the software market, to make a profit out their hard programming work.
Again, thanks for your blog and thanks for your post! I don’t feel alone anymore in quest for knowledge to conquer the Apple II’s brain!
All the best, and please keep us posted about your progress.
Neo Winston
I think it IS neccessary to understand these calculations. Think of a RAM/ROM-expander connected to your expansion port using some glue logic. To speed up things or only to em working you should really see the bits in a byte, otherwise you’ll never really understand what’s happening. Other examples are the hardware connected to the 6510′s IO in a C64 and lots more.
Youre using assembler where high level languages arent fast enough, small enough or even not available. On these platforms you need to know whats going on…
Keep on learning, everything up to x86 is very easy