arith. algorithms.


add

'a+b

	while b <> 0

		x = a xor b

		x2 = lshft a and b

		a = x
	
		b = x2
	wend

	result = a



subtraction

'a-b

	while b <> 0

		x = a and not b

		x2 = lshft not a and b

		a = x

		b = x2

	wend

	result = a



mult

'axb
	while b <> 0 
		x1 = a
		x2 = 1
	
		while x2 < b	

			x2 = lshft x2

			x1 = lshft x1

		wend

		'x2 = rshft x2

		x1 = rshft x1

		x3 = x3 + x1

		b = b - x1
	wend

	result = x3
	

'
div
'a/b

	b2 = b
	rx = 1
	
	while b2 < a
		b2 = lshft b2
		
		rx = lshft rx
	wend
	
	b2 = rshft b2
	rx = rshft rx
		
	rxt = rxt + rx
	
	while b2 > 0
		b2 = rshft b2
		rx = rshft rx
		
		if rxt + b2 <= a then
			rxt = rxt + tx
		endif
	wend
	
	result = rxt
		

'
'modulus

' comp sci.

' a / b = x
' 14 / 3 = 4 with 2 remaining

	b2 = b
	rx = 1
	
	while b2 < a
		b2 = lshft b2
		
		rx = lshft rx
	wend
	
	b2 = rshft b2
	rx = rshft rx
		
	rxt = rxt + rx
	
	while b2 > 0
		b2 = rshft b2
		rx = rshft rx
		
		if rxt + b2 <= a then
			rxt = rxt + tx
		endif
	wend
	
	result = a - rxt
		