Interactive PowerBasic Forum

IT-Consultant: Charles Pegge => OxygenBasic Examples => Topic started by: Charles Pegge on March 13, 2024, 09:43:46 AM

Title: Algorithms for Multiply and Divide
Post by: Charles Pegge on March 13, 2024, 09:43:46 AM

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
Title: Re: Algorithms for Multiply and Divide
Post by: Theo Gottwald on March 14, 2024, 09:36:38 PM
Are you planning an ARM Version?
Title: Re: Algorithms for Multiply and Divide
Post by: Charles Pegge on March 14, 2024, 11:21:23 PM
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.
Title: Re: Algorithms for Multiply and Divide
Post by: Theo Gottwald on April 04, 2024, 01:56:35 PM
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.