C語言的switch/case語句
switch(tmp)
{
case 1:
high =1;
break;
case 3:
high =5;
break;
case 5:
high =2;
break;
case 9:
high =1;
break;
default:
high =11;
}
Verilog的case語句
case(tmp)
1: high =1;
2: high =5;
3: high =1;
4: high =1;
default: high = 1;
always @(posdage clk)
if(rst)
begin
low <= 4'h0;
high <= 4'h0;
end
else
begin
case(low)
0,1,2,3,4,5,6,7,8:
low <= low+4'h1;
9:
begin
low <= 4'h0;
case(high)
0,1,2,3,4,5,6,7,8:
high <= high+4'h1;
9:
high <= 0;
endcase
end
endcase
end
end module
always @(posdge SCK)
if(nCS)
bitcnt=0;
else
state = next_state
always @(posdge SCK)
case(state)
BIT_RECV:
begin
bitcnt <= bitcnt+4'h1;
shift_in <= {shift_in[6:0], MOSI};
end
BYTE_SAVE:
begin
bitcnt <= 4'h0;
data <= deshift_in;
end
endcase
always @(posdge clk)
if(!nCS)
casex(instr)
16'b0000_0000_????_????: //MOV
begin
acc <= instr[7:0];
pc <= pc + 16'h0001;
end
16'b0000_0001_????_????: //ADD
begin
acc <= aluout;
pc <= pc + 16'h0001;
end
16'b0000_0010_????_????: //SUB
begin
acc <= aluout;
pc <= pc + 16'h0001;
end
16'b1???_????_????_????: //JMP
begin
pc <= instr[14:0];
pc <= pc + 16'h0001;
end