1

I wrote an algorithm for computing the multiplication of two binary numbers. In my instruction set, there is no and instruction, just a nand(not and). I read and it logically makes sense that two nands make an and. I feel this is really simple and I'm overthinking it

So for example, if i wanted to compute the and of 3 & 1, how could i do this using two nand operations with two instructions

My ISA executes a Nand like the following and has 8 registers numbered 0-7. For example:

nand 1 2 3 (nand contents in reg1 and reg2 and store in reg3)

Machavity
  • 30,841
  • 27
  • 92
  • 100
James Wilks
  • 740
  • 1
  • 8
  • 20
  • I'm voting to close this question as off-topic because it is not "[a practical, answerable problem that is unique to software development](https://stackoverflow.com/help/on-topic)". – Makyen Jun 27 '18 at 23:52

2 Answers2

3
result = x nand y
result = result nand result

Use the second nand as a not.

user2357112
  • 260,549
  • 28
  • 431
  • 505
2

NAND is ~(a & b) so if you give it another ~, you get an and. If you don't have any NOT gates, you can build one out of NANDs: ~(a & a) is the same as ~a. Put it together, and you get

nand r1 r2 r3
nand r3 r3 r3
nmichaels
  • 49,466
  • 12
  • 107
  • 135