Hacker News new | past | comments | ask | show | jobs | submit login
Easy 6502 (skilldrick.github.io)
172 points by rahimnathwani on May 30, 2022 | hide | past | favorite | 28 comments



I came across this when I was searching for resources to help better understand ALUs and assembler.

I love it because:

1. My first computer (an Acorn Electron) had a 6502 processor, and gave me my first exposure to assembler.

2. It's been built so you can do all the exercises in the browser. I really like stuff like this (e.g. Scrimba), as it makes it so much more likely that you'll get started.

A related point: as I go through it, I'm thinking about which instructions are really necessary (maybe all of them?) and why it would be inconvenient if you didn't have a particular instruction.


The simplest computer has only one instruction:

https://en.wikipedia.org/wiki/One-instruction_set_computer

There is even ZISC:

https://en.wikipedia.org/wiki/No_instruction_set_computing

Check out brainfuck if you are into stuff like this.


Very interesting, never heard of this. I love Hacker News for being able to learn something new from comments. Although I cannot agree with labeling "horizontally nanocoded CPU" as "No instruction set". There are instructions, they are just low-level.

I wonder, can Turing machine count as "Zero Insturction Set"? Technically there is no sequence of instructions.


That's a fair criticism.

I think this article describes it better than I could and I get why they chose that name:

https://www.lsmarketing.com/LSMFiles/9809-ai1.htm


Haha these are really interesting.

It seems to program with such a reduced instruction set requires one to be either a genius or a computer (i.e. generated code). I'm neither :(


Either that, or a compiler with such an instruction set as the target.

For instance:

https://github.com/arthaud/c2bf

It seems like this is a frivolous subject, but it is actually quite enlightening to realize just how little is required to get something that computes, it changes how you view the whole concept of computation.


Someone wrote a C compiler that generates code using only x86 MOV instructs.

https://github.com/xoreaxeaxeax/movfuscator


which instructions are really necessary (maybe all of them?) and why it would be inconvenient if you didn't have a particular instruction

The ones added in the 65C02 offer some insight there, a very brief overview from the Wikipedia page:

https://en.wikipedia.org/wiki/WDC_65C02#New_and_modified_ins...

Somewhat related and mentioned in one of the comments downthread, you can view Woz's SWEET16 as a 'the 16 bit CPU a 6502 system designer and programmer wished they had' take.


Tbf, the 6502 is super limited even by modern standards I think. I don't really think any of the instructions cannot find some use, not a single one. I think the only real instructions that you could think are not really "needed" are the "illegal opcodes[0]." Some games / demos including commercial ones use them, either for efficiency or just because I guess. A good "just because" reason I know of is for code obfuscation to deter disassembly and copyright infringement.

[0] https://www.masswerk.at/6502/6502_instruction_set.html#illeg...


Well, if you really want to nitpick, there are quite a few instructions in the 6502 that are unnecessary.

For example, STX. You could emulate it with PHA, TXA, STA, PLA.

But overall, you are correct that the 6502 was extremely primitive in various ways, especially compare to the 8080 and followers.


You'd need PHP/PLP too! STX doesn't affect the N and Z flags.


CLV is only there because the original 6502 had a SO (Set Overflow) pin, so if you wanted to test that pin, a CLV would be needed to remove the possibility your last ALU op set it.

BIT isn't super useful and is generally used to allow multiple entry points into a subroutine with slightly different starting instructions, not something it was intended for and not really needed.

There's a few instructions that aren't used that often unless you're being really hacky:

- RTI isn't something you'll normally be using unless you're writing an IRQ handler.

- TSX/TXS are only for changing the stack pointer, not a usual thing but might be used at times.


I've used Easy 6502 a ton. A few years ago, I got into Atari 2600 programming. I personally haven't made anything useful but the community is very active and doing truly amazing stuff. I use desktop software (Stella and DASM) these days but 8bitworkshop[0] is a great site for playing with it.

[0]https://8bitworkshop.com/v3.9.0/?platform=vcs&file=examples%...


My first Computer was a Commodore 116 which also had a 6502 derivative processor. I stumbled accross Ben Eaters video series and nostalgia hit me hard. I started the ZeroMips project (https://zeromips.org/) and now I have the old Amiga Bouncing Ball demo running on my Western Design Center W65C02S together with FPGA based video hardware. This escalated quickly ;)


Back in my Apple II+ days, I spent a great deal of time programming 6502 assembler. I learned a great deal of the language by studying the disassembly of the Apple ROM (written primarily by Woz) that was conveniently included in the user manual and studying programs written by others and published in a variety of Apple-centric magazines (Nibble come to mind). I wrote straight assembler programs as well as a hybrid assembler/Applesoft Basic. I'd written assembly programs for the IBM 360 in college so I undertood the gist but the 6502 just seem friendlier. Very fondly revered times.


For anyone interested in the 6502, assembly and just in general how things like loops, conditional branches, hardware communication, etc all work, I HIGHLY recommend Ben Eater's videos on the subject: https://www.youtube.com/watch?v=LnzuMJLZRdU

They are incredibly fascinating!


I like this. I learned ASM first on the PDP-11, and I thought that was a great introduction to assembly language concepts. 6502 has a lot of similarities with the PDP-11 instruction set, but also gives you the ability to (if you want to) more easily deploy your code to a real chip inside a real machine.


I used this when I was learning 6502 assembly so I could build my senior project (An NES game). It was tremendously helpful to rapidly test ideas on how to manipulate bits and test subroutines.


Modern debuggers make programming 6502 much much easier. The one (1) nes demo I made was finished in something like two weeks because I was able to just put random values at certain addresses to track the path of the program and watch the memory viewer in fceux at those addresses to see if the program hit those points, similar to mining with printfs. Without a debugger, doing it all from my lesser experience level and in the short amount of time I did do it would have been difficult.


A similar (but much more primitive) tool is The Visible Computer

https://archive.org/details/a2_Visible_Computer_v1.0_1982_12...

It's far too ancient to be of anything but historical interest now but it does run on a 6502.


6502 is relevant again thanks in part to THEC64, which did the retro console craze one better by making BASIC and cassette/disk-based software usable. There are programming guides out there that target THEC64, so even if it is emulated it's a fun, supported way to get started with low-level programming.


I wished I had this when first trying (and quickly giving up learning some 6502) back in ~1988.


> Nobody ever called x86 fun.

I thought x86 was pretty dang fun.


TBH I think people get stockholm syndrome with whatever their first assembler language is. I can't stand X86, but similarly find 6502 absolutely bonkers. My first ASM was MIPS-I, and apparently that makes me one of the few people that /like/ delay slots.


Hm, as a counter-example, I learned assembly languages in this order - Z80, x86, 6502, ARM, SuperH, MIPS (then some more). SH and MIPS I like the most, not because of delay slots specifically, but I do like the concept. (The one I "hate" is ARM.)


Well, my 1st assembler was IBM mumble... goto Computer History Museum to see a 1401 running; it had BCD representation (before ASCII), and variable-length fields for data, with the length being noted with a 'word mark' -- so you could add two 6,000 digit numbers with a single instruction.

Arm v8 seems to have fixed some of the arm v7 cruft -- what do YOU not like about arm?

My 2nd favorite is Z80 -- that also had 'automatic' move-a-string instruction (LDIR / LDDR). 8051 is OK. Z8 is OK. And MSP-430 is pdp-11esque.


> what do YOU not like about arm?

I find it difficult to read, it's aesthetics mostly, not necessary an architectural thing as such, the choice of mnemonics, why "ubfx", what's "rsb" - have to lookup these things constantly when I need them, while 6502 or x86 I can just open and read after all those years.

But that's just a personal preference certainly - yeah, I was fine with the abovementioned LDIR on Z80, heh.


Totally. “You never forget your first.”




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: