Show HN: Architect – Hardware Description and Emulation JavaScript Library
github.com
github.com
module ForInpAndGate(a,b,c,d,o);
input wire a,b,c,d;
output reg o;
always @(*) begin
o <= a & b & c & d;
end;
endmodule;So we can implement a descriptive component doing something similar on the same lines.
But I kind of thought of pushing more for a `functional behaviour`. Hence I used the existing AND-Gate to build the Four Input AND-Gate.
I should probably put the descriptive component on the README as well
I want to kind of give this library a similar direction. It's in its infancy at the moment :P
In short, coding in verilog is like creating a schematic of the circuit.
Mostly hardware designers get away without thinking about all those above details in those terms, but sometimes you get bit by them (race-conditions between threads can occur, sadly) and it helps to understand it.
All programming is modeling of some sort or another.
The @(*) syntax is what's called the sensitivity list, it's saying that the state of the module should be recalculated whenever any of the inputs change. Other possible values might include something like @(posedge clk) if you have a clock signal called "clk" and you only want the outputs of the module to update on the rising edge of the clock signal. This is dramatically oversimplifying the insanely complex world of HDL, but it's ultimately not /that/ hard if you know your computer architecture fundamentals.
The main things that trip people up in Verilog coming from programming are the difference between synthesis and simulation, and the intrinsic parallelism with the two kinds of assignment operator.
There are all kinds of idioms that are syntactically valid Verilog that cannot be compiled to hardware. Usually you only use these while constructing a "testbench" to drive the simulated hardware.
There are also two kinds of assignment: = and <=. So for example, starting with a being set to 1 and b being set to zero:
b = a; c = b+1;
results in c being set to 2.
always @(posedge clk) b <= a; c <= b+1; end
results in b being set to a and c being set to 1: the value of b on the previous cycle plus 1. It also causes flip-flops to be inferred to hold b and c.
(Note that <= behaves differently depending on what's in the sensitivity list, which is also potentially very confusing!)
If I were still doing HDL design I'd advance my plan for modern object(bus)-orientated friendly HDL..
Let's hope the community shows some interest in my efforts to make this library the best of both worlds - verbosity with action :P
But one of the reasons might be because I would like the person going through my code to easily understand it without much problems.
It's more about perspective I suppose and the requirements of the project.
entity ForInpAndGate is
port( a: in std_logic;
b: in std_logic;
c: in std_logic;
d: in std_logic;
o: out std_logic;
);
end ForInpAndGate;
architecture behavioral of ForInpAndGate is begin
process(a, b, c, d) begin
o <= a & b & c & d;
end process;
end behavioral;
I don't think it's too much worse, and I do like some features of VHDL, such as it being strongly typed and having typed enums.Can you provide some reference link to systemVerilog?
http://standards.ieee.org/getieee/1800/download/1800-2012.pd...
There is an open source compiler which can compile the hardware description subset of system verilog to c++ called verilator:
http://www.veripool.org/wiki/verilator
It was originally developed to verify processor designs at DEC (Alpha etc.).
Unfortunately all the other features of system verilog are onl y implemented in commercial tools. I believe the Xilinx Vivado tools support most of it, the others are not really affordable if you are not at an academic institution (Modelsim/the Synopsis tools).
Thanks for the references though!
module FourInputAndGate(input [3:0] in, output out);
assign out = ∈
endmodule
Reference:
http://www.asic-world.com/verilog/operators2.htmlReally. Hardware is very fascinating. Great job OP!
* Nand2Tetris[2]
I didn't know about them though. My project's inspiration is due to the fact that I love JS and had a computer system architecture course wherein I learnt VHDL.
I felt that the NodeJS Events API could probably help me simulate a `signal` driven system and thus, I started experimenting :)
Thus,the I/O arguments of every hardware component are extensions to EventEmitter, resulting in quite an amazing simulation.