Page 1 of 1

Simple subleq

Posted: Tue May 09, 2017 9:48 am
by MichaelFarthing
I've been quite intrigued by some of the discussion in this area. Perhaps geri (or someone else) might post some examples of how other basic operations - shifts or xor for example - can be carried out on a machine word using subleq. Just curious.

Re: Simple subleq

Posted: Tue May 09, 2017 9:53 am
by Geri
1. the best method of left shifting is multiplication, so:
-a+a (shift left by one byte)
-a+a+a (shift left by two byte)
etc

shifting 8, 16, 24, 32, 40 to left/rifht, etc is trivial, becouse you just read a byte forward-backward
2. right shift has to do with algorythm (i divide with pow(2, i)).
3. and/or/xor has to do with algorithm (i shift with one and check where the values will be negative and create the new bitfield as result and shifting that too).

the solution for 2 and 3 is my invention, but maybe alreday invented by someone else too, and maybe more optimal methods also invented previously.

also, more optimal methods should be exist (like having precalculated byte-tables) but i used algorithmic solutions to keep binary size smaller. i wrote the algorithmical solutions in C so i have no idea what subleq binary codes they compile to.

besides the very basic operations, i made everything with C algorithms