|
module alu8(a,b,select,out,rst);
& G) W4 D3 ^1 V9 Y( \9 L! o input[3:2]a,b,rst;
" a, q$ `/ R% Z: D9 T input[2:0]select;( d% }- X7 n' o" g- }2 u
output[4:0]out;
4 T0 x0 ?# S& L, c! t reg[4:0]out;; Z9 S0 D+ H& d- ~- N
parameter . p5 c4 l' B8 o
idle=3'b000,3 F, A$ M7 I! C$ l: J
s1=3'b001,( Y$ f2 T4 X5 x6 v
s2=3'b010,. M0 A1 u3 H1 H4 w0 O) a' H$ N J
s3=3'b011,
/ G1 Q2 P: M _) C* U3 x* [ s4=3'b100,
- c! ], e5 Z$ s: V Y- V2 o s5=3'b101,
7 L0 ]# k4 `/ [7 \ s6=3'b110,
4 f: b5 [& [- b s7=3'b111;# f: W: k' x! u* A
0 f o5 h' y" I" {: Q& y# n
always@( a or b)
0 @% e( Y n6 t# ~0 B+ k if(rst)
* w8 _6 _. a% E7 h out<=00000;2 k2 a) S8 Y2 S; `3 q
else
& `0 `# G( J2 Y! C- P7 O8 F begin4 }! X. V% b9 N' ?
case(select)
; m, t; M9 e/ p: J* D: F idle:begin
" {/ V5 W2 x$ E+ A out<=a;' _0 e& x0 A" |: H( j8 Z# ^/ Y
end4 O7 V7 F7 u- G) Y
s1:begin
$ G8 A" S: n z' |3 T$ R/ E out<=a+b;& U, M: _7 P1 k5 d+ B
end- i& a4 o* c$ z3 }8 h% T2 A
s2:begin- A! @) \! G; z9 }. C- G
out=a-b;
7 X# Z& @5 t+ U4 Z end$ B- ^4 g: ~0 j5 X' Q0 U
s3:begin" @1 J t. i$ r
out=a/b;
( K2 ~, v4 C9 Z: q5 Z end0 x& h+ e0 e* }% s9 N
s4: begin
: L5 r& @4 F u3 R) e1 i$ } out=a%b;
3 d! W7 }! z& n0 Q: U end* `0 r! t& R* P* x3 N. x' O( F
s5:begin
( v) b" A" G7 L, o) _" B- Y P out=a<<1;) o9 z8 W4 @2 K2 {7 f Z5 {
end
7 z8 Y6 E, B. X3 |) Ds6:begin- w! x; c2 S6 t! o! [' b( d
out=a>>1;
4 `6 C) p/ l- ^9 Aend, Q$ i D) ?" B$ a0 g! v( N. \
s7:begin
$ K6 _( R9 Q4 s4 [- b3 { out=a>b;# x) \. X. A1 C: {- U
end/ q3 O, S$ o# a5 ?& u! H/ @: h2 F: L
default: d/ ^4 t# e7 `( N& p0 I
$display( "Invalid control signals!");" F o$ H: c% T) ]
endcase1 u$ [0 \; B; i% w/ \8 G: ]# a& m. I
end
* k: v. i. D% E* s6 a endmodule |
|