Algorithms for Multiply and Divide

Started by Charles Pegge, March 13, 2024, 09:43:46 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Charles Pegge


Using only shifts and adds. For CPUs that don't have these built-in operations:

'AlgoMultiply
'positive integers
'm*n
int i
quad m,n,q
m=101
n=96
for i=1 to 64
  if n=0
    exit for
  endif
  if n and 1
    q+=m
  endif
  shr n 'shift right
  shl m 'shift left
next
print q

int b,i,j,k,n,m
n=1010
m=026
'n/m
if m=0
  end
endif
'shift m left
while n>m
  j=m
  k++ 'shifts counter
  shl m
wend
for i=1 to k
  shl b
  if n>j
    n-=j 'remainder
    b++
  endif
  shr j 'shift right
next
print b " remainder " n

Theo Gottwald


Charles Pegge

I have an ARM based RaspberryPi 400 sitting on my other desk, but no opportunity to use it much. It's a small keyboard with the processor board tucked inside, and connectors at the back. the modern ARMs have multiply, divide and floating-point SIMD coprocessors with sufficient power  to run smartphones. It's graphics power is rather limited  but overall  its a  competent Linux desktop.

Theo Gottwald

Its not that i need one, i just remember that some ARM Chips are so much RISC that they do not have own Divide operatoprs. So they use tables for this.