I've been trying to figure out how to do a nand bitwise operation in assembly but have been unsuccessful. I'm tried to write a logic gate simulator that will essentially produce this truth table for inputs A and B
A | B || F ----------------- lo | lo || hi lo | hi || hi hi | lo || hi hi | hi || lo
I've tried ever开发者_如何学JAVAything.
and $t3,$t1,$t not $t4,$t3
Does not produce the correct output
OF course it does, look at the truth table:
A B And Nand
---------------------
lo lo lo hi
lo hi lo hi
hi lo lo hi
hi hi hi lo
As you can see, you can get nand values by negating previously anded values. But you may have forgotten that and
and not
operate on each bit of the registers. I think you confused with boolean values, where (usually) any non-zero value is assumed to be true. Therefore,
11101001 nand 01000111 =
= ~ (11101001 and 01000111) =
= ~ 01000001 =
= 10111110
because
1 and 0 = 0
1 and 1 = 1
1 and 0 = 0
0 and 0 = 0
1 and 0 = 0
0 and 1 = 0
0 and 1 = 0
1 and 1 = 1
Next time you should post both expected and actual results too, this way it is easier for us to understand what went wrong.
精彩评论