# Whether or not, to say "whether or not" or not.

A project log for Rubidium 2.0

This is an all in one spectrum and logic analyzer, robotics control platform, and modular synthesizer with audio in and sheet music out!

Or is it this or that, or neither this nor that?  Perhaps it doesn't matter.  That's not what this post is about, unless maybe it is.  Writing a compiler from scratch is no small task, on the one hand, but then again, on the hardware side of things there are always going to be those people who want to do things like "build" a compete CPU or at least an ALU with nothing but NOR gates; just like the Apollo guidance computer.  So while building such at beat is not in the cards, simulating on with software is certainly fair game, especially if there is also the possibility that a compiler for such a beast might emerge in the very near future.  So lets have a look at some code.

```inline DWORD nor(DWORD r1, DWORD r2)
{
DWORD result;
result = ~(r1|r2);
return result;
}

inline DWORD not(DWORD r1)
{
DWORD result;
result = nor(r1,r1);
return result;
}

inline DWORD or(DWORD r1, DWORD r2)
{
DWORD result;
result = not(nor(r1,r2));
return result;
}

inline DWORD and(DWORD r1, DWORD r2)
{
DWORD result;
result = nor(not(r1),not(r2));
return result;
}```

So far so good.  Just wait until you try to debug addition.  But first take a look at how we do "and" via DeMorgan's law.  Fairly straighforward.  Now assuming that you have addition, and if you also have the square of the first 255 integers in a look up table, 8 bit by 8 bit multiplication follows, like so:

```inline unsigned short mult8 (unsigned char c1, unsigned char c2)
{
unsigned short s0, s1, s2, s3, s4;
if ((c1==0)|(c2==0))
return 0;
if (c1==1)
return c2;
if (c2==1)
return c1;
s1 = (unsigned short) sub(c1,c2);
bool m_odd = (s0&0x1?true:false);
bool m_neg = (s1&0x8000?true:false);
if (m_odd) {
}
s0>>=1;
s2>>=1;
s3 = (unsigned short) sub(lut1[s0],lut1[s2]);
if (m_odd)
s4 = (unsigned short) sub(s3,c2);
else
s4 = s3;

ASSERT(s4==c1*c2);
return s4;
}```

Yes, script kiddies and sugar friends, that does the trick.  Which kind of makes me wonder what it would look like if I had a good C++ 6502 compiler, or C++ for the NOR machine, that is.  Care to try for 16 bit?  I think that this works, but I haven't run every possible test:

```inline DWORD square(unsigned short r1)
{
DWORD t0,result;
DWORD t1, t2, t3;
unsigned char highbyte, lowbyte;
lowbyte = r1&0xff;
highbyte = (r1&0xff00)>>BYTESIZE;
t0 = (lut1[highbyte]<<WORDSIZE)|(lut1[lowbyte]);
t1 = mult8(highbyte,lowbyte);
t2 = t1<<(BYTESIZE+1);
result = t3;
ASSERT(r1*r1==result);
return result;
}

inline DWORD mult16(unsigned short r1, unsigned short r2)
{
DWORD result;
DWORD t1, t2, t3, t4; 