|
module alu8(a,b,select,out,rst);
! q3 n# R+ D: A4 X0 A input[3:2]a,b,rst;4 |- p3 F5 r7 e" {! ~3 ?$ l
input[2:0]select;
# _( U& r! k7 h- U0 X& g, j9 O output[4:0]out;
3 [/ |: M, {1 f$ R reg[4:0]out;
! R' r, J; q. H0 k. c parameter
4 H$ t4 N' c# H7 g( O idle=3'b000,) J# w! B* t, a" K$ r
s1=3'b001,
( o( `# F# S, {6 X8 u s2=3'b010,
0 U7 Z1 w+ Y$ x( Y& I5 C. } s3=3'b011,4 A, G* B: _. \5 |, [/ R' Q
s4=3'b100,
1 U) W4 k) {- ?8 ^# X; Z& `$ Y: l s5=3'b101,
G2 G6 Y- {) y& ?2 I7 J s6=3'b110,1 Y! J9 I3 @( m2 f' x0 l3 B
s7=3'b111;$ l9 j) A) _7 z' F1 T# l
- I+ M( T0 E0 l( A' J2 h% h
always@( a or b)
% Q, n* [# ^6 I1 R2 V1 N if(rst)5 N1 V! z5 w; d% @# j
out<=00000;$ C; N' c2 \2 K# [
else
. b) K2 @3 M6 {) T) j begin# p- u6 p9 \' G" V! b! q' z
case(select)
, M* U" R: v; j) c* b9 y& g idle:begin$ }# z; [: c/ @' \+ r+ P, E( A. c
out<=a;
; ?, e$ }# f; Z8 o7 C end
/ ^8 O2 w" s9 a8 m. x9 j s1:begin6 Q. }6 p" O( J% T$ R
out<=a+b;
- g& s* o b( W2 k1 q1 ^ end
+ |9 Z5 k2 ~, P5 E s2:begin0 U3 z$ T+ F9 h; [: Z
out=a-b;; u7 a6 ` g9 F& \/ n" n( r2 `
end7 H( K1 M/ p3 K
s3:begin3 b( S6 E* x6 S% e0 C: u* K4 S0 y
out=a/b;
$ B" X4 v4 [5 ^) I# x) X1 M) K end0 H8 c& j6 C, F* I# j; ]
s4: begin
, Z3 j# f5 w9 p1 ^$ ]9 ]6 o out=a%b;$ F Q$ E7 S0 F9 q, \2 W6 {
end5 r/ w! G X; @ | @4 P
s5:begin
. v& ]6 ?9 h5 V, A( o out=a<<1;, i6 N( v) K- B3 M9 v d- o0 @0 m
end
3 n. `" O M/ K9 a. ns6:begin% c4 M) a7 U, Y# y0 v
out=a>>1;
6 N, ~9 ?6 H/ }5 R9 ^1 {/ Mend
; q) |- y% H- ^3 N/ t, y3 g) Ys7:begin- C8 S8 X/ B3 @; q' Z2 L* }% U
out=a>b;
: ?* W- V! ]% v+ c9 c end
7 m2 M; e$ L+ m- i, `. V) l7 ? o default
5 s4 b9 y+ h1 `2 g* i% N, D. j \ $display( "Invalid control signals!");# ?: w# f9 K6 b: ]- R; \+ v" j. x
endcase, i% E9 r. {& D+ ?' M2 B
end
6 {( \! z: m0 g1 J) X! r, N/ d endmodule |
|