1
$\begingroup$

Okay so I'm going through a book CS:APP.

I'm in chapter 2. And problem 2.13 talks about how the Digital Equipment VAX computer used bis (bit set) and bic (bit clear) instead of Boolean operations AND and OR.

Both instructions take a data word x and a mask word m. They generate a result z consisting of the bits x modified according to the bits of m. With bis, the modification involves setting z to 1 at each position where m is 1. With bic, the modification involves setting z to 0 at each position where m is 1.

Now you're given x and y. And you're allowed to use bis and bic to recreate x | y. And x ^ y.

Now I have already tried looking at the answers to understand what's going on. But I don't understand it.

If I literally look at explaination for bis and bic I would say bis just copies the mask and leaves x unused. And for bic it goes opposite of m, but also without using x. If I try to interpret it differently I end up with questions like what does bic do (for example) when m is 0?

The answers are for x | y: bis(x, y) where y becomes m... so a relatively simple answer. And for x ^ y (xor): bis(bic(x, y), bic(y, x)) where y and then x becomes m

So basically anything that could clarify what's going on here would be much appreciated!

And aside from this question, I also would like to ask if this is the right place for questions about a specific CS book? Because I'm teaching myself and don't have a teacher or someone to ask questions to and seeing with the previous exercise I also had a question it's possible that I might get a lot. But I can't find anything when searching on CS:APP (Computer Systems: A Programmer's Perspective) and yeah don't know where else to turn to. The book was recommended through teachyourselfcs.com if anyone was wondering.

$\endgroup$
0
$\begingroup$

If $z=\mathrm{bis}(x,m)$ then $$ z_i = \begin{cases} x_i & \text{if } m_i = 0, \\ 1 & \text{otherwise}. \end{cases} $$ This is exactly bitwise OR.

If $z=\mathrm{bic}(x,m)$ then $$ z_i = \begin{cases} x_i & \text{if } m_i = 0, \\ 0 & \text{otherwise}. \end{cases} $$ This is bitwise AND of $x$ and the bitwise complement of $m$.

In order to see how $\mathrm{bis}(\mathrm{bic}(x,y),\mathrm{bic}(y,x))$ computes bitwise XOR, we just need to compute the truth table: $$ \begin{array}{c|c|c|c|c} x & y & \mathrm{bic}(x,y) & \mathrm{bic}(y,x) & \mathrm{bis}(\mathrm{bic}(x,y),\mathrm{bic}(y,x)) \\\hline 0 & 0 & 0 & 0 & 0 \\ 0 & 1 & 0 & 1 & 1 \\ 1 & 0 & 1 & 0 & 1 \\ 1 & 1 & 0 & 0 & 0 \end{array} $$ Another way of seeing this is replacing $\mathrm{bis}(x,y)$ with $x \lor y$ (read: $x$ or $y$) and $\mathrm{bic}(x,y)$ with $x \land \lnot y$) (read: $x$ and not $y$): $$ (x \land \lnot y) \lor (\lnot x \land y), $$ which is one of the standard formulas for XOR. In C, it would look as follows: (x & ~ y) | (~x & y).

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.