Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

TIL that a 6502 didn’t have division and remainder instructions. Yikes.


None of the 8-bit CPUs had that, but you can get pretty far with left- and right-shift (which is the same as multiplication and division by 2), which allows to compose multiplication and division by constants quite easily (it's a bit more trouble and usually too slow for a universal runtime mul/div, but one simply tried to avoid that, or use precomputed lookup-tables instead).


not division, but the 6809 8-bit processor did have a MUL(tiply) instruction.


I stand corrected and TIL :) That's pretty awesome actually, pity that the 6809 wasn't more popular in the home computer era (but looking at the price compared to the Z80 or even 6502 it's understandable - $37 versus $9 for Z80 and $6 for the 6502 in 1980 according to Wikipedia: https://en.wikipedia.org/wiki/Motorola_6809).


I worked in embedded systems design through this era. I don't remember ever hearing of a design using one 8-bit cpu vs another due to chip cost. Those Wikipedia numbers also seem suspect.


i wasn't aware of the price difference, and at the time i owned a 6809-based system - a dragon32 (a sort of UK re-branded version of the tandy colco). i wasn't fussed about the MUL instruction, but i simply loved all of the addressing modes that thing had.


Game consoles like the SNES (65816) had a coprocessor for multiplication, division, etc. You load the values into a certain address, wait a couple cycles, and retrieve the result.

Not pretty, but those CPUs were designed to be really cheap.


I learned a lot from Chuck Moore's designs; for instance he assumes that you know how to build multiply given a multiplication step instruction, or the full set of logic ops given just and and xor. (which comes on top of the traditional forth punning of logical and bitwise booleans)

> Before I studied the art, a binding was just a binding.

After I learned the art, an assignment was an assignment but an application was an application.

Now that I've understood the art, a binding is just a binding.


Zero page addressing was far more inconvenient than calling a library for division on the 6502

16 bit addresses didn’t fit into registers, so you keep pointers in the zero page (bytes 0-255). There was no 16 bit increment either, so to increment the pointer you incremented the low byte and on overflow increment the high byte


It is quite rare to need an actual division instruction; for the majority of cases you would simply precompute the modular inverse and use that with multiplication.

Non-constant modulo can often be computed by checking for roll-over when incrementing (or just computed in a similar way to division)


There are still modern CPUs that don't. Division/remainder is much much harder than all the other basic arithmetic operations.




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

Search: