Live data from Hacker News

I believe 6502 instruction set is a good first assembly language

nemanjatrifunovic.substack.com

291–297 of 297 posts

Re: I believe 6502 instruction set is a good first assembly language

#291

Earlier quoted context omitted.

The original 68K instruction set is distant from modern computing only in these points: - 32 bits - lack of vectorization and such. It's still perfect for most embedded stuff, by my estimation. Well .... there are certain points like: wasn't there some issue with branch displacements on MC68K being confined to 16 bit ranges? If you have large functions, it can be a problem. I dimly remember a project I was on circa 2…

> I remember having to chop the source file into several translation units, because when it was all in one file, the inlining or static function calls or whatever, were generating PC relative branches that were too large for the opcode. That's just inadequate tools. With GNU as for RISC-V if I write `beq a1,a2,target` and target is more than 4k away then the assembler just silently emits `bne a1,a2,.+4; j target` ins…

OK, I better informed/refreshed myself on this.

The MC68K has a BRA instruction with an opcode 0110 0000 (0x60). The low byte of the 16 bit opcode word is a displacement. If it is 0, then the next 16 bit word has a 16 bit displacement. If that low byte is 0xFF, then the next two 16 bit words have a 32 bit displacement.

The displacement is PC relative.

This unconditional 0x60 opcode is just a special case of Bcc which ids 0x6N, where N is a condition type to check for a conditional branch. Bcc also has 8, 16 or 32 bit displacement.

So, yeah; that's not a problem. Not sure what the issue was with that GCC target; it somehow just didn't generate the bigger displacements.

Re: I believe 6502 instruction set is a good first assembly language

#292

Earlier quoted context omitted.

> 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.

Also, compare the "zeropage indirect" address mode of the WDC 65C02, which does exactly this w/o involving any of the index registers.

Oh, 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.)

Re: I believe 6502 instruction set is a good first assembly language

#293
post #268

Earlier quoted context omitted.

> 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.

I 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 lan…

Implementing 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...

Re: I believe 6502 instruction set is a good first assembly language

#294

Earlier quoted context omitted.

Also, compare the "zeropage indirect" address mode of the WDC 65C02, which does exactly this w/o involving any of the index registers.

Oh, 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 indire…

Notably, 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.)

Re: I believe 6502 instruction set is a good first assembly language

#295
post #18

Was 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/

The 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

According 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.

Re: I believe 6502 instruction set is a good first assembly language

#296

Earlier quoted context omitted.

> real available hardware Last I checked the 65C02 was still being manufactured and sold. It can also at a blazing 14 MHz.

It'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 You ca…

For a "first dive" into a programming paradigm, I could see the appeal of something more "PC" shaped than "MCU shaped", just because it offers recognizable, easy ways to deal with primitive debugging.

If you have a memory-mapped frame buffer, you can write a single byte to it if you need a status checkpoint or tracking a variable. If you have a keyboard, you can probably read its buffer or use it for triggers.

Maybe modern debugging environments and tools make it easier, but I tend to think of my university assembly language class which featured original Intel SDK-86 boards with LEDs and hex keypads to interact with.

Re: I believe 6502 instruction set is a good first assembly language

#297

As 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. T…

Gustav, thanks for giving us Pikuma.

My pleasure! :)
Post reply on HN