nand2/03_Sequential_Logic/BitShift9R.v

33 lines
677 B
Coq
Raw Permalink Normal View History

2023-01-11 10:13:09 +00:00
/**
2023-04-15 06:29:38 +00:00
* 9 bit Shiftregister (shifts to right)
2023-01-11 10:13:09 +00:00
* if (load == 1) out[t+1] = in[t]
2023-04-15 06:29:38 +00:00
* else if (shift == 1) out[t+1] = out[t]>>1 | (inMSB<<8)
2023-01-11 10:13:09 +00:00
* (shift one position to right and insert inMSB as most significant bit)
*/
`default_nettype none
module BitShift9R(
input clk,
input [8:0] in,
input inMSB,
input load,
input shift,
output [8:0] out
2023-01-11 10:13:09 +00:00
);
// Put your code here:
reg [8:0] reg9;
2023-01-11 10:13:09 +00:00
always @(posedge clk) begin
if (load == 1) begin
reg9[7:0] = in[7:0];
end
else if (shift == 1 ) begin
reg9[7:0] = reg9[8:1];
reg9[8] = inMSB;
end
end
assign out = reg9;
2023-01-11 10:13:09 +00:00
endmodule