Assign With Operators
Coddy'nin Verilog Journey'sinin Temeller bölümünün bir parçası. Ders 38 / 90.
Sürekli atamayı (continuous assignment) anladıktan sonra, yararlı mantıklar oluşturmak için bunu operatörlerle birleştirebilirsiniz. assign ifadesi, bir teli sürmek için herhangi bir operatörü kullanabilir.
Temel Sözdizimi
assign wire_name = expression;İfade şunları içerebilir:
- Aritmetik operatörler (
+,-,*,/) - Bit düzeyinde operatörler (
&,|,^,~) - Mantıksal operatörler (
&&,||,!)
- Karşılaştırma operatörleri (
>,<,==,!=) - Kaydırma operatörleri (
<<,>>) - Koşul operatörü (
? :)
Farklı Operatörlerle Örnekler
Bit Düzeyinde (Bitwise) AND:
assign out = a & b;Toplama:
assign sum = a + b;Karşılaştırma (Comparison):
assign is_greater = (a > b);Koşullu (Çoklayıcı / multiplexer):
assign out = sel ? a : b;Shift:
assign shifted = data << 2;Concatenation:
assign bus = {high_byte, low_byte};Kod Örneği
module assign_operators (
input [3:0] a, b,
input sel,
output [3:0] and_out,
output [4:0] sum_out,
output is_equal,
output mux_out
);
assign and_out = a & b; // Bitsel AND
assign sum_out = a + b; // Toplama
assign is_equal = (a == b); // Karşılaştırma
assign mux_out = sel ? a : b; // Koşullu (çoklayıcı)
endmoduleTek ATAMA İçinde Birden Fazla Operatör
Operatörleri tek bir ifadede birleştirebilirsiniz:
assign result = (a & b) | (c ^ d);
assign final = (a + b) > (c - d);
assign parity = ^data; // Reduction XOR (tek sayıda 1'ler)Operatör Önceliği
Verilog standart operatör önceliğini takip eder. Amacınızı Clear bir şekilde belirtmek için parantez ( ) kullanın:
// Belirsiz
assign out = a & b | c;
// Açık
assign out = (a & b) | c;Görev
Görevlere göre eksik assign ifadelerini ekleyin.
Yapılacaklar:
and_resultifadesiniinput_a AND input_b(bitsel) olarak ayarlayınor_resultifadesiniinput_a OR input_b(bitsel) olarak ayarlayınxor_resultifadesiniinput_a XOR input_b(bitsel) olarak ayarlayınnot_resultifadesiniNOT input_a(bitsel) olarak ayarlayın
Kendin dene
module assign_challenge (
input input_a,
input input_b,
output and_result,
output or_result,
output xor_result,
output not_result
);
// TODO: Şunlar için assign ifadeleri ekle:
// and_result = input_a & input_b
// or_result = input_a | input_b
// xor_result = input_a ^ input_b
// not_result = ~input_a
endmoduleBu ders kısa bir quiz içerir. Soruları yanıtlamak ve ilerlemeni kaydetmek için derse başla.
Temeller bölümündeki tüm dersler
4Operators Part 1
Arithmetic OperatorsModulo OperatorComparison OperatorsRecap - Simple MathBitwise Operators7Assign And Gates
Continuous AssignmentAssign With OperatorsBuilt In Gate PrimitivesAND OR NOT GatesXOR XNOR GatesRecap - Logic Gate Circuit10Decision Making
If StatementIf - ElseRecap - Simple ComparatorCase StatementCasex And CasezRecap - ALU Design5Operators Part 2
Logical OperatorsReduction OperatorsShift OperatorsConcatenation OperatorConditional OperatorRecap - Operator Challenge3Number System
Binary RepresentationSized NumbersUnsized NumbersNegative NumbersSpecial Values X And ZRecap - Number Formats6Modules
Module StructureInput And Output PortsInout PortsModule InstantiationPort Mapping By NamePort Mapping By OrderRecap - Build A Module9Procedural Blocks
Always BlockInitial BlockSensitivity ListBlocking AssignmentNon Blocking AssignmentRecap - Always vs Initial15Traffic Light Controller
Defining The StatesState Machine LogicKendi başına pratik yap: Online Verilog derleyicisi