Menu
Coddy logo textTech

Recap - 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 korrekten Ausdrücke für jede Aufgabe schreibst. Diese Herausforderung behandelt alle Operatoren aus diesem Kapitel.

Aufgabe:

  1. Logical: Überprüfe, ob sowohl value1 als auch value2 ungleich null sind, und speichere das Ergebnis in logic_out
  2. Reduction: Überprüfe, ob all bits von vector den Wert 1 haben, und speichere das Ergebnis in reduction_out
  3. Shift: Verschiebe data um 2 bits nach left und speichere das Ergebnis in shift_out
  4. Concatenation: Führe high und low zu einem 8-bit-Wert zusammen und speichere das Ergebnis 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 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

Übe selbstständig: Online-Verilog-Compiler