|
In the context of this algorithm "w" stands for the bit-width. So it would work for w=16 in the case of the Hack system. The loop goes from 0 to w-1, to ensure that you run through w iterations - one for every bit (e.g. bit 0 to bit 15 in this case).
An additional remark: The definition of the algorithm states x,y>=0. Positive numbers in two's complement representation will only use 15 bits. So with this limitation of x,y>=0, the algorithm would also work with w=15. In this case you have to convert negative operands first and adjust the result depending on the signs of the operands.
However, for multiplication of signed numbers, the algorithm would also work ignoring the sign of the operands and just run through all 16 bits (like an unsigned multiplication with w=16). The result will still be correct and with the correct sign.
|