下面是一个4位的双向移位寄存器程序,该程序正确吗?module UniversalShift (S1,S0,Din,Dsl,Dsr,Q,CP,CLR_); input S1, S0; //Select inputs input Dsl, Dsr; //Serial Data inputs input CP, CLR_; //Clock and Reset input [3:0] Din; //Parallel Data input output [3:0] Q; //Register output reg [3:0] Q; always @ (posedge CP or negedge CLR_) if (~CLR_) Q <= 4b0000; else case ({S1,S0}) 2b00: Q <= Q; //No change 2b01: Q <= {Dsr,Q[3:1]}; //Shift right 2b10: Q <= {Q[2:0],Dsl}; //Shift left 2b11: Q <= Din; //Parallel load input endcaseendmodule
举一反三
- 下列Verilog HDL程序所描述电路功能是( )module ShiftReg (Q,Din,CP,CLR_); input Din; //Serial Data inputs input CP, CLR_; //Clock and Reset output reg [3:0] Q; //Register output always @ (posedge CP or negedge CLR_) if (!CLR_) Q <= 4b0000; else begin //Shift right Q[0] <= Din; Q[3:1] <= Q[2:0]; endendmodule
- 下列Verilog HDL程序所描述电路功能是 .module _4bit_cnt (CP,nCR,Q,Mod); input CP, nCR, Mod; output reg [3:0] Q; always @ (posedge CP or negedge nCR) if (~nCR) Q <= 4b0000; else if (Mod==1) Q <= Q + 1b1; elseQ <= Q - 1b1; endmodule
- P,Q,R都是4bit的输入矢量,下面哪一种表达形式是正确的() A: input [3:0] P,Q,R B: input [3:0] P,Q,R C: input P,Q,R[3:0] D: input P[3:0],Q,R E: input P[3:0],Q[3:0],R[3:0] F: input [3:0] P, [3:0]Q, [3:0]R
- 执行以下程序,输入qp,输出结果是: k = 0 while True: s = input('请输入q退出:') if s == 'q': k += 1 continue else: k += 2 break print(k) A: 请输入q退出: B: 2 C: 3 D: 1
- k = 0 while True: s = input('请输入q退出:') if s == 'q': k += 1 continue else: k += 2 break print(k) 运行上述程序,并且输入qp,则程序输出的结果是( ) A: 0 B: 1 C: 2 D: 3