Continuous Assignment
جزء من قسم الأساسيات في رحلة Verilog على Coddy. الدرس 37 من 90.
في العتاد، connection هو سلك مادي يربط بين نقطتين في دائرة. بمجرد وضع السلك في مكانه، تصبح connection دائمة ونشطة always. إذا تغيّر أحد الطرفين، يتغيّر الطرف الآخر فورًا.
في Verilog، نحتاج إلى طريقة لنمذجة هذا السلوك. نريد تمرير قيمة إلى wire وإبقاؤها متصلة إلى الأبد. تُسمّى عملية القيام بذلك continuous assignment.
Continuous assignment يستخدم الكلمة المفتاحية assign لإنشاء اتصال دائم بين wire و expression. يأخذ wire قيمة expression continuously، تمامًا مثل wire فعلي.
فكّر في الأمر على أنه لحام سلك بدلاً من كتابة قيمة مرة واحدة.
البنية
assign wire_name = expression;| الجزء | المعنى |
|---|---|
assign | كلمة مفتاحية تبدأ عملية الإسناد المستمر |
wire_name | السلك الذي تتم قيادته (لا يمكن أن يكون reg) |
expression | القيمة التي تقود السلك |
مثال بسيط
wire out;
assign out = a & b;هذا يعني: out هو always مساويًا لـ a AND b. كلما تغيّرت a أو b، تتغيّر out فورًا.
كيفية عمله
على خلاف reg الذي يخزّن قيمة، يتم تحديث wire مع continuous assignment باستمرار:
module continuous_demo;
reg a, b;
wire c;
assign c = a & b; // c يتبع a AND b في جميع الأوقات
initial begin
a = 0; b = 0;
#10 $display("a=%d, b=%d, c=%d", a, b, c); // c=0
a = 1;
#10 $display("a=%d, b=%d, c=%d", a, b, c); // c=0 (1&0=0)
b = 1;
#10 $display("a=%d, b=%d, c=%d", a, b, c); // c=1 (1&1=1)
$finish;
end
endmoduleالناتج:
a=0, b=0, c=0
a=1, b=0, c=0
a=1, b=1, c=1في كل مرة تتغير فيها a أو b، يتم تحديث c تلقائيًا.
تعيينات متعددة
يمكنك أن يكون لديك تعيينات مستمرة متعددة في وحدة:
module multiple_assign (
input a, b, c,
output x, y
);
assign x = a & b;
assign y = x | c; // y يعتمد على x
endmoduleيتم تنفيذ all assignment بالتوازي، continuously.
الاستخدامات الشائعة
تُستخدم continuous assignments من أجل:
- المنطق التوافقي البسيط (AND، OR، XOR)
- توصيل wire معًا
- إنشاء مخازن ثلاثية الحالة
- قيادة output من continuous expressions
التحدي
ما يجب فعله:
- Add الـmissing continuous assignment that makes
zequalًا لـx AND y.
جرّب بنفسك
module continuous_challenge (
input x,
input y,
output z
);
// TODO: أضف التعيين المستمر المفقود الذي يجعل z يساوي x AND y
endmoduleيتضمن هذا الدرس اختبارًا قصيرًا. ابدأ الدرس للإجابة عليه وتتبّع تقدمك.
جميع دروس الأساسيات
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 Logicتدرّب بنفسك: مترجم Verilog عبر الإنترنت