29 ms·
I believe 6502 instruction set is a good first assembly language
- ein0p 2y agoThe best beginner assembly hands down is Z80. It may be a bit harder to start with, but if I could write games in it at 14 years old, an adult should have no issue at all.
- quantified 2y agoBiased here (it was my first language period), but I agree. Simple addressing modes. Getting started with x86 seems like it would warp the thinking a little bit, you can always pick its peculiarities up later. Having worked with the 6809 series as well, it wouldn't be a bad choice either. The Freescale 68HC12 is still in production. Little systems with limited-yet-real I/O give the programmer very useful feedback.
- musicale 2y agoThe 6809 seems like a more powerful (16-bit accumulator and index registers, multiply instruction) and orthogonal 6502 (itself a cheaper/simpler 6800) with fewer (possibly charming) quirks? The 6502 won in the marketplace though, apparently due to its lower cost (the 6809 had nearly triple the transistors.) It's nice that it's still in production if you want to build a breadboard system.
- quantified 2y agoThe Dragon-P eval board has a keypad, breadboard, and small display. Great for getting close to the metal.
- djmips 2y agoIndeed the 6809 has several 16 bit stack registers as well as 16 bit X and Y index registers which mean you can use proper structures and it even has a decent mul instruction.
- ergonaught 2y ago6502 and 680x0 were just a delight. I learned C (and later C++) solely because I couldn’t escape x86 anymore and hated assembly on those chips. Still do, really, though I’m decades beyond wanting to write anything in assembly now.
- ack_complete 2y agoI love 68K. So nice to read with the separated data/address registers, and between the instruction set and addressing modes you can easily translate idiomatic C into reasonable 68K assembly. Main downside is that with 68K you're more likely to be loading your program into an OS rather than bare metal hardware, and have to deal with things like relocation.
- bb88 2y agoI got into 6502 assembly when trying to do bit manipulations on an Apple IIc back in the day. The problem was that Applesoft basic set the high bit on data going out a serial or parallel port which was a problem for printing and sending data out through a modem. So if you wanted to keep the high bit one had to use 6502 assembly.
- dhosek 2y agoI’ve only ever learned two assembly languages: 6502 (when I was in elementary school in the early 80s) and 370 (my senior year of high school when I had access to the UIC mainframe thanks to taking night classes there). I can roughly follow the output of godbolt on those rare occasions that I’m curious enough to bother, but the complexity of modern CPUs and computer architectures are such that I don’t know that I really need to deal with assembly language now. That said, my mental model of how a computer works at a low level is very much based on how the Apple II was set up.
- WhitneyLand 2y agoSame, learned as a kid. What was your motivation? Mine was wanting to make games and hitting the performance wall in basic.
- kstrauser 2y agoThat's what did it for me, too. The magazines at the time said that if you wanted to make your game run faster, you had to write parts of it in assembly. I was fortunate that no one told me that was supposed to be harder. I just knew that it was different, and it never occurred to me to be leery of it.
- dhosek 2y agoPretty much all kids want to write games.
- serviceberry 2y agoI really don't see how. When students are first exposed to computer programming, it might make sense to start with toy / compact languages that don't have any real-world use. But assembly is not the first language you're supposed to learn! It's very utilitarian and most commonly just used for debugging and reverse engineering. So why would you waste time on the assembly language of a long-obsolete platform? Plus, the best way to learn assembly is to experiment. Write some code in your favorite language and look at the intermediate assembler output, or peek under the hood with objdump or gdb. Try to make changes and see what happens. Yes, you can do that with an emulator of a vintage computer, but it's going to be harder. You need to learn the architecture of that computer, including all the hardware and ROM facilities the assembly is interacting with to do something as simple as putting text on the screen... and none of this is going to be even remotely applicable to Linux (or Windows) on x86-64.
- chasil 2y agoIn many decades past, there were no high level languages, and assembly was the only language. It was a very different time. Those people would be equally astonished at our casual computing devices and ignorance at how they work. Oddly enough, my current karma score is 6502. Synchronicity indeed.
- kazinator 2y agoThe era in which there was nothing but assembly language was very short-lived. By the time the 1950s were over, we had higher level languages. Like before The Beatles recorded their first album.
- analog31 2y agoIn addition to be a good starting point for programming, the 8-bit micros are also a good way to begin learning about the hardware side of microprocessor systems, since the external stuff (memory chips, etc.) was correspondingly simpler as well. And without pipelining, you can form a more straightforward mental model of what the system is actually doing. For me, it was Z80, just because Radio Shack had a book on it. I never actually built or programmed a Z80 system, but I still fall back on that knowledge when working with microcontrollers.
- musicale 2y agoI think the Z-80 is sadly out of production at this point, but the eZ80 SoC is still available, so hopefully you can still build a hardware CP/M system! Of course there are also synthesizable FPGA implementations, cycle-accurate software implementations, etc.
- einr 2y agoYou can run CP/M on the Agon Light computer, which is indeed based on the eZ80: https://github.com/TheByteAttic/AgonORIGINS https://github.com/TheByteAttic/AgonORIGINS https://github.com/nihirash/Agon-CPM2.2 https://github.com/nihirash/Agon-CPM2.2
- hippospark 2y agoI prefer RISCV as an starting assembly language because: it has good design, it's more intuitive, it has modern language and tool support (GCC, LLVM, Rust, etc.), and it runs on QEMU and real available hardware.
- musicale 2y ago> real available hardware Last I checked the 65C02 was still being manufactured and sold. It can also at a blazing 14 MHz.
- musicale 2y ago*run
- brucehoult 2y agoIt's $8 and can't run without external ROM and RAM and a clock circuit and some glue logic. A RISC-V CH32V003 32 bit processor with 2k RAM and 16k of flash running at 48 MHz costs $0.10 for an 8 pin package (6 available I/O pins) or $0.20 for the 20 pin package. Once programmed, it needs only electricity between 2.8V and 5.5V to be applied to start running. https://www.aliexpress.com/item/1005005036714708.html https://www.aliexpress.com/item/1005005036714708.html You can get it on a ready-made board or kit for as little as $1. https://www.youtube.com/watch?v=dfXWs4CJuY0 https://www.youtube.com/watch?v=dfXWs4CJuY0 https://www.olimex.com/Products/Retro-Computers/RVPC/open-source-hardware https://www.olimex.com/Products/Retro-Computers/RVPC/open-so... The recommended dev board, with a USB programmer/debugger interface for your PC, plus 5 of the 20 pin chips, costs $8.35 about the same as a bare 65C02 chip. https://www.aliexpress.com/item/1005004895791296.html https://www.aliexpress.com/item/1005004895791296.html You can make your own cool shit like this, which uses the $0.10 8 pin chip. https://www.youtube.com/watch?v=1W7Z0BodhWk https://www.youtube.com/watch?v=1W7Z0BodhWk It's as easy to learn the instructions of as a 6502 -- there are fewer of them! -- and far easier to write useful code for. MUCH easier to learn than a 68000, and no more difficult to use. TBH the A and D register split always annoyed the hell out of me in early Mac days.
- 2y ago
- blkhp19 2y agoIt's also a fun one to write an emulator for. There are plenty of example programs out there to test, and they draw graphics by writing bytes to a frame buffer at some offset in memory. You can read from that region in memory, interpret each byte as a color from a preset palette, and use it to display visual output / graphics. I wrote one in Swift a few years back, and then ended up developing it further into an NES emulator capable of playing Donkey Kong. It was a great learning experience.
- stevekemp 2y agoI recently found a 6502 emulator written in Z80 assembly, which runs under CP/M: https://github.com/davidly/a1/ https://github.com/davidly/a1/ The full title is " 6502 and Apple 1 emulator for 8080/Z80 CP/M 2.2 machines " which I guess gives a better idea of the (impressive) scope.
- JKCalhoun 2y agoWas the KIM-1 the first 6502 computer? I'm not sure. In any event, try out the KIM-1 simulator if you want to use your 6502 coding skills: https://maksimkorzh.github.io/KIM-1/ https://maksimkorzh.github.io/KIM-1/
- classichasclass 2y agoIt's down to either the KIM-1 or the JOLT. The JOLT was advertised in December 1975 ( http://retro.hansotten.nl/6502-sbc/jolt-and-super-jolt/jolt/ http://retro.hansotten.nl/6502-sbc/jolt-and-super-jolt/jolt/ ), compared with the 6502 which was being sampled around June or July. The KIM-1 was variously noted as early as winter 1975 but some sources say it wasn't available until 1976, but then the JOLT probably didn't get into people's hands until then either. I think it's logical that MOS would have been the first one to use their own chip but that's not a given. I have a ROR-less KIM-1, though, so there are systems dating from that early.
- chasil 2y agoThe wiki says that the KIM-1 was an internal design, and the Apple 1 was the first customer design. "Another group inside [MOS] designed the KIM-1... One of the first "public" uses for the design was the Apple I microcomputer, introduced in 1976." https://en.m.wikipedia.org/wiki/MOS_Technology_6502 https://en.m.wikipedia.org/wiki/MOS_Technology_6502
- timbit42 2y agoAccording to Wikipedia, the Microcomputer Associates Inc. (MAI) JOLT came out in July 1975, the Apple 1 came out July 1976, and the KIM-1 came out in 1976 but no month is specified. Also, the JOLT was used in the Atari VCS prototype. MAI was later acquired by Synertek and the company was rebranded as Synertek Systems and then created the SYM-1, a 6502-based SBC, in 1976.
- kazinator 2y agoI cannot agree that the simplicity of the 6502 wins over the 68000. The 68000 has more registers and wider data types: but the registers are all uniformly the same. It's really just two registers A and D, copied a bunch of times in to D0 to D7, and A0 to A7. Whatever you can do with D0 can be done with D3 and so on. Some A's are dedicated, like for a stack pointer. Simplicity of structure has to be balanced with simplicity of programming. It's not that easy to program the 6502, because in moderately complex programs, you're constantly running into its limitations. The best way to learn how to hack around the limitations of a tiny machine is to completely ignore them and become a seasoned software engineer. A seasoned engineer will read the instruction set manual in one setting, and other pertinent documents, and the clever hacks will start brewing in their head. You don't have to start with tiny systems to get this skill. When you're new, you don't have the maturity for that; get something that's a bit easier to program with more addressing modes and easier handling of larger arrays, more registers, wider integers.
- musicale 2y ago> The best way to learn how to hack around the limitations of a tiny machine is to completely ignore them and become a seasoned software engineer Learning to hack around the limitations of a tiny machine is a good step toward becoming a seasoned software (and possibly hardware) engineer! The advantage of tiny systems is that you can understand them completely, from silicon to OS to software. The 6809 is simpler than the 68K, and more powerful and orthogonal than the 6502, but there isn't the same software base for it. I think Motorola was onto something with the 6809 and 68K instruction sets and programmer-facing architecture. IIRC PDP-11/VAX and NS32K are similarly orthogonal.
- classichasclass 2y ago6502 was my first assembly, though we didn't have an assembler - we entered raw opcodes into the Epyx FastLoad monitor on the C64. You kids with your symbol tables and your fancy mnemonics. a9 01 8d 20 d0 a9 93 20 d2 ff ... When we got a KIM-1, we were able to write meaningful programs on it in a weekend, since we already had memorized all the hex.
- scarface_74 2y agoEven on the Apple //e you could “call -151” to get into the assembler and then type “!” to use the mini assembler
- djmips 2y agoNot on the Microsoft laden Apple ][+ - they removed that... :`( Only on the OG Integer ROM Apple ][ and then again on the later 1985 enhanced ROM //e
- kstrauser 2y agoI've forgotten so much of that, but I'll go to my grave remembering that LDA #97 JSR $FFD2 writes "A" to the screen.
- scarface_74 2y agoFunny. I still remember it $FDED on the Apple // series. But printing text out like that was really slow. For fast text printing you had to write to memory locations between $400-$7FF and deal with the non continuous memory block -> screen location mapping. It was even more of a pain with 80 columns when half of the text was in the main memory and the other half was the bank switched memory.
- kstrauser 2y agoOuch. That sounds painful. Yeah, I usually ended up writing to screen RAM at $400. It was convenient to let the kernal manage cursor position and all that, though.
- monocasa 2y agoIt really isn't. Biggest issue is that register width is half of pointer width, so for arbitrary pointers you at least need to make a trip through the zero page. That fact alone really obfuscates a lot of what you're trying to teach as a first stab in assembly. I say this as someone who has a whole lesson plan in 6502 asm.
- djmips 2y agoIDK - I guess you are mentally modelling it wrong. Think of the zero page as a bunch of registers - that's kind of how I modelled it and it was also the hump to get over that helped someone building a 6502 compiler backend. See the slide on imaginary registers. https://llvm.org/devmtg/2022-05/slides/2022EuroLLVM-LLVM-MOS-6502Backend.pdf https://llvm.org/devmtg/2022-05/slides/2022EuroLLVM-LLVM-MOS... But all that being said, 68000 or modern ARM or RISCV are also good targets. I am probably just a little nostalgic for the 6502.
- renewedrebecca 2y agoIt's really not a bunch of registers though... If you could so something like LD[$0f] #65 - then yeah, you have registers. But you can't do that sort of thing with zero page. You'd still need to do: LDA #65 STA $0f
- djmips 2y agoYou can do LDA ($0f),y This is using a 16 byte address in zp as a ptr + y offset For LD[$0f] #65 It's more instructions but you LDA #65 STA ($0f),Y (assume Y = 0)
- renewedrebecca 2y agoSure, but the point is that you can't treat a zero page address like a register. There's a LDA, LDX, LDY, but no way to load directly to a zero page address. You have to load a real register, then store it in the ZP address. Zero page isn't a bunch of registers because register operations by and large don't work on them directly.
- kiwih 2y agoAt my institution we teach MIPS, or rather, we teach MIPSY, which is our own version of MIPS which includes a bunch of helper pseudo-instructions. It's taught to all computer science and software engineering students. Most students would take it in their first year, second semester. We cover everything from the basics to hand-compiling code with functions, stacks, arrays, pointers etc. We have our own emulator and even web platform for students to step forward (and backward!) their code: https://cgi.cse.unsw.edu.au/~cs1521/mipsy/ https://cgi.cse.unsw.edu.au/~cs1521/mipsy/
- dtaht 2y agoThe difference between A and D in the 68000 was sometimes bothersome. I think riscv is cleaner to think about. That said, I loved the zero page on the 6502...
- progmetaldev 2y agoCan anyone speak on how it is to move from an older assembly, to a modern CPU? I asked to take an assembly class in local/public college, and was told they wouldn't hold the class because not enough students were interested. This was in 1998, and I truly couldn't believe my ears. I feel like learning modern assembly would be more useful, but maybe 6502 assembly is far easier to pick up? The first language I learned was Atari BASIC around 1991, and it was enough to get me to keep on moving to better languages and more powerful CPUs, but I wonder where I would have ended up if I learned assembly either before or after Atari BASIC. I try to keep up with technology, and have read quite a bit on different assembly dialects. I still haven't learned an assembly that I can program in, and I suppose it's because there are so many other high-level languages now and I feel like I need to keep up to what is used in "industry" rather than what is more obscure (but might help in debugging).
- adiabatichottub 2y agoOne thing to consider is that there's a whole world of 8, 16, and 32-bit microcontrollers out there being used in new products every day. They are all readily programmable in assembly language, and if you have the basics down then the learning curve isn't terribly steep.
- __alexander 2y agoCheck out Assembly Language for x86 Processors by Kip Irvine. It’s probably one of the best books on x86. The older editions are way cheaper.
- professoretc 2y agoDoesn't it still treat 64-bit code as something of an afterthought?
- leptons 2y agoI started with BASIC on a Vic 20 in 1979 in a computer class for kids. Then I got my own Atari 400 at home, so I learned BASIC on that. Then around 1984 I got a Commodore 64 and it was amazing. I quickly got past the BASIC part of the C64 manual and in the back of the manual they had a memory map, all the hardware registers for all the chips, and then all the 6502/6510 opcodes. There was even an entire schematic for the C64 in the back of the book as a fold-out poster. 14 year old me was hooked. I got into assembly when I was about 15 and never looked back to BASIC. I wrote a lot of assembly code for many years, creating "crack intros" for cracking groups and demos on the C64. I then moved on to Amiga and 68000 assembly, and I even got into SNES 65C816 (16 bit version of 6502) assembly coding using a 30th generation photocopy of the pirated SNES developer manual and a floppy disk game copier, which also had a parallel port that I managed to connect to my Amiga and use that as the development system uploading the compiled program to the SNES via parallel port. I would make "crack intros" for SNES games being traded on pirate BBS's. It was a lot of fun. Many years later, I'm still doing some 8-bit assembly code for microcontroller projects where I'm trying to use the smallest possible CPU to do interesting things. Everything I learned about Assembly on the C64 still applies to the modern microcontrollers (PIC/AVR) that I use today. In so many of these years I had not learned C. I went from assembly to scripting languages, and was a very early adopter of Javascript since the same month it first came out. Only in the last 10 years have I learned C, and it was so easy! After learning Assembly and Javascript, C was right in the middle. I've programmed in over a dozen languages through the years, but I'm really happy with Assembly, C, and Javascript as my stack depending on the project.
- dboreham 2y agoNope. Too many quirks. 68k or if you must do 8-bit 6809.
- djmips 2y ago6809 is a good point. It's like let's split the difference between 6502 and 68000! I started with the 6502 and graduated to 68000 on ST and Amiga and Sega Genesis. Definitely two of my all time favourites. Only recently have I started to try my hand at 6809 and I can see how you reccomend it, it's a very nice in-between from the 6502 to 68000. It's hard to fathom the 6502 came out in '75, the 6809 in '78 and the 68000 in '79
- aappleby 2y agoStrong disagree. The RV32E subset of the RISC-V spec is even simpler than 6502 and has good modern support in cheap microcontrollers (CH32V003 etcetera) and widely available simulators.
- musicale 2y agoRISC-V has a simple instruction encoding, but the 6502 has 151 instructions total.
- brucehoult 2y agoCounting instructions is problematic. 6502 has 56 mnemonics, RV32I/RV32E has 37. But mnemonics are arbitrary. Are BCC, BCS, BEQ, BMI, BNE, BPL, BVC, BVS really different instructions, or just one instruction with a field specifying the condition. If you look at 8080 and Z80 assembly languages you see the same binary instructions represented with different mnemonics and some things that have different mnemonics in one are the same mnemonic with different arguments in the other. 6502, original, has 151 of the 256 eight bit opcodes used, but when you add in the immediate data or address it has millions of possible instructions: with ABS ABS,X ABS,Y modes: ADC, AND, CMP, EOR, LDA, ORA, SBC, STA with ABS ABS,X modes: ASL, DEC, INC, LDX (act ABS,Y), LDY, LSR, ROL, ROR with ABS mode: BIT, CPX, CPY, JMP, JSR, STX, STY So that's (38 + 28 + 7) * 65536 = 3,080,192 instructions right there. Immediate and the various Zero Page instructions add another few thousand. Similarly with RISC-V RV32I when you fill in the Rd, Rs1, Rs2 fields and immediates/offsets there are again many millions of possible instructions.
- musicale 2y agoMaybe it's just me, but I consider data "data" and addresses "addresses" rather than instructions. I do understand your point, and I'm fine with saying there are 151 opcodes/instructions.
- brucehoult 2y agoDo you consider binary code patterns that do exactly the same thing except for using different register(s) to be the same or different instructions? For example, on RISC-V `sub Rd,Rs1,Rs2` has no immediate data or addresses but can have 32768 different results on the machine state (less the 1024 with Rd = x0, and I guess the same number with Rs1 = Rs2)
- brucehoult 2y ago> modern RISC architectures such as ARM, MIPS or RISC-V. At some point, a serious assembly programmer should definitely learn some of them. Yes. > However, they are not ideal to start with: the “S” in RISC stands for “simple”, but the simplicity is more about internal implementation of the chips than the instruction set. That is in fact a much better description of the 6502, which is not even a RISC but rather something almost prehistoric, where you figure out how much circuitry you could fit on a chip (or board) and then figured out what instruction set you could fit to that hardware. Note that 6502 was the first machine code I learned as a 17 year old in 1980, after I got bored with BASIC after two days. I learned z80 on a ZX81 the year after and PDP-11 the same year. VAX in 1982, 6809 in 1983, and 68000 in 1984. > Modern microprocessors are almost exclusively programmed with high-level languages and the direct usage of assembly instruction is not high on the list of priorities for CPU designers nowadays. That's just absolutely not true. They might be in some way "harder" than a CISC instruction set such as VAX but any of the above are far simpler to program than 6502, especially the base RISC-V RV32I instruction set. > To illustrate this point, loading a 64-bit constant to a register on ARM64 can take 4 instructions with bit shifting. Whereas you can't do it at all on a 6502! Loading a 64 bit constant into 8 zero page locations takes 16 instructions and 32 bytes of code on a 6502. Let's not even talk about adding or comparing or multiplying two such values. The GNU assembler for ARM64 doesn't help you out, but on RISC-V you can just type ... li x10,0xfedcba9876543210 ... and the assembler will generate the multiple instructions for you.
- deleted 2y ago[deleted]
- KingOfCoders 2y ago68000 is much more pleasent from my experience (~40 years ago, so might be wrong). Personally I also like the Z80 better than the 6502, but that is just taste. The biggest benefit of the 6502 was a zero page, I loved the idea. My favorite computer book of all time is "Z80 Assembly Language Subroutines".
- Findecanor 2y ago6502 is a bit limited, so you'd have to resort to self-modifying code to get things done — and self-modifying code is a big no-no on any processor with cache, and therefore not a good habit to acquire. For teaching, I would instead go with RISC-V. In particular RISC-V with the bitmanip extensions, which make some things much easier and gives it feature-parity with the base set on x86 and ARM. The Raspberry Pico 2 has two RISC-V CPUs with those. The board is easy to use, widely available and has a lot of support. There are also alternative boards with the same MCU but other form factors and features.
- larusso 2y agoI have mixed feelings here. On the one hand yes. It’s a good introduction because the simple patterns and instructions mean you can only do X a specific way. But when you start to write real programs, especially from a mindset of a programmer from the post 2010 times its starts to feel weird because the patterns become harder to grasp. So I‘m not 100% sure myself here. I love the 6502 and the instruction set. But on the other hand I feel that basic c and unoptimized assembly give you a more real live introduction to assembly? The issue is that it’s hard to judge for someone who already got introduced and grasps the concepts.
- acjohnson55 2y agoI first went deep on programming learning Z80 assembly for my TI-83. It has a lot of idiosyncracies, such as 8-bit registers that can be combined for 16-bit operations. But it was a lot of fun learning from tutorials and from reading other people's code. It put me way ahead when I got to college, as I had already learned a lot about computer architecture.
- pjmlp 2y agoNah, Z80 is sooo much better, lets discuss on the playground. :)
- js8 2y agoMy take is that any instruction set that has "centralized" instruction flags is an obsolete design, as it creates dependencies between instructions that could be otherwise executed out of order. So neither 6502 or 68000 is ideal.
- pwdisswordfishz 2y ago> the “S” in RISC stands for “simple” TIL
- herczegzsolt 2y agoWhen I learned assembly at university, we were required to learn Intel 8086. I remember hating every second of it, because it was so useless. Around the same timey I had to learn AVR8 family assembly (for ATMega328P) which was a joy in comparison. I don't think AVR assembly is any better or easier then 16bit Intel, but just the fact that it's a usable and actually triable thing makes a world of difference. I guess what i'm trying to say is that you shouldn't underestimate the importance of learning something useful instead of something antiquated, even when it is not the simplest thing to do.
- Onavo 2y agoThese days just learn RISC V. Plenty of chips and MCUs.
- germandiago 2y agoNES emulator. Super nice exercise for the brave.
- fjfaase 2y agoI agree with the article. The 6502 was the first CPU I wrote a lot of machine code for both on the Acorn Atom, where the Basic had a buildin assembler, and the Atari XL-800, for which some roommates and I programmed a compiler in Basic and next made it self hosted.
- Dwedit 2y agoThe hairy part the 6502 instruction set is Subtract With Carry, and the confusion about how the carry flag works as a result of subtracting or comparing. SBC is implemented by adding the ones-complement (XOR FF) of the number or register. And the carry flag is backwards compared to other architectures, such as the Z80. On input, Carry Set means that you don't want an additional one subtracted, and Carry Clear means you do want an additional one subtracted. Then on output, Carry Set means that no borrow took place, and Carry Clear means that borrow took place. When borrow takes place, you get an additional one subtracted, and that lets you chain the low bytes up to the high bytes and subtract bigger numbers. CMP is like SBC, except it always adds the extra one whether your input carry is set or not, making it act like you'd expect comparison to act.
- masswerk 2y agoAnother way to put it is that in SBC context the carry provides for the bit required to turn ones' complement into two's complement (all bits flipped + 1). If it's clear, we fall short by one (so we remain in ones' complement, missing the "+1" part), which makes for a perfect implementation of a borrow. Since SBC is essentially ADC with the invers of the operand (ones' complement) this applies in general (not just for negative values). (So, technically, the carry is like a ones' complement / two's complement switch. And this is also all we need to implement a borrow in two's complement math.)
- dmitrygr 2y agoCarry flag meaning "not borrow" is the same as ARM, is it not that "backwards compared to other architectures"
- c64cryptoboy 2y agoThe carry is certainly the most complicated flag on the 6502: https://archive.org/details/carryFlagCheatSheetV1.0 https://archive.org/details/carryFlagCheatSheetV1.0
- PeterStuer 2y agoUnlike the author, I always found the Z80 to be far more simple and sane than the 6502. Also, for me the excellent 68000 instruction set was design wise far more a continuation of the clean Z80 style than the messy 6502.
- eleitl 2y agoI would like to mention stack machines, particularly of Chuck's MISC type. I still have my Novix board somewhere.
- relistan 2y ago6502 is a good start. But IMO, ARM assembly is where it’s at as a starting point. Much more useful and it spans so many vendors and classes of devices. It’s not harder than 6502 IMO.
- andyjohnson0 2y agoThe 6502 was the first cpu that I programmed in machine code - on my Vic-20 and BBC Micros at school in the 80s. Later I wrote some code for the 6809. And later still I used 68000 dev boards as an undergraduate. Its been a while now, but I remember feeling that the 68k was clearly powerful and elegant and a proper cpu, but also that I had little hope of understanding all the details. The 6502 was my first, and with hindsight was far less elegant with plenty of warts, but I felt at the time that I understood it pretty well. The 6802 was somewhere inbetween, I guess, and a very nice cpu to work with I've never thought about it before, but I suppose I benefited from that progression 6502->6809->68k. Whether or not it makes sense now, I couldn't say. (Never got on with the Z80. That brash upstart /s)
- julian55 2y agoI'm slightly surprised that no one has suggested PDP-11 assembler as a good starting point if you're not going to learn a current instruction set. Perhaps it's because it was the first one I learnt properly but all the early miccroprocessors felt like a step backwards. I did spend a few years writing Z80 assembler but I wouldn't recommend it nowadays as it's not a very orthogonal instruction set and 6502 doesn't have enough registers to give you a proper feel for writing assembler.
- brucehoult 2y agoIt's kind of hard to get hold of a PDP-11 these days. Even getting an OS, compiler etc is not that easy. If you like the PDP-11 then you get the same qualities slightly restricted in the MSP430 and slightly enhanced in the 68000. But, really, just forget all those relics and learn either RISC-V (the best answer) or else one of the half-dozen Arm variations. I'm partial to ARM7TDMI myself for sentimental reasons doing a lot with it in the mid 2000s. The Thumb mode is probably slightly easier to learn than the original Arm mode, but neither is as satisfactory as RISC-V.
- shakna 2y ago> Even getting an OS, compiler etc is not that easy. There's a GCC fork [0], macro11 [1] (GCC and clang also both have macro11 backends), ack [2] and more. Getting hold of a modern compiler is trivial. > It's kind of hard to get hold of a PDP-11 these days. The PiDP-11 [3] emulator that runs on a Pi, is fairly popular among the retro crowd. So sourcing something hardware wise that behaves that way is easily possible. The Computer History Simulation Project [4] will give you easy access to simulating a PDP-11 on just about anything that you own. But if you want the original hardware, then they're in the $400-500 range, in my area. Easy to source. [0] https://github.com/JamesHagerman/gcc-pdp11-aout https://github.com/JamesHagerman/gcc-pdp11-aout [1] https://gitlab.com/Rhialto/macro11 https://gitlab.com/Rhialto/macro11 [2] https://github.com/davidgiven/ack https://github.com/davidgiven/ack [3] https://obsolescence.wixsite.com/obsolescence/pidp-11 https://obsolescence.wixsite.com/obsolescence/pidp-11 [4] https://github.com/simh/simh https://github.com/simh/simh
- pizza234 2y agoThe topic of the 6502 ISA simplicity is a pet peeve of mine, because to me it's clear that anybody thinking that such simplicity is a good thing, never progressed past a hello world. Programming anything of moderate complexity on the 6502 is hard. 8 bits are way too restrictive (e.g. screen addressing on the Commodore 64). Multiplications/divisions need to be hand-rolled. And even 16 bit sums/subtractions are simple but still not trivial to perform efficiently. The 8086+DOS platform is way easier to work on, in comparison (if one wants to learn basic assembly).
- apricot 2y ago> Multiplications/divisions need to be hand-rolled. In the context of someone's first contact with assembly language, that's a good thing! Translating various multiplication and division algorithms to assembly is a great way to learn it.
- kccqzy 2y agoI learned to implement my own multiplication and division as part of learning bignum with a high level language (in my case Pascal). By the time I learned assembly language I simply focused on how to translate high level language to assembler; basically be a manual compiler and compare my output against a real compiler. It seems unnecessary to learn any algorithm including the multiplication algorithm in assembly language.
- apricot 2y agoImplementing shift-and-add multiplication and division algorithms in assembly, and analyzing them, is a very formative exercise in my experience. Besides, if assembly language is good enough for Knuth to express all the algorithms in TAOCP, it's good enough for me...
- PaulHoule 2y agoI probably wrote more 8086 (really 80286 in real mode) assembly than any other assembly. I loved every minute of it, I didn't even mind the segment registers.
- hcfman 2y agoWhat about the 6809 processor? I believe this was even simpler, it was very consistent.
- DonHopkins 2y agoNo, it was more complex and luxurious, with a MUL instruction.
- DonHopkins 2y agoThe accumulator A is your mouth with 8 teeth, that can bite and chew and taste, the status register is your tongue, and the X and Y registers are your hands, that can help you shove stuff into your mouth and spit it out.
- toolslive 2y ago6502 was my first assembly language (back in the 80s). It was fine. However, when I later had to do some Z80 assembly programming I considered that instruction set a lot nicer. It had more registers. It had a swappable register set. It even had a few 16 bit instructions. Really nice. I guess most people just give up once they see the ugliness of what they got from Intel.
- masswerk 2y agoI guess, it's a matter of perspective. The Z80 is derived from the 8008 (actually the 8080), which was an on-a-chip implementation of the processor of the Datapoint 2200. Notably, the DP2200 was designed around an early Intel shift-register for memory (meaning, sequential memory), hence the multitude of internal registers in order to minimize memory access. (It's probably only for the 8080, which provided better support for direct memory access, that there's this notion of luxury about these internal registers. Before this, it had been a necessity.) The 6502, on the other hand, is a derivate of the 6800, a genuine microprocessor design that takes fast random access into account. And thus, taking fast memory for granted, it became viable to outsource some of the internals. From this perspective, the 6502 provides a plenitude of 256 slightly slower registers in the zeropage. – However, if you're using the 6502 like this, you may discover that you lose some of the much acclaimed advantage in cycle count per instruction.
- adrian_b 2y agoZilog Z80 had very significant improvements over Intel 8080. From many points of view it can be considered midway between Intel 8080/8085 and Intel 8086/8088. Besides increasing the number of registers, Z80 has added many features that were standard in any general-purpose computer (e.g. signed integer support and indexed addressing), but which were missing in Datapoint 2200/Intel 8008/Intel 8080, simply because Datapoint 2200 had not been designed to be used in general-purpose computers but only for implementing the logic required inside a serial terminal. However many programs for Z80 did not make good use of its additional functions, because they were intended to remain compatible with the legacy Intel 8080 systems. Intel 8086 did not have this problem, because it was only source-code compatible with 8080, not binary compatible, so any application had to be recompiled for it, and fully using the new ISA did not have any additional disadvantage. Unlike 6502, Intel 8080 and Z80 had a few 16-bit operations, which were intended for address computations, while data operations were expected to be handled using the 8-bit accumulator. Despite the intended use and the limited set of 16-bit operations, implementing complicated arithmetic operations, e.g. floating-point arithmetic, was still faster using the 16-bit address registers and operations for handling data. With properly optimized programs, Z80 and even 8080 could be much faster than 6502 for number crunching. (Though faster is only relative, because FP64 floating-point operations took many milliseconds per operation on any 8-bit microprocessor, many billions of times slower than on a modern laptop or desktop CPU.)
- amelius 2y agoMakes more sense to learn an IR nowadays. Or WASM.
- bArray 2y agoPersonally I learned with 8086/8088 via MikeOS [1] (written in NASM). Highly recommended. [1] https://mikeos.sourceforge.net/ https://mikeos.sourceforge.net/
- ChrisMarshallNY 2y agoMy first program was 6800 Machine Language. My second, was 6502 (VIC-20), my first ASM was 8085. With that, I actually wrote an embedded OS. The byte order seemed strange to me, after the Motorola chips. Also, the two-part memory addressing. Eventually, I ended up doing ASM with 68000 (Mac Plus), but by then, I was well on my way with higher-level languages. Starting from Machine Language helped me a lot in understanding some of the more fundamental concepts of software. It was also an excellent troubleshooting teacher, which has probably been the most valuable software development skill I have. These days, though, with the current complexity of CPUs, I don’t think it would be reasonable to start folks off with assembly/machine languages, anymore. I’m not sure that “retro” CPUs would really represent some of the difficulties experienced with highly parallel processors. I would worry that it might encourage an “idealized” view of the underlying architecture.
- msla 2y ago[flagged]
- crest 2y agoI would argue that 6502 is a bad first ISA to learn if you want learn assembly. You‘ll spend most of your time fighting the quirks of this clever, but deeply flawed architecture. The idioms you learn to work around them don‘t translate to any better designed architecture that wasn‘t constrained by the tools and budget available to MOS at the time. If you want to learn a small, yet powerful instruction set with a few quirks go for ARM v6M. It‘s still in meaningful production (no the Monster 6502 doesn‘t count), has good platform support in the latest open source toolchains (debuggers, compilers, assemblers, linkers, etc.). If you value openness of the architecture enough to deal with a less mature platform (as of early 2025) then pick a RISC-V MCU instead. If you can‘t decide pick a RP2350 :-). The ARMv6M instruction set is small and no loading constants doesn‘t require long winded instruction sequences if you do it as documented (PC-relative load instead of shifting in immediate data). You don‘t have to deal with self modifying code and/or the zero page to index memory. Your registers are the same width as the address space. Yes it‘s 32 bits, but that makes it simpler to learn, use and teach than all 8/16 bit and most 16 bit instruction sets I’ve seen because you don‘t have to work around to narrow registers for common operations. To anyone who thinks this sounds boring: don‘t worry ARMv6 still has enough quirks you can use for code golfing.
- systems_glitch 2y agoAgree, I like the 6502 architecture but tend to steer newcomers in vintage computers away from it if they have no previous ASM experience. I started on PIC16 assembly, and dabbled in a bunch of other architectures, but my favorite in terms of cleanness has been MIPS32. Nitpick: you can still buy new made 6502s, MCUs with 6502 cores, and peripheral chips from Western Design Center. They sell through e.g. Mouser: https://www.mouser.com/c/?m=Western%20Design%20Center%20%28WDC%29 https://www.mouser.com/c/?m=Western%20Design%20Center%20%28W...
- jmull 2y ago> deeply flawed I can't even guess what you might be referring to.
- leptons 2y ago
- nickyisonline 2y agoI go to an compsci-centered technical institute and my informatics professor (a retro nerd that loves to show us his arcade machines) went against the set program for our class, which is learning the 8808 assembly language, and instead focused on the 6502. It was honestly one of the best learning experiences of my life and i woudln't have it any other way. He even got us to build the ben eater breadboard computer so it was particularly hands on and really interesting!)
- lutusp 2y ago> I believe 6502 instruction set is a good first assembly language It was for me. In 1977 I lived in a little cabin in Oregon. I bought an Apple II as a diversion. Within a year I was working on a program that later became "Apple Writer" (https://en.wikipedia.org/wiki/Apple_Writer https://en.wikipedia.org/wiki/Apple_Writer), written entirely in assembly. Some in this conversation identify 6502 assembly as rather clunky and difficult to use. In retrospect I have to agree, but in 1977 I didn't have a basis for comparison. There were no fast, high-level languages available for the Apple II, so my little program became an Apple product, primarily from the lack of alternatives. Consider this -- Apple Writer lived in 8 kilobytes of RAM, but actually did things. It even had a macro language people used to process address lists. I just boosted my main system to 96 gigabytes of RAM to be able to more easily host DeepSeek locally (I have an RTX 4090). I just realized that's enough RAM to hold almost 12 million copies of Apple Writer. This is all pretty surreal ... but I've had occasion to say that a number of times since 1977.
- thoughboxy 2y agoHaving programmed the 6502 and struggled with 8-bit arithmetic, I can only say that I don't believe it is a good first language at all. 32-bit ARM2 was so much more intuitive, where each and every instruction could be conditionally executed and there were 12? general purpose 32 bit registers in user mode.
- vertnerd 2y agoI learned 6502 as a teenager in the 70s (after learning 6800 first). When 68k came along, I immediately recognized it was a superior architecture. Nevertheless, when I went to teach a short intro to CPU class to high school students recently, I chose the venerable 6502 for programming. Why? Because performing the 8-bit arithmetic and performing hand assembly are all very manageable on the 6502. Any 8-bit CPU would do, frankly, but the connection between 6502 and early microcomputer history is intriguing (and I was familiar with it). Everyone here is talking about how there are better assembly languages to learn first, but I wonder how many of them are practical for hand assembly. I still maintain that learning (and debugging software for) any CPU architecture beyond the 6502 was easy because of the skills I learned as a teenager, hand assembling 6502 code. That experience put me miles ahead of my colleagues who didn't have that experience when it came to working with low-level coding in the decades to follow.
- a1o 2y agoI liked the 8051 :)
- daitangio 2y agoI do not know. I learned it when I was 12, but it was quite challenging for me. Pros: It is very ortagonal, has no memory-to-memory instructions Zero page is like a having 256 generic RISC registers (a bit faster than accessing to other memory areas). Very easy to understand how the assembly is micro-coded Cons: It is impossible to create a "generic" memory pointer with an index >255 without auto-modifying code. It is a true 8bit only system and cannot manipulate 16bit word easily Steve Wozniac created a small VM just to manage 16 bit Integers (see the his Byte magazine articles). Too much addressing mode. So I like 6502, but I disagree a bit.
- apricot 2y ago> It is impossible to create a "generic" memory pointer with an index >255 without auto-modifying code. Sure it is. Just store your pointer in zero page, set Y to 0 and use the (ZP),Y addressing mode.
- masswerk 2y agoAlso, compare the "zeropage indirect" address mode of the WDC 65C02, which does exactly this w/o involving any of the index registers.
- apricot 2y agoOh, nice. I wished for a similar addressing mode in the 1980s. I see they also added instructions to increment and decrement the accumulator as well. (Actually, what I wished for was slightly different: only the high byte of the effective address would be fetched from zero page, the low byte being the Y register. In this way, one could keep both bytes of the pointer in zero page, LDY the low byte and use my zp indirect mode. The first use of a pointer would cost an extra instruction / 2 cycles, but further uses of the same pointer would be cheaper.)
- masswerk 2y agoNotably, the Motorola 6800 has decrement and increment for the accumulator, both of them. It also features an indexed address mode that is somewhat reverse to how the 6502 does it: there's only one index register (X), but this is of 16-bit length and a single-byte operand is added to this. So, while not exactly a zeropage address, with a bit of courage for self-modification we get there… The 6502 did intentionally away with quite a number of features, but, as it had since become evident that it was a computer CPU, WDC added (back) for the CMOS version some of what was kind of missing for this application. (The thing I'm probably missing most on the 6502 is a sequential-shift or barrel-shifter, shifting/rotating by multiple bit positions at once. This would be so great for games, graphics, encoding and decoding… Sophie Wilson had the wisdom to opt this into the ARM architecture.)
- PaulHoule 2y agoAVR-8 for the win. AVR-8 is highly orthogonal and has a whopping huge 32 register file. Devices like https://store.arduino.cc/products/arduino-uno-rev3 https://store.arduino.cc/products/arduino-uno-rev3 are affordable and have good tooling. Memory capacity is tiny but it is fast, andthere is a lot of I/O, you can even write console programs that use the serial ports or better, programs that do physical things and also communicate over the serial ports -- in some ways AVR-8 boards are more capable than conventional computers, phones, etc. So far as I can tell, AVR-8 was the last 8-bit architecture, if it has a real weakness it is that, compared to other microcontrollers, it's a dead end because you're going to upgrade to ESP-32 or ARM if you need more. The 6052 has more registers than the PDP-8 but just barely. Writing compilers for the 6052 is difficult because there just aren't enough registers not to mind a limited set of addressing modes. If you want to do anything interesting with the 6502 you are likely to use virtual machine [1] techniques such as Wozniak's SWEET16 or the atrocious UCSD p-System [3] or Infocom's Z Machine [4]. That kind of stuff is really fun, but so is writing straightforward AVR-8 code. I have fond memories of the 6809 which supported really advanced software engineering techniques at the time [5] but if I had to pick a classic 8-bit architecture that is easy to find hardware for today it would have to be the Z-80, or the successor eZ80, which I think the only 24 bit micro that didn't suck (had real 24 bit index registers!) Boards are available [6] [1] as in 'Java Virtual Machine', not 'VM/CMS' [2] https://en.wikipedia.org/wiki/SWEET16 https://en.wikipedia.org/wiki/SWEET16 [3] http://pascal.hansotten.com/ucsd-p-system/ http://pascal.hansotten.com/ucsd-p-system/ [4] https://en.wikipedia.org/wiki/Z-machine https://en.wikipedia.org/wiki/Z-machine [5] https://en.wikipedia.org/wiki/OS-9 https://en.wikipedia.org/wiki/OS-9 [6] https://www.olimex.com/Products/Retro-Computers/AgonLight2/open-source-hardware https://www.olimex.com/Products/Retro-Computers/AgonLight2/o...
- donatj 2y agoEvery time I have tried to learn assembly, I've gotten frustrated with an overwhelming urge to try and automate it. I end up having to talk myself down like "no, we're here to learn, not to create another language"
- Gracana 2y agoMaybe you can meet yourself halfway and write assembly macros to make your life easier.
- gxd 2y agoThis discussion contains well argued points about the 6502 vs other instruction sets. Does anyone know of resources/books that I could read that would help me have a more informed opinion on the pros/cons of each instruction set?
- Sardtok 2y agoThe S in RISC does not stand for simple. What the? If someone's going to write about assembly programming, they should at least know what CISC and RISK are. I'm not saying 6502 assembly can't be an interesting endeavor, but it's a bit restrictive for a first language. Maybe if you already know some low-level programming like C. But it's still easier to do things with a few more registers. And it's not like you have to use every register and instruction available on the CPU to write some assembly.
- louthy 2y ago6502 was my fist assembly language, it’s good from the point of view of learning basics like carry flags and how to do multi byte maths, that’s about all. If I was to think of the most approachable assembler it would be the ARM assembler for the original ARM2. A real thing of beauty. Which is not what anyone would normally say about any assembly language! I remember going from ARM to MIPS and being utterly horrified by its ugliness compared to ARM!
- acc_297 2y agoIn university we we're taught a version of MIPS that was implemented into a decent simulator with an IDE showing the state of memory and registers with fine grained debug stepping. Some quirks of processor pipelines (i.e. nops after branch) could be enabled for realism or turned off to make things easier for new students. That was pretty great for learning assembly, I can't comment on any other approach - no doubt there are other good options.
- Sponge5 2y agoSounds like CTU FEE in Prague. I learned a bunch about registers, branch prediction and cache, but most of the assembly went out of my head once the class was over.
- yoyohello13 2y agoIf you want a really accessible intro to assembly. Try playing TIS-100 or ShemzenIO. Those games give you a really good taste of the concepts.
- pcthrowaway 2y agoI'm curious what people's thoughts are on the 65816 (used by the SNES) instead of the 6502 (the NES instruction set). Is this author arguing the 6502 is preferable because it's simpler? Or because there are more/better resources for learning?
- tomku 2y agoBoth reasons apply. There's probably orders of magnitude more learning material for the 6502, and the 65816 is strictly more complicated than the 6502 because it has the entire feature set of a 6502 plus modifications like register size flags and new addressing modes.
- renewedrebecca 2y agoThe 65816 is a pain to code for. It has what's basically a segmented memory architecture with only two segment registers: D (data bank) and P (program bank). You can't just make a 24-bit pointer w/o doing things using the direct page, which is admittedly a bigger problem for a C compiler than an assembler. You always have to be able to know what mode the 'A' register is in (8/16) as well as the index registers. These are separate switches. Even disassembling code on the '816 is tainted by this, because for any section of code you look at, you have to know what mode the thing is in to accurately disassemble the code. So basically, it's a 16-bit processor, sometimes which is a bit maddening.
- WillAdams 2y agoWhy not learn a language intended for didactic use? https://en.wikipedia.org/wiki/MMIX https://en.wikipedia.org/wiki/MMIX has a quite deep corpus and what looks to be a good introduction: https://www.mmix.cs.hm.edu/getstarted.html https://www.mmix.cs.hm.edu/getstarted.html (and I say that as a person who owns a much battered copy of Inman & Inman's _Apple Machine Language_)
- crote 2y agoBecause there aren't any real-world implementations. Why bother with MMIX when you already know it'll never go beyond a toy "hello world" equivalent in an emulator? MMIX might be good for educational use in an academic setting, but literally anything else would be better if you want to have fun working with it. Nothing beats the magic of seeing your first program run on a real computer.
- WillAdams 2y agoUnless your toggling switches at the front panel, I don't see this as a meaningful difference.
- zeta0134 2y agoI program in 6502 assembly all day. It's certainly lovely as beginning assembly languages go, though it can also be limiting. The addressing modes encourage using the "Zero Page" (the memory from $0000 - $00FF) as something of an extended register set, which basically means you can have up to 128 pointers if you really want them, and lots of quick-access scratch space. If you're used to other ISAs with lots of in-CPU registers, the first thing to do is allocate about 16 bytes of "scratch" space on zeropage and use those instead. I call mine R0 - R15. Once that clicks, the rest falls into place. Problems with the ISA become obvious the moment you want to scale your program beyond toy complexity. The stack is absurdly tiny, and trying to use it as a calling convention quickly becomes both a performance and a nesting depth bottleneck. I work around this for my larger projects by using zeropage scratch as a sortof manually-managed local scope for routines, but it requires carefully tracking which otherwise global bytes my programs are using at various nesting levels. Recursion is off the table both with this technique (difficult to manage) and with the stack (256 bytes will be exhausted very quickly). The C compilers I'm aware of work around this (slowly!) by using a separate software stack for arguments to functions. It's pretty fun though! I'm working on a full modern indie game for the NES, which is 100% programmed in 6502 assembly for performance reasons. The existing C toolchains for the NES are either very slow (cc65) or not yet mature (llvm-mos). Most of the true complexity in the project is algorithmic stuff, like resource allocation and deciding how much work to do on a given frame. The 6502 ISA is a bit slower to write than higher level code, but it's not really a major limiter now that I've got my process down. Here's that game if you're interested: https://zeta0134.itch.io/tactus https://zeta0134.itch.io/tactus
- lizknope 2y agoThe important thing to consider is WHY you want to learn assembly language. I learned M68K in a college class in 1995. When I saw x86 asm 2 years later it looked like a mess. But I've never needed to write asm for a job. I'm thinking about learning 6502 because my first computer (Atari 800) and first dedicated game console (original Nintendo NES) both used the 6502 and it would be fun to write games for them when I retire.
- sircastor 2y agoI wrote some 6502 as my final project for school (An NES game, so a specific environment) and I found it fun and extremely challenging. I'm sure there is a lot to be said for writing ASM in a modern context, but I think it's a good exercise in learning. One of the benefits you get out of working with an 8-bit processor is dealing with data bigger than 8-bits.
- fargle 2y agoi have to agree with a lot of sibling comments: i don't think 6502 is a good pick. first, it's highly atypical and limited. second, it's borderline RISC and i'd start with a simpler to use CISC ISA. CISC makes sense and was designed exactly for hand-written assembler. VAX or 68K would be cleaner CISC ISA to learn first. 8086 (16 bit) x86 has the advantage of being ubiquitous and you can run on "hardware" everywhere. but the disadvantage of being a little weird wrt. segment registers. x86 32-bit is complicated, but at least flat memory space and you can mostly ignore the segments. MIPS or one of the RISC-V variants is a second one to learn to contrast RISC load/store with CSIC.
- rayholt 2y agoThis is like making a big deal of the flaws of the first automobile. OF COURSE, there are more appropriate ways to teach ASM today .... its been 50 years. As designer of the first sets of computer cards (yes, way before Apple) ... the Jolt, Super Jolt, SYM-1 we sold over 75K units mostly used to teach early college students to program. Ray Holt FirstMicroprocessor. com
- MarkusWandel 2y agoWhat about the modern 68K subset still manufactured as Coldfire? Much more orthogonal, modern (as of the 1980s) architecture. On the other hand, the cleaner, more modern architectures are easily targeted by compilers. If you really want to live the "assembly language required for performance" era, the 6502 is fine. Equally quirky is MCS-51. I've written nontrivial assembly language projects for both "back in the day".
- firesteelrain 2y agoSerious question: What is the best platform to learn assembly on and where do I start? Books, videos, building my own computer, etc?
- MarkusWandel 2y agoWhat is a "good" assembly language? The best I've ever seen was the VAX instruction set. The second best, probably m68k. These were big, CISC CPUs that were as nice as possible to program in assembly language. The 6502 wasn't. Everything about the 6502 was "do more with less" and you had to be really clever to eke out performance on it. But that's a good thing! A clean, big CISC architecture like the former ones is also a good compiler target. The 6502 was deeply weird, but programming it in assembly was necessary to get it to fly. That's an era. If you want to relive that era, then go for it. It's much more quirkily fun that, say, the 8080 (the Z80 is another beast, though backwards compatible) and much more mainstream than the otherwise better 6809, all of which are also from the "assembly language required for performance" era.
- MarkusWandel 2y agoArguably PDP11 is probably the best. Dates back to the assembly language programming era, but nice clean instruction set. But what are you going to run your PDP11 code on? A simulator? Sure. But no real, consumer facing machines with graphics chips.
- badc0ffee 2y agoThis is what I learned in university in the late 90s. (It was already totally no longer relevant by then, and we did run it on a simulator.)
- mikepavone 2y agoIf you like the PDP11 instruction set, then you'll probably enjoy 68000 as well. It drew a lot of inspiration from the former. You lose the "deferred" addressing modes (though the 68020 adds something similar), but gain access to a few other useful ones. Conveniently it was used in a lot of consumer devices (Mac, Amiga, Sega Genesis, etc.)
- WhyOhWhyQ 2y ago+1 for https://skilldrick.github.io/easy6502/ https://skilldrick.github.io/easy6502/ You can go through that in one pleasant sitting.
- dekhn 2y ago6502 assembly was fairly easy to learn, but it didn't translate to being a productive assembly programmer on the Apple //e I had. In particular, I wanted to do fast 2D and 3D graphics (basically what Ultima III did) to write my own games. My goal was simply to implement SetPixel(x, y, c) which turns out to be tricky because the Apple screen was 280 x 192 so you had to deal with 16-bit math. See https://nicole.express/2024/phasing-in-and-out-of-existence.html https://nicole.express/2024/phasing-in-and-out-of-existence.... for the weird nature of the Apple HIRES graphics mode, and https://github.com/fadden/fdraw/blob/master/docs/manual.md#nutshell https://github.com/fadden/fdraw/blob/master/docs/manual.md#n... for a project that implements fast drawing on the Apple today.
- efitz 2y agoI think that the first question to ask oneself is "why do you want to learn assembly language?" If you want to learn to write programs in assembly language or to debug disassembly of programs written in higher languages, then learn the language for the platform that you want to target. This also covers the "I want to write/understand retro stuff" case. If you want to understand how high-level programs are compiled into assembly language, then read Aho[1]. If you want to understand how algorithms are implemented in assembly, read Knuth[2]. Knuth invented a hypothetical computer "MIX" with its own assembly level instruction set and I believe that MIX has actually been implemented in software several times. If you just want to play a little bit with assembly, "dipping your toes in the water", then I agree with the OP that 6502 is simple and easy to learn, but it is not practical for many modern use cases and has sharp edges. [1] "Compilers - Principles, Techniques and Tools", by Alfred V. Aho et al. https://en.wikipedia.org/wiki/Compilers:_Principles,_Techniques,_and_Tools https://en.wikipedia.org/wiki/Compilers:_Principles,_Techniq... [2] "The Art of Computer Programming", Volume 1, by Donald Knuth, Section 1.3 "MIX" (p. 124 in the 3rd edition) https://en.wikipedia.org/wiki/The_Art_of_Computer_Programming https://en.wikipedia.org/wiki/The_Art_of_Computer_Programmin...
- WalterBright 2y ago> why do you want to learn assembly language? Back in the 70s I was fully aware that learning computers was the key to the universe. And if you wanted to learn how computers worked, you have to learn assembler. And if you want to be more than a beta programmer, you had to learn assembler. > Knuth invented a hypothetical computer "MIX" with its own assembly level instruction set I never bothered with that. Why, when real computers are available? MIX is a waste of time. > it is not practical for many modern use cases and has sharp edges All CPUs have their sharp edges. Like learning to use a milling machine, you don't want to drive the cutter into the vise. Sure, the 6502 doesn't have a divide instruction, but writing a divide routine is a good start to learning how to make the 6502 dance.
- openasocket 2y agoI would recommend against learning MIX, and instead learn the successor, MMIX. MIX was designed in the 1960s, and as a result includes things that simply don't make sense today. For example, the number of bits in a byte is not specified. In fact, MIX is agnostic to whether or not it is a binary computer or a decimal computer! I believe for binary machines MIX says there are 6 bits in a byte, and for decimal machines there are two digits in a byte. Words are not uniform: a word consists of 5 "bytes" and a single bit, used to indicate the sign of the number. MIX has no stack manipulation instructions, and subroutines are implemented using self-modifying code. As in, in order to call a sub-routine you take your return instruction point and write it to a jump instruction in the sub-routine so it will jump back to where you want.
- nyrikki 2y agoThis may be an unpopular opinion but I think Knuth's MMIX is ideal as an initial introduction to ASM these days. It is Purpose built, load-store etc... https://mmix.cs.hm.edu/ https://mmix.cs.hm.edu/ You can use the simplified MMIX-SIM Then you can move to typical RISC features like full pipeline, cache, etc... Then you can move to actual hardware etc.. But I am probably bitter, I learned on a Heathkit ET 3400, and I find that a lot of the quirks of the 6800 are something I had to get around to understand modern processors. MMIX may not be 'useful' for real applications, but being intentionally free of those quirks is very useful for understanding the core concepts, at least for the few people I have had try it.
- WalterBright 2y agoMy first exposure assembly language was the PDP-10. All I had was the DEC-10 processor manual. I was completely baffled by it. It had hundreds of instructions, with completely opaque descriptions. What was a register? What was an accumulator? What was an address? What was a stack? I had no idea. David Rolfe wrote some subroutines I needed for my Fortran version of Empire, and that helped a little, but I was lost. One day, I asked my friend Shal Farley, what was a stack? He said "Imagine a stack of plates. You added a plate (pushed it on the stack), and took off a plate (popped it off the stack). Suddenly, Shal had turned the lights on! I instantly understood it. Then, I began working with a 6800 microprocessor on a little board. It had something like 40 instructions, that all fit on a card. 40 instructions were simple to learn, and suddenly, I got it. I want back to the -10 manual, and it all made sense.
- smitelli 2y agoI started by reading disassembled real-mode x86 code. Not bad, not great. The thing that took me the longest to “get” was how much was implicitly coded into each instruction. Once I figured out how the accumulator worked, plus the way the flags influenced jump instructions, I found over time that most other architectures are more similar than they are different.
- samspot 2y agoI learned some 6502 last year in service of NES ROM Hacking. If you're interested in doing the same, NesHacker's Final Fantasy guide was instrumental in getting me started: https://www.youtube.com/watch?v=HLzEhyvHBos https://www.youtube.com/watch?v=HLzEhyvHBos
- mud_dauber 2y agoIt certainly was for me. I learned how to build Forth on my Commodore.
- mr_coleman 2y agoI always advocate for people to learn 6502 because it's easy and small. Not because they are going to write assembly but because they should have a basic idea of what their code is going to turn into. It doesn't matter if someone writes in Rust, Java, .Net, Python, Lua or C, it's all mov and cmp at the end of the day.
- glouwbug 2y agoChip8 was really good too, and it gets your feet wet with some VM programming
- callanmcc 2y ago[flagged]
- callanmcc 2y ago[flagged]
- gustavopezzi 2y agoAs someone who has been teaching assembly to undergrads for many years, I have a couple of things to say about this. First of all, I agree. The 6502 is great for beginners but that is not just merit of the 6502 language and I want to explain why. I have taught 68K, MIPS, ARM, x86, etc., and the overall good student feedback I got by teaching 6502 is mostly because of the surrounding context that comes with the CPU. The reason 6502 clicked better than other modern alternatives (MIPS, ARM, x86, etc.) was because we use it to program a real machine that is simple to understand (i.e. Nintendo Entertainment System). Rudimentary memory mapped IO, no operating system, no pipelined instructions, no delay slots, no network, no extra noise, ...it's just a simple box with a a clock inside, a CPU, some memory addresses, some helper chips, IO mapped to memory addresses, and that's pretty much it!!! So, even though I agree that the 6502 is not the simplest instruction set out there, THIS simplicity of the system helped a lot. And about the limitations of the 6502 CPU, these limitations were also important for students to understand that these instructions have a reason to be the way they are. CPUs were designed and wired given the constraints of that time, and that reflects on how we programmed for them. So, even thought this was mostly empirical, I have to say picking 6502 and the NES to teach beginners was successful. Once again, not really because it was the 6502, but because the 6502 forced us to go simple in terms of the sytem we were moving bits left and right. Once students played around with the 6502 and saw NES tiles moving on the screen, then it was super cool to evolve and show them how the 68000 did things differently, and then evolve more and show how MIPS came, show how pipelining works, how to take advantage of delay slots, and being able to compare the differences of RISC and CISC. It's super simple to evolve once the basics are there.
- markus_zhang 2y agoGustav, thanks for giving us Pikuma.
- gustavopezzi 2y agoMy pleasure! :)
- Angostura 2y agoZ80 was what I cut my teeth on. No idea if it's 'good', but it made sense and didn't particular weird at the time
- dwheeler 2y agoThe 6502 was a great CPU for its time and price point. I wrote many programs in its assembly language. However, if you're going to work on modern systems, there are too many differences for the 6502 to be a good first assembly language (unless the 6502 is your focus). The 6502 was designed to be easily implemented with relatively few transistors. For that it was amazing. There is a reason it was popular! But its CPU registers are only 8-bit, its call stack is 256 bytes, and for real work you need to use the zero page (zpage) well. None of these are likely to relevant to a modern software developer using assembly. Its design encourages the use of global locations, again, an approach that don't make sense on modern systems. I say this as someone who admires what the 6502 was able to achieve in its time, and I even have a long-running page dedicated to the 6502: https://dwheeler.com/6502/ https://dwheeler.com/6502/ If you want retro and easy, the 68000 has it beat in terms of simplicity of development. The 68K is quite regular & a little more like modern systems (sort of). However, I think starting retro is often a disservice. Most the time the reason to use assembly is performance. If you're running code on chips more than a dollar or so, getting performance out of modern architectures is MUCH different than retro computers. For example, today a lot depends on memory cache latency, yet is typically not a serious concern on most retro computers. So learners will learn to focus on the wrong problems. If you want a modern simple architecture, may I suggest RISC V? That's under a royalty-free open source license, and real computers use it today. It's pretty simple (your basic load-store architecture) and you can pick only the modules you care about. Full disclosure: I work for the Linux Foundation, but I'd say that anyway. Plausible alternatives are ARM and x86. If you subset them, they're okay. The reality is that assembly languages reflect the underlying system, and that will change over time.
- pcvarmint 2y agoI would say that the 6809 is a better first assembly language of that era. (I keep hearing references to 68xxx, but the 6809 is closer.)