4 ms·
Perhaps this is a naive question, but why would something like this be written in assembler, and not C or similar? It seems assembler makes it a bit more compl
by Alupis 8y ago
Perhaps this is a naive question, but why would something like this be written in assembler, and not C or similar?
It seems assembler makes it a bit more complicated without much benefit, and surely there's a compiler for a chip as common as the 6502.
- gridspy 8y agoBecause the cheapest chips have very limited code and memory space. And back when this product was released, optimizing compilers were really poor by comparison with a human for these tasks. Today you probably wouldn't bother with assembly for all but the most timing critical parts.
- bengarrr 8y agoYou'd be surprised how much overhead a compiler adds even for something like C. Also you can do things in pure assembly that you just can't do in C (w/o inlining assembly haha).
- TomVDB 8y agoFrom my reading of the code, this microcontroller has 128 bytes of RAM.
- dzdt 8y agoNo higher level languages were ever competitive with assembler for the 6502. The stack model of C is not a good fit, as the 6502 machine stack doesn't give any support for reading or writing stack-based variables. Good performance depends on effective use of the zero-page -- the first 256 bytes of memory which have special addressing modes and allow more efficient access. Registers are few and quirky -- accumulator, two index registers which are not quite interchangeable, a byte stack pointer. All operations are 8 bit; 16 bit calcs like for pointers are costly both in code size and speed. Back in the 80's and 90's the best compiled languages were probably COBAL and Forth. As far as I know nobody seriously used these for games or applications. There are more recent C compilers, but the code generation is multiples of size and speed (5* maybe?) away from assembler.
- kstrauser 8y ago*COMAL (see https://en.wikipedia.org/wiki/COMAL https://en.wikipedia.org/wiki/COMAL)
- dzdt 8y agoHa! Yes, COMAL. Thanks.
- exikyut 8y agoWell, Mattel used Forth: https://groups.google.com/d/msg/comp.lang.forth/omi6PUvymEE/QL-MsNwhPygJ https://groups.google.com/d/msg/comp.lang.forth/omi6PUvymEE/... Because it was cheap: https://groups.google.com/d/msg/comp.lang.forth/LzOasFOyIMg/xBcoPILM4_YJ https://groups.google.com/d/msg/comp.lang.forth/LzOasFOyIMg/... (forth not mentioned here; plausibly(?) extrapolating) Some nearby discussion about 6502 market penetration (I can't determine whether Forth is being discussed here - oh and dodge the cartoon fistfight-cloud wending its way between the posts, happens a lot on this usenet group): https://groups.google.com/d/msg/comp.lang.forth/Yoa9u55cpbo/9gNfJe7vvhsJ https://groups.google.com/d/msg/comp.lang.forth/Yoa9u55cpbo/...
- lifepillar 8y agoFor those into modern (!) medium-level 6502 programming, PLASMA [0] may be better (syntax-wise) than Forth and better (size and performance-wise) than C. [0] https://github.com/dschmenk/PLASMA https://github.com/dschmenk/PLASMA
- protomyth 8y agoCompilers just didn’t get as good of code as assembler. Really, for the 6502, 6809, and space constrained 68000s assembler was really fun and just worked. Have a decent macro assembler and some discipline and assembler was pretty easy and understandable. Heck, I’ve seen C code that was a whole lot less clear or understandable.
- rustcharm 8y agoA lot of these PWM algorithms required counting clock cycles which is only practical in assembler.