Page 1 of 2

Nand Gate

Posted: Fri May 01, 2015 4:11 am
by BobF
Bobs_Nand.fsm
(922 Bytes) Downloaded 1591 times
Hello gang,
Well I think I could use some help. I am trying to make a Nand gate that will mimic a Transistor Transistor Logic (TTL) Nand gate. Thats a hardware Nand gate that will pass Streamin data. I am not sure if the coding is right. Sometimes it SEEMS to work right and other times NOT. It should only work with values of 0 and 1, so I also coded a little module that will convert streamin data say from a Osc to just 0 and 1. Any help, suggestions, examples, etc., will be very greatly appreciated. Many thanks, BobF.....

Nand.png
Nand.png (7.5 KiB) Viewed 36658 times

Re: Nand Gate

Posted: Fri May 01, 2015 10:18 am
by KG_is_back

Code: Select all

streamin in1;
streamin in2;
streamout out;


out= 1 & ((in1 & in2) ==0);



Re: Nand Gate

Posted: Fri May 01, 2015 7:15 pm
by BobF
Hey KG,

Thanks a million! Sorry to ask for more, but if you have a moment what would it be for a NOR gate and XOR gate?
I really have trouble figuring out Boolean for some reason.

Thanks again. BobF

Re: Nand Gate

Posted: Fri May 01, 2015 7:52 pm
by KG_is_back
Actually there is even better solution to this. Assembler code has opcodes for preforming AND, OR, XOR and NOT(x) AND (also called ANDNOT). XOR is present only in the latest version of FS and ANDNOT has a syntax colouring bug in older versions (although it works normally)
Simple assembler modules will provide such functionality very easily. Also boolean logic will work very same way as for bitmasks if both numbers are the same.

Here are some codes for what you ask (same have two implementations, one for older FS versions,which not include XOR). Simply copy it to assembler component and remove parts you do not need (for better performance). Also "andps xmm0,F1;" code makes it work with input 1 rather than bitmasks.

Code: Select all

streamin A;
streamin B;
streamout outXOR;
streamout outNAND;
streamout outNOR;
float F1=1;
int In1=-1; //=bitwise all true

//XOR
movaps xmm0,A;
xorps xmm0,B;
andps xmm0,F1;
movaps outXOR,xmm0;
//XOR old version
movaps xmm0,A;
movaps xmm1,xmm0;
movaps xmm2,B;
andnps xmm0,xmm2;
andnps xmm2,xmm1;
orps xmm0,xmm2;
andps xmm0,F1;
movaps XOR,xmm0;


//NAND
movaps xmm0,A;
andps xmm0,B;
andnps xmm0,In1;
andps xmm0,F1;
movaps outNAND,xmm0;

//NOR
movaps xmm0,A;
orps xmm0,B;
andnps xmm0,In1;
andps xmm0,F1;
movaps outNAND,xmm0;

Re: Nand Gate

Posted: Fri May 01, 2015 10:42 pm
by BobF
Hi again KG,

Thanks many times over, you are a life saver. Now I just have to learn ASM and Boolean both (kidding around).
Have a great one! Later, BobF.....

Re: Nand Gate

Posted: Sat May 02, 2015 3:30 am
by martinvicanek
I think it shold read
int In1=-1; // bitwise true
not float.

Re: Nand Gate

Posted: Sat May 02, 2015 12:56 pm
by KG_is_back
martinvicanek wrote:I think it shold read
int In1=-1; // bitwise true
not float.

Ops.. my bad... fixed in original post...

Re: Nand Gate

Posted: Sat May 02, 2015 4:04 pm
by BobF
Hello All,

What version of Flowstone does "andnps" show up in? Mine does not seem to have it. I am using version 3.02 within Fl Studio. Thanks Bobf.....

Re: Nand Gate

Posted: Sat May 02, 2015 4:27 pm
by KG_is_back
andnps is in Flowstone since Synthmaker 2, I think. However, it has a syntax colouring bug - it is not recognized by assembler as valid opcode (code is marked black after it), although it works. Also one minor problem I forgot about: it works with registers only. So replace every "andnps xmm0,In1;" with "movaps xmm2,In2; andnps xmm0,xmm2;" and it should work.

Re: Nand Gate

Posted: Sat May 02, 2015 4:28 pm
by martinvicanek
3.0.8 fixes the syntax coloring bug. Otherwise KG is right that it has been there all along.