Instance creation in Verilog
Creating an instance of a module is a very frequent task in Verilog. Let's see how efficiently can it be done
Start file
module sram #(
parameter AW = 12,
parameter DW = 32
)(
input clk,
input rstn,
input wr,
input rd,
input [AW-1:0] addr,
input [DW-1:0] wdata,
output [DW-1:0] rdata
);
// here goes the SRAM model
// ...
endmodule
End file
wire w_clk;
wire w_rstn;
wire w_wr;
wire w_rd;
wire [ 7:0] w_addr;
wire [15:0] w_wdata;
wire [15:0] w_rdata;
sram #(
.AW (8),
.DW (16)
) i0_sram (
.clk (w_clk),
.rstn (w_rstn),
.wr (w_wr),
.rd (w_rd),
.addr (w_addr),
.wdata(w_wdata),
.rdata(w_rdata)
);
View Diff
1,15c1,20
< module sram #(
< parameter AW = 12,
< parameter DW = 32
< )(
< input clk,
< input rstn,
< input wr,
< input rd,
< input [AW-1:0] addr,
< input [DW-1:0] wdata,
< output [DW-1:0] rdata
< );
< // here goes the SRAM model
< // ...
< endmodule
---
> wire w_clk;
> wire w_rstn;
> wire w_wr;
> wire w_rd;
> wire [ 7:0] w_addr;
> wire [15:0] w_wdata;
> wire [15:0] w_rdata;
>
> sram #(
> .AW (8),
> .DW (16)
> ) i0_sram (
> .clk (w_clk),
> .rstn (w_rstn),
> .wr (w_wr),
> .rd (w_rd),
> .addr (w_addr),
> .wdata(w_wdata),
> .rdata(w_rdata)
> );
Solutions
The best way to learn is to practice. Below, you will find some of the solutions other golfers have entered. To unlock higher ranked solutions, submit your own entry which does as well or better than the solutions you can currently see - climb the ladder!
Check out these helpful resources to improve your Vim skills... Game on.
Unlock 8 remaining solutions by signing in and submitting your own entry
#9 Dyson / @DoctorDalek1963 - Score: 197 - 01/24/24 @ 14:45
dwjw<C-V>jels.<Esc>f=<C-V>jr llct,(8)<Esc>jvhc(16)<Esc>ji i0_sram <Esc>jqq$Bd^yiwi.<Esc>ea (w_)<Esc>Pjq6@qjdGkf f <C-V>kdkkbhh<C-V>ks <Esc>kki <Esc><C-V>6jbygg8O<Esc>ggpqqI wire w_<Esc>A;<Esc>jq6@qkqq^ellR[15:0]<Esc>kq2@qjF1R 7<Esc>:%s/ \+;/;<CR>4jqqI <Esc>jq11@qZZ
0 comments