On Mon, 20 May 2019, Dwayne Reid wrote: > Hi there, Sergio. > > Many thanks for your insight. I'm going to writing some PIC > assembler code using your technique tonight. > > Question: I am completely incompetent in C. I downloaded and > installed a package called "MinGW" but I don't get much useful when I > try to compile the C program that you attached to your message. What > should I see? > > I tried "gcc pic_mult_test.c" and gcc creates a file called "a.exe" > in the directory. Running that exe give an output to the screen "0x76 = =3D 6". > > I tried "gcc pic_mult_test.c 171" and gcc reports an error: "no such > file or directory" > > If you don't mind leading a complete C newbie by the hand step by > step, I would greatly appreciate it. I do understand if you don't > have the time - I'll fumble my way through it. But your help is > greatly appreciated. > > Many thanks! > > dwayne Hi Dwayne, running "a.exe" without any parameters should produce: "0x7f =3D 6" 127 is the default multipler to use if no parameters are specified. for "a.exe 171" the result should be: "0xab =3D 7 0x40 0x10 0x4" This shows that the most significant bit set to 1 is bit 7, it then shows=20 which bits (from bit 7 down) are set to 0. It outputs these as bit masks=20 to make it easier to compare these bits with "0xab" but as bit positions=20 these are 0x40 =3D 6 0x10 =3D 4 0x04 =3D 2 Therefor to use the subtraction algorithm: where x =3D 171 y =3D (x << 7) - (x << 6) - (x << 4) - (x << 2) - x a simpler solution might be: y =3D (x << 7) - ((x << 6) + (x << 4) + (x << 2) + x) The program I presented was originally intended to prove that: x * (2^n - 1) =3D x * (2^n) - x e.g. x * 127 =3D (x << 7) - x As such the program did a brute force search to find any errors. I later=20 extended the program to be able to cope with random bit patterns. The only other thing the program produces are error messages if the=20 algorithm fails. What should be of most interest to you is: // given // x is a runtime variable // val is a runtime constant // y is the runtime product of x and val // find the most significant bit of val set to 1 for (msb=3D31; msb>0; msb--) { if ((val & (1<=3D0; k--) { if ((val & (1<