Sunteți pe pagina 1din 1

27/12/12

Reduction Operator

Reduction Operator
Keysymbols : &, ~&, |, ~|, ^, ~^, ^~. The reduction operators are and, nand, or, nor, xor xnor and an alternative xnor. They take one operand and perform a bit-by-next-bit operation, starting with the two leftmost bits, giving a 1-bit result.
m o d u l er e d u c t T e s t ; r e g[ 3 : 0 ]a ,b, c ; i n i t i a lb e g i n a=4 ' b 1 1 1 1 ; b=4 ' b 0 1 0 1 ; c=4 ' b 0 0 1 1 ; $ d i s p l a y b ( &a ) ;/ /b i t w i s ea n d ,( s a m ea s1 & 1 & 1 & 1 ) ,e v a l u a t e st o1 $ d i s p l a y b ( |b ) ;/ /b i t w i s e o r ,( s a m ea s0 | 1 | 0 | 1 ) ,e v a l u a t e st o1 $ d i s p l a y b ( ^b ) ;/ /b i t w i s ex o r ,( s a m ea s0 ^ 1 ^ 0 ^ 1 ) ,e v a l u a t e st o0 e n d e n d m o d u l e/ /r e d u c t T e s t

Note: the bitwise xor and xnor are useful in generating parity checks. Please note carefully the differences in logical, bitwise and reduction operators. The symbols for bitwise and reduction overlap but the number of operands is different in those cases. EXERCISE What do the following evaluate to ?
$ d i s p l a y b ( &1 ' b 1 0 ) ; $ d i s p l a y b ( |3 ' b 1 0 1 x ) ; $ d i s p l a y b ( ^4 ' b 1 1 0 1 ) ;

Answers previous next contents

www.see.ed.ac.uk/~gerard/Teach/Verilog/manual/Operators/reduction.html

1/1

S-ar putea să vă placă și