I'm new to Verilog, so please excuse any newbie mistakes. I'm trying to implement a 3 byte stack in verilog. Using R_W to read write (push/pop) and a 2D Array to store the contents of the stack.
`timescale 1ns / 1ps
module one(R_W,PUSH,POP);
input PUSH;
input R_W;
output POP;
wire [31:0] PUSH;
reg [31:0] POP;
wire R_W;
reg [31:0] temp[0:3];
integer tos = 3;
if(R_W == 1 && tos != 3)
begin
POP = temp[tos];
end
if(R_W == 0 && tos != 0)
begin
tos = tos +1;
POP = temp[tos];
end
endmodule
Test Bench
`include"one.v"
module one_test();
wire pop;
reg [31:0] push;
wire r_w;
initial begin
push = 2'd12;
r_w = 0;
#10
$finish;
end
one one(r_w,push,pop);
endmodule