|
module alu8(a,b,select,out,rst);
# T" H& q" s. m! { input[3:2]a,b,rst;6 t9 t" X! [/ \2 ]2 P5 t* @* f
input[2:0]select;( o) r, t1 g. R
output[4:0]out;
# `! O3 Q' w0 `8 \: v* T; ~. Q' Q reg[4:0]out;( G4 U" c. j. V& ~
parameter 7 ~: J0 e* M1 a7 c. Z5 c
idle=3'b000,
3 r8 j, p: U8 F8 f# x" s+ e s1=3'b001,9 f) Q4 b }7 a' X" [- K S" @
s2=3'b010,/ P, X7 g" x4 E T6 p) {
s3=3'b011,
7 F5 A/ c9 d1 Z3 v5 |; {1 B3 f s4=3'b100,
6 N* J% i, d6 E9 v9 {5 f s5=3'b101,( c- F# Y3 b6 h( t
s6=3'b110,
: ]/ u: R4 M) S s7=3'b111;3 J z+ r; w" m. z" S
3 B; i" t: |6 x
always@( a or b): _9 P8 t' O) c$ \4 ?
if(rst)! e+ i" y) ?* ?3 m" ^- e
out<=00000;
3 k& W. b. o' e else
* j1 E2 {/ c$ I( X2 m' ^. B- c begin4 G7 v6 n- A8 |7 j! S( ^
case(select)! }& r0 a8 W7 ?! `8 D
idle:begin
& e6 @% e! n! ]1 }0 t! \ out<=a;
! n! S* I7 S/ i. @, z) k' s end
, R6 |/ @, K: u m# E+ X, z A s1:begin: n. V# }3 i! |- q: N
out<=a+b;
) i+ v H$ O' {" N7 M end2 f( ^& F( Z7 Q7 U) t( \
s2:begin- z6 M/ O/ H: y) ~4 T9 y' m J
out=a-b;! d4 s3 p5 @" H! u8 ~" S
end1 x3 b; T6 X) Y+ o( x2 v
s3:begin
0 e" G+ U% B7 q' j- @5 s# V out=a/b;
* w9 l L5 ?# K) p end& o# D7 m q6 o. A( x
s4: begin! M4 u3 i- H1 m/ T
out=a%b;5 ?9 a: h1 d7 y* _
end
: S5 [& M' O* A s5:begin
' t( K6 Q9 f& @ out=a<<1; Z8 _) }3 d! n- ?4 g/ |. w
end" M x- R* c6 G0 j/ @9 Z6 `
s6:begin. N S. d z0 k
out=a>>1;. t( J9 Y: \8 B7 X; \
end+ ^1 Q' E1 k# `& l
s7:begin5 S2 `8 P. m. q& D
out=a>b;
% P1 c/ X5 W- \- Q9 Y3 c end
9 C; U; t- s4 ^1 n default! i9 l( G& _! P5 c- c
$display( "Invalid control signals!");7 ~1 S+ K# |. G
endcase
# I3 K* n# F5 e+ F6 g9 e1 L end% P% c0 z2 v7 |, w3 S2 Y
endmodule |
|