ADSD lab code
ADSD lab code
module d_flip_flop(
);
if (reset)
else
q <= d; // Store the input data on the rising edge of the clock
end
endmodule
module parallel_load_register(
);
if (reset)
else if (load)
data_out <= data_in; // Load the data when 'load' is high
end
endmodule
module serial_in_parallel_out_shift_register(
);
if (reset)
else
parallel_out <= {parallel_out[2:0], serial_in}; // Shift left and input new bit
end
endmodule
module parallel_in_serial_out_shift_register(
);
else
end
if (reset)
else
end
endmodule
EX no.2 Design of counters by Verilog HDL
module up_counter(
);
// Counter behavior
if (reset)
else
end
endmodule
module down_counter(
);
// Counter behavior
if (reset)
else
end
endmodule
(iii) Verilog Code for a 4-bit Up/Down Counter:
module up_down_counter(
);
// Counter behavior
if (reset)
else if (up_down)
else
end
endmodule
module async_up_counter(
);
if (reset)
else
end
always @(posedge count[0] or posedge reset) begin
if (reset)
count[1] <= 0;
else
end
if (reset)
count[2] <= 0;
else
end
if (reset)
count[3] <= 0;
else
end
endmodule
module async_up_down_counter(
);
if (reset)
else
end
if (reset)
count[1] <= 0;
else if (up_down)
else
end
if (reset)
count[2] <= 0;
else if (up_down)
else
end
if (reset)
count[3] <= 0;
else if (up_down)
else
end
endmodule
Ex no : 3 Design of sequential Machines by Verilog HDL
module moore_counter(
);
// State encoding
S0 = 2'b00, // State 0
S1 = 2'b01, // State 1
S2 = 2'b10, // State 2
S3 = 2'b11 // State 3
} state_t;
if 3(reset)
else
end
case (current_state)
endcase
end
case (current_state)
endcase
end
endmodule
module mealy_detector(
);
// State encoding
} state_t;
state_t current_state, next_state;
if (reset)
else
end
case (current_state)
endcase
end
case (current_state)
S0: detected = 0;
S1: detected = 0;
default: detected = 0;
endcase
end
endmodule
EX no.4 Design of serial adders, multipliers and divider by Verilog HDL
The microprocessor design can be broken down into the following components:
1. Registers: A set of registers for holding data and instructions.
2. ALU: The Arithmetic and Logic Unit for performing operations.
3. Control Unit: Decodes the instructions and generates control signals.
4. Program Counter (PC): Keeps track of the current instruction.
5. Instruction Fetch/Decode Unit: Fetches instructions from memory.
2. ALU Design
The ALU performs basic arithmetic and logical operations.
module ALU (
input [3:0] A, // Operand A
input [3:0] B, // Operand B
input [2:0] ALU_Control, // Control signal to select the operation
output reg [3:0] ALU_Result, // Result of the ALU operation
output reg Zero // Zero flag, set if result is zero
);
module RegisterFile (
input clk,
input reset,
input [1:0] read_addr, // Address of register to read from
input [1:0] write_addr, // Address of register to write to
input [3:0] write_data, // Data to write to the register
input write_enable, // Control signal to enable writing
output reg [3:0] read_data // Data read from register
);
module ControlUnit (
input [3:0] opcode, // Instruction opcode
output reg ALU_src, // ALU source control signal
output reg RegWrite, // Register write control signal
output reg [2:0] ALU_Control, // ALU control signal
output reg PC_src, // Program counter control signal
output reg MemWrite // Memory write control signal
);
module ProgramCounter (
input clk, // Clock signal
input reset, // Reset signal
input PC_src, // Control signal to change the PC
input [3:0] jump_addr, // Address to jump to
output reg [3:0] PC // Program Counter output
);
// Instantiate components
ProgramCounter PC_unit (
.clk(clk),
.reset(reset),
.PC_src(PC_src),
.jump_addr(jump_addr),
.PC(PC)
);
ALU ALU_unit (
.A(read_data),
.B(instruction[3:0]), // Use instruction as operand for simplicity
.ALU_Control(ALU_Control),
.ALU_Result(ALU_result),
.Zero(Zero)
);