ELEC 2607
Assignment 4
50 Marks
I. Write a complete well-commented Verilog code for a machine that detected two sequences A=001100
and B=110011 with overlap as received through input X. Beside the Clk and X, the machine has the
active-low asynchronous reset (Rst). The outputs A, B, and Z, are flags that are raised when Sequence A,
Sequence B, and either sequence is detected, respectively. You must use the simple shift register
circuit design, and draw the circuit.
25 Marks
VI. Draw a simple block diagram of the following Verilog code and explain its operation. This is a
typical ALU (Arithmetic Logic Unit).
10 Marks
//behavioral 8-function arithmetic and logic unit
module alu_8_bh (a, b, opcode, rslt);
//define inputs and output
input [3:0] a, b;
input [2:0] opcode;
output [7:0] rslt;
//the rslt is left-hand side target in always and is declared as type reg
reg [7:0] rslt;
//define operation codes
//parameter defines a constant
parameter add_op = 3’b000,
sub_op = 3’b001,
mul_op = 3’b010,
and_op = 3’b011,
or_op = 3’b100,
not_op = 3’b101, //negation
xor_op = 3’b110,
xnor_op = 3’b111;
//perform the operations
always @ (a or b or opcode)
begin
case (opcode)
add_op: rslt = a + b;
sub_op: rslt = a - b;
mul_op: rslt = a * b;
and_op: rslt = a & b; //also ab
or_op: rslt = a | b;
not_op: rslt = ˜a; //also ˜b
xor_op: rslt = a ˆ b;
xnor_op: rslt = ˜(a ˆ b);
endcase
end
endmodul
4