Authored by: Anonymous on Saturday, May 11 2013 @ 06:13 AM EDT |
The Motorola 68k family have multiply and divide instructions built into the
instruction set, as I guess do the Intel 80x family.
However, aren't those CISC processors actually implemented by a more RISC core
running microcode to "emulate" the instruction? ie the instruction to
multiply is decoded to run a "miocrocode" subroutine to do the
multiplication.
For a slightly less low level example, consider the Sinclair ZX81 (aka Timex
1000): it implemented the various BASIC keywords for several mathematical
functions using a [reverse polish] "calculator". One specific
function, SQRT X was implemented as X**0.5 - ie it just used the exponent
function, which itself, IIRC, was implemented as EXP(0.5 * LN X).
cm[ Reply to This | Parent | # ]
|
|
Authored by: DL on Saturday, May 11 2013 @ 09:47 AM EDT |
Part of the problem with multiplication is that the result is often much wider
than the source registers, so you need to be able to store the result in 2
registers.
My assembly experience started with the 8086 and 68k, so I had the luxury of a
MUL instruction. On the other hand, I've also worked on computers where the CPU
was a set of circuit boards.
And now, for everyone who is wondering how computers multiply numbers, a simple,
brute-force multiplier would go something like this:
Put the operands in 2 registers (a place on the CPU that can hold one number), A
and B, and the result goes in register C.
Logically AND all the bits in A with bit 0 in B and add the result to C (to
logically AND two bits together means that if both bits are 1, the result is a
1, if either or both of the bits are 0, the result is a 0).
Shift the bits in A left 1 (has the effect of multiplying by 2).
Shift the bits in B right 1 (divides by 2),
Repeat the above 3 steps until you run out of bits.
The above leaves out a lot of stuff, and it's slow, but it gives the basic
concept.
I now await all the nit-pickers piling on. Sure, point out all the flaws in the
above, add all of the steps I left out, especially when you don't have very many
registers, talk about handling overflows, and go into the nasty details of what
it takes to make a good and fast multiplier. Melt people's brains, that's what
I say.
---
DL[ Reply to This | Parent | # ]
|
|
Authored by: Anonymous on Saturday, May 11 2013 @ 12:51 PM EDT |
Because they are just that. [ Reply to This | Parent | # ]
|
|
|
|