News for hackers. Stuff that matters.
Re:Easy 6502 by rahimnathwani on Monday May 30, 2022 @01:57PM (#31561686)
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.

Re:Easy 6502 by jacquesm on Monday May 30, 2022 @02:22PM (#31561956)
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.

Re:Easy 6502 by codedokode on Monday May 30, 2022 @06:14PM (#31564193)
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.

Re:Easy 6502 by jacquesm on Monday May 30, 2022 @07:30PM (#31564714)
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

Re:Easy 6502 by rahimnathwani on Monday May 30, 2022 @02:36PM (#31562104)
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 :(

Re:Easy 6502 by jacquesm on Monday May 30, 2022 @03:02PM (#31562408)
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.

Re:Easy 6502 by pkaye on Tuesday May 31, 2022 @12:55AM (#31566241)
Someone wrote a C compiler that generates code using only x86 MOV instructs.

https://github.com/xoreaxeaxeax/movfuscator

Re:Easy 6502 by pvg on Monday May 30, 2022 @03:10PM (#31562498)
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.

Re:Easy 6502 by noobermin on Monday May 30, 2022 @10:05PM (#31565465)
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...

Re:Easy 6502 by hota_mazi on Monday May 30, 2022 @11:26PM (#31565830)
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.

Re:Easy 6502 by tom_ on Tuesday May 31, 2022 @02:47AM (#31566747)
You'd need PHP/PLP too! STX doesn't affect the N and Z flags.
Re:Easy 6502 by tenebrisalietum on Monday May 30, 2022 @11:16PM (#31565784)
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.

Re:Easy 6502 by kgwxd on Tuesday May 31, 2022 @08:56AM (#31568964)
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%...

Re:Easy 6502 by hwd on Tuesday May 31, 2022 @05:22AM (#31567495)
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 ;)