Mockup in C of hardware implementation for multiplication of signed integers
Sign bit manipulation unnecessary

I looked at your code and was puzzled by all the sign bit manipulation.  As far as I can tell, it's not necessary.  I rewrote your function to be like the following and it still passed all your tests:

int multiply(int a, int b)
{
    // Bit keeps track of mask bit index.
    struct {
        unsigned int index: 5;
    } bit = {31};
    int prod = 0;

    do {
        prod += ((a &amp; (1 &lt;&lt; bit.index)) ? b &lt;&lt; bit.index : 0);
    } while (bit.index--);

    return prod;
}


Bonus answer: no conditionals inside loop

int multiply(int a, int b)
{
    // Bit keeps track of mask bit index.
    struct {
        unsigned int index: 5;
    } bit = {31};
    int prod = 0;

    do {
        prod += (-((a &gt;&gt; bit.index) &amp; 1)) &amp; (b &lt;&lt; bit.index);
    } while (bit.index--);

    return prod;
}


Explanation:


((a &gt;&gt; bit.index) &amp; 1) is 1 or 0 depending on the masked bit.  Call this B.
-B is -1 or 0.  This sets up a mask to use for the next step (-1 is a mask of all one bits).
-B &amp; (b &lt;&lt; bit.index) is either (b &lt;&lt; bit.index) or 0.