Menu
Coddy logo textTech

Zusammenfassung – Operator-Challenge

Teil des Abschnitts Grundlagen der Verilog-Journey von Coddy — Lektion 29 von 90.

challenge icon

Aufgabe

Vervollständige den Code, indem du die richtigen Ausdrücke für jede Aufgabe schreibst. Diese Herausforderung deckt alle Operatoren aus diesem Kapitel ab.

Was zu tun ist:

  1. Logical: Prüfe, ob sowohl value1 als auch value2 non-zero sind, und speichere das Ergebnis in logic_out
  2. Reduction: Prüfe, ob all bits von vector 1 sind, und speichere in reduction_out
  3. Shift: Verschiebe data um 2 bits nach left, und speichere in shift_out
  4. Concatenation: Combine high und low into einen 8-bit Wert, und speichere in concat_out
  5. Conditional: Speichere den larger Wert von `a` und `b` in cond_out

Probier es selbst

module operator_challenge;
  reg [3:0] value1, value2;
  reg logic_out;
  
  reg [3:0] vector;
  reg reduction_out;
  
  reg [7:0] data;
  reg [7:0] shift_out;
  
  reg [3:0] high, low;
  reg [7:0] concat_out;
  
  reg [3:0] a, b;
  reg [3:0] cond_out;
  
  initial begin
    // Logisch
    value1 = 4'd6;
    value2 = 4'd0;
    logic_out = ______;   // Prüfe, ob sowohl value1 als auch value2 ungleich null sind
    
    // Reduktion
    vector = 4'b1111;
    reduction_out = ______;   // Check if all bits of vector are 1
    
    // Shift
    data = 8'b00001111;
    shift_out = ______;   // Verschiebe data um 2 Bits nach links
    
    // Konkatenation
    high = 4'b1010;
    low = 4'b1100;
    concat_out = ______;   // Kombiniere high und low zu einem 8-Bit-Wert
    
    // Konditional
    a = 4'd7;
    b = 4'd12;
    cond_out = ______;   // Speichere den größeren Wert von `a` und `b`
    
    $display("6 && 0 = %d", logic_out);
    $display("&4'b1111 = %d", reduction_out);
    $display("00001111 << 2 = %b", shift_out);
    $display("{1010, 1100} = %b", concat_out);
    $display("max(7, 12) = %d", cond_out);
    $finish;
  end
endmodule

Alle Lektionen in Grundlagen