💻
Crafting Computer
  • Introduction
  • Logic Circuits
    • Not Gate
    • And Gate
    • Or Gate
    • Xor Gate
    • Multiplexer
    • Demultiplexer
  • Arithmetic Circuits
    • Addition
    • Subtraction
    • Multiplication
  • Arithmetic Logic Unit
  • Memory
    • Cascading Not Gates
    • S R Latch
    • S R Flip Flop
    • D Flip Flop
    • Random Access Memory
  • Von Neumann Architecture
  • Assembly Language
Powered by GitBook
On this page

Was this helpful?

  1. Logic Circuits

Not Gate

Let's start by looking at how to implement a logical not gate in Sim:

not a[1] -> [1] =
    nand a a

Notice that we first specify the interface of the circuit by declaring:

not a[1] -> [1]

This means that the not circuit takes one input pin called a that has a size of 1 and produces an output of size 1. We can use not as follows:

not_0 = not 0
-- not_0 is now 1
not_1 = not 1
-- not_1 is now 0

Note: line comments in Sim starts with --. Multi-line comments starts with {- and ends with -}.

At first, the way we called not may seem odd because you may be used to call syntax like this:

not_0 = not(0)

In Sim, to make function calls cleaner, we do not use parentheses around arguments. In addition, we use space instead of comma to separate arguments:

nand a a

instead of

nand(a, a)

Now you may also wonder where is nand defined. The answer is that unlike the not gate which is defined by the user, nand gate is a built-in circuit provided by Sim. It's the most fundamental logic gate and we can build all other gates and circuits from the nand gate.

PreviousIntroductionNextAnd Gate

Last updated 5 years ago

Was this helpful?