It has to do with what can be easily evaluated at elaboration time, formally, what is called a "locally static expression". This is an obscure looking rule, but it deserves some thought - eventually it does make some sense, and your simulator is quite correct in alerting you by generating non-obvious results.
Now, temp(1)
can be evaluated at compile time (even earlier than elaboration time) and it can generate a driver on bit 1 of "temp".
However, temp(i)
involves a bit more work for the tools. Given the trivial nature of the loop bounds here ( 1 to 4 ) it is obvious to us humans that temp(0) cannot be driven and what you are doing is safe. But imagine the bounds were functions lower(foo) to upper(bar)
in a package declared somewhere else... now the most you can say with certainty is that temp
is driven - so the "locally static" expression is temp
.
And that means that the process is constrained by these rules to drive all of temp
, at which point you have multiple drivers on temp(0)
- the process driving (no initial value, i.e. 'u') and the external temp(0) <= '0';
.
So naturally the two drivers resolve to 'U'.
The alternative would be a "hacky little rule" (opinion) that if the loop bounds were constants, do one thing, but if they were declared as something else, do something else, and so on ... the more such oddball little rules there are, the more complex the language becomes... in my opinion, not a better solution.
Best Answer
Can you clarify what HDL you want to use? The choices are basically Verilog or VHDL, [EDIT], and their relatives, Verilog-ASM and VHDL-ASM (Analog mixed-signal). [/EDIT]Verilog has some C-like syntax, which makes it easier to pick up if you've worked with C before, but this also makes it easy to develop bad habits - You can't program hardware in C, because it's all parallel! Also like C, it assumes you know what you're doing, and it's easy to shoot yourself in the foot. VHDL forces you to think in a totally different way, which is helpful, but difficult. It is more verbose, and more likely to warn you if you do something strange. See this Slashdot discussion, or this article.
EDIT: The "Netlist languages" are not something I've used for design work (in a text editor), but I suppose that you could. SPICE, Cadsoft Eagle's format, and EDIF are all examples (with very different purposes) that come to mind. I've only used netlists to verify that my schematic is correct (does each connection in my Eagle schematic make sense), to tweak the abstraction provided by a simulator (SPICE, similar to the way one uses ASM statements in C), or to do export/import between different programs (EDIF).
The Spectre netlisting language is related to Verilog-A[nalog] and SPICE, and is designed for design and verification work. MAST is a component modeling language which is compatible with Verilog-AMS and VHDL-AMS. Searching for tutorials on these languages shows that tools which look like schematic capture utilities are often used, rather than programming in the netlisting language itself.
I'll also second the Xilinx Spartan FPGA, and a Digilent dev board. However, I'd go with the Basys ($60) or Nexys ($100) if you don't need the Ethernet on the Starter board ($150) mentioned by O Engenheiro (Prices with education discount). The Basys and Nexys are cheaper and therefore more popular in schools, so there are more tutorials and labs online.