Learn A Little Assembly Language For The 6502 Processor

6502-assembly-tutorial

Evern wanted to write your own Atari 2600 games? This won’t get you quite that far, but it will teach you the very basics. It’s an assembly tutorial for the 6502 processor. The nice thing is that you need nothing more than your browser to participate thanks to the embedded JavaScript emulator which acts as assembler, machine, and debugger in one.

The 6502 was in a lot of early equipment. In addition to the previously mentioned Atari they can be found in the Commodore 64, Apple II, and the original NES. You can even find folks building their own computers around the chip these days (most notable to us is the Veronica project). The guide starts off slowly, providing a working program and challenging the reader to play with to code in order to alter the outcomes. It moves on to an overview of registers and instructions, operators and branching, and culminates in the creation of a simple game.

[Thanks Mathilda]

29 thoughts on “Learn A Little Assembly Language For The 6502 Processor

    1. Not to forget expansion cards for the C64 featuring a 65816 running at 4 times the clock rate. I actually owned a Rossmöller “Turbo Process” card and I remember owning a book about 65816 assembly language.

    1. Yeah, ive pointed that out several times before, but these guys don’t read the comments and seem to have no interest in publishing accurate information. This is the 3rd time in a month that they’ve claimed that the c64 had a 6502 while it really had a 6510. Not to mention the atari 2600 used a 6507 and the nes used a 2a03. Whilst all are similar or even derived from the 6502 they aren’t the same and they aren’t code or hardware compatible either. I guess the hackaday writers believe everything they read on hackaday.

      1. The 6510 is code compatible with the 6502 even down to the undocumented opcodes. The 6510 is just a 6502 with an io port that was used to control the memory map on the C64. Yes I had one when they where new. The 2A03 from the NES also used a 6502 core but lacked the BCD mode “No big deal because it was almost never used”. As to support for undocumented op codes I have no idea. The 6507 was a 6502 with fewer IO lines. The actual core is identical. So….
        6510 and 6507 are minor variants on the 6502 that are op code compatible. They are more opcode compatible than the 65c02.
        The 2A03 is opcode compatible with the 6502 except for BCD.
        You are more or less correct about them not being pin compatible but that doesn’t matter in the case of learning asembly language.
        So you are being pedantic and annoying as well as most incorrectly as far as your objections in this use case. You have won you have failed to win your anoying geek badge because you filed to be 100% while complaining about a usful simplification in an artical. You may now leave and hang your head in shame.

        1. Uh, incorrect sir. The 6510 had the extra io and also a tristate address bus, the 2a03 had an additional 22 registers to control the built in sound hardware and poll the controllers, the 6507 lacked access to interupts that were available on the 6502. So, what you are saying is basically like saying that all x86 type chips are really just 386s. While they may be opcode compatible and you can even run basic 6502 code on all 3; anything requiring the interupts or addressing more then 8k won’t run on a 6507, and any code using the extended features from the 6510 or the 2a03 isn’t backward compatible with the 6502. Not to mention that all these chips and their variations run at different clock speeds which if you had done much asm programming on chips of the erra you would realize is a big deal because it was common practice to use cycles to set up delays and other timing critical routines.

          1. The extra IO and buss on the 6510 do not effect the opcodes in anyway. The use case here is to learn assembly language not to learn how to write for a specific system. At the Op code level these CPUs are identical and in this use case they are identical.And you are still being anoying over picky and your original post was incorrect when you said that they the instruction sets where different.
            BTW clock speed is not even variant specific. Not all 6502s run at 1Mhz so difference in clock speed is a given to anyone that has ever had to count cycles.

          2. @ 1watcdr: i didn’t say they had different instruction sets i said they weren’t code compatible which they aren’t. Have you ever even done any asm coding? It’s extremely hardware specific; what good is it having the same opcodes when in order to do anything outside of basic bit manipulation you have to communicate with the rest of the system which will be totally different from system to system. You are the one being annoying and pedantic and also misleading just because the opcodes are similar doesn’t mean any code written for one system will run on another; i grew up writing asm code for the c64 and apple 2 and they’re quite different. If things were as simple as you imply how come you couldn’t run apple 2 programs on a c64? Or why did no one ever market an adapter to play nes games on another system? Not only does the original description imply that you could learn on this 6502 emulator how to program a 2600 it flat out says that the nes and 64 use the same chip as the apple. Your comment about the 6502 running at different speeds is also misleading as those other chips would’ve had different part numbers and wouldn’t have been interchanged at all. Having done quiet a bit of asm coding on quite a few arch’s i would argue that the opcodes are the least important part as all cpu’s would have functionally simmilar opcodes that will do pretty much the same things. While in order to do anything useful like use the keyboard or joystick or monitor or diskdrive required an intimate knowledge of the entire system and is totally different from system to system.

          3. steveg, you’re comparing I/O and I/O compatibility, not the processor itself. It is entirely normal for two computers having 6502’s in them to have different I/O, with different I/O registers, different clock speeds, and different memory maps, whether the memory and I/O are on-chip, on-board, or on a separate plug-in board of the computer. These things will keep them from being compatible even if they have the same processor, just as two Apple II’s may be unable to use each other’s code if they have different sets of plug-in boards installed. The 6510 does has a 6502 in it.

            On a different point, modern 6502’s have come a long way, although not as far as the x86 family has come. They are selling in huge volumes (hundreds of millions of units per year) but are rather invisible, being at the heart of custom ICs in things like engine controllers under your hood. The fastest ones are running over 200MHz. It’s the only processor approved for human-body-implantable life-support electronics.

  1. Look up a UK101. That used a 6502 but was a complete kit of parts. Every single capacitor, chip, transistor, resistor, coil etc had to be soldered to the board. I nearly wore out a 1mm iron bit doing so! Coding was then all assembly language but boy did you learn! Sigh….

  2. I find I agree with steveg here. The first thing I thought reading the article was the C64 didn’t have a 6502 (although the 1541 disk drive did). I think HAD could at least say 6502 “based” processors or something similar. All these things might use the same core but the actual part is different and it shouldn’t be that hard to specify them correctly. If someone has a C64 with a duff processor and you give them a 6502 to replace it with that isn’t going to fix their problem.

    And I did code a bending robot (beer brewing Bender) with a 6502 once, taken from a 1541 drive! I built my own computer around one to be his brain and to play his voice. I could have built it using the 6510 I guess, it would have worked the same, but then people would have complained that’s not the right chip!

    Specifying the correct part is important.

    Simon

    1. Simon, it also won’t fix their problem if you give them a PLCC or a PQFP instead of a 40-pin DIP. “6502” specifies the processor, not the package, operating voltage (new ones are spec’ed down to 1.2V), temperature range, or whether there’s also other circuitry in the package.

Leave a Reply to MarkCancel reply

Please be kind and respectful to help make the comments section excellent. (Comment Policy)

This site uses Akismet to reduce spam. Learn how your comment data is processed.