5 ms·
I don't miss those early days of programming. It's fun to optimize and it's amazing what you can do with minimal resources, but it took an incredible amount of
by saulpw 3y ago
I don't miss those early days of programming. It's fun to optimize and it's amazing what you can do with minimal resources, but it took an incredible amount of effort to get a 70s-era computer to do elementary school arithmetic fast enough to be useful. People spent their lives working on analyses like this, only to find in a scant few years that the next chip has it built-in as a single instruction.
- jandrese 3y agoTo be fair, those chips made multiply a single instruction, but they would take tens or hundreds of clock cycles to complete. What it really saved you was precious working memory, no longer needing to consume a significant chunk of memory with a lookup table in order to multiply at a decent speed. If your platform has 16kb of working memory then a 2k lookup table is a huge ask. Even a small 512k lookup table is serious chunk of your memory budget, you have to really consider if wasting hundreds of clock cycles per multiply is a better option.
- boredhedgehog 3y agoI'm not even sure how to compare it fairly. For example, on the Super Nintendo you have to load 2 registers and then wait 8 cycles for the result. But of course those cycles could also be used for something different, if necessary.
- wvenable 3y agoI love these early days of programming as I do it as hobby. What's pretty amazing is how much you can do without any multiplication or division at all. With add, substract, and shifts you can do a surprising amount on a computer.
- gary_0 3y agoWith shifts, you can multiply and divide by any number you want, as long as it's a power of two. ;)
- wvenable 3y ago"Doctor, my arm really hurts when I bend it this way, do you have any advice?" "Don't bend your arm that way" You can honestly get around not needing arbitrary multiplication and division by just avoiding numbers that aren't powers of two. No oddly sized data structures, for example. It works well unless, of course, you're building a calculator.
- whartung 3y agoYou can do it by any number if you toss in addition. If you’re multiplying by a constant, you can factor it out. For example multiply by 40 (coincidentally the number of characters per line on common microcomputers), you could shift to multiply by 32, shift to multiply by 8, and add them together. Took some additional storage but was faster, particularly for 16 bit, than a general routine.
- dhosek 3y agoI remember “discovering” shift and add as a high school student for doing multiply by 40 (a useful operation for screen mapping) as an improvement over the more naïve x×y = x+x+…(y times)…+x. But seeing the table of squares thing, I see the genius of being able to take (x+y)²-(x-y)²=(x²+2xy+y²)-(x²-2xy+y²)= 4xy and what a brilliant piece of math that is.
- wkjagt 3y agoI do quite a bit of 6502 assembly (hobby only). And the only types of multiplications I’ve needed were either multiplying by a power of 2 (often if I’m using a data table where an entry is 2 bytes long and I need to calculate the index into the table), or multiplying by a known constant, which is solved by shift and add or a lookup table if I only ever need to multiply a small number of known values.
- tonyedgecombe 3y agoI quite enjoyed working within those tight constraints. It's very satisfying squeezing every last drop of blood from the system. What I don't miss is the lack of reliability. Modern systems are so dependable compared to what we had to deal with back then. Also it's nice being able to download your tools for free and find documentation online.
- JohnFen 3y agoI'm the exact opposite from you on this. One of the main reasons why I switched to extremely tiny microcontrollers for my hobby projects is because they bring a lot of those days back for me. Vive la différence! :)
- m463 3y agoI remember at the time thinking how much they could pull off with so little hardware. An IBM mainframe could do a giant block move (with padding) in one instruction. but a normal person couldn't afford that. But a 6502 was in reach. With the 6502 you had to be clever and do something similar in software. But yeah. It was enlightening when the 6502 didn't have an add instruction. (you had to do clear carry, then add with carry) These kind of tradeoffs persist through time. People do all kinds of ridiculous things with an inexpensive ESP8266 or ESP32.
- cbm-vic-20 3y agoIt's funny you used the single-instruction block move as an example. The successor to the 6502, the 65C816, does have a single-instruction block move. Actually it has two, one for when you want to move from the top down, and another when you wnat to move from the bottom up (in the case where regions overlap). https://snes.nesdev.org/wiki/MVN_and_MVP_block_copy https://snes.nesdev.org/wiki/MVN_and_MVP_block_copy
- m463 3y agoI had to look that one up... 370 - 32-bit, ibm, 1970 6502 - 8-bit, mos technology, 1975 65C816 - 16-bit, wdc, 1985 and even dug into this move characters long: http://www.simotime.com/asmins01.htm#MVCL http://www.simotime.com/asmins01.htm#MVCL lots of cobwebs in those memories...