2011年5月21日 星期六

Arbitrary Width Logic Type

#include

int sc_main (int argc, char* argv[]) {
sc_lv<8> data_bus (sc_logic ('z')); // All bits are Z 設定初值為Z
sc_lv<16> addr_bus ; // All bits are X 沒有設的為X
sc_logic parity ;
// Print Default value of data_bus
cout <<"Value of data_bus : " << data_bus << endl;
// Assign value to sc_bv
data_bus = "00001011";
cout <<"Value of data_bus : " << data_bus << endl;
// Use range operator
addr_bus.range(7,0) = data_bus;
cout <<"Value of addr_bus : " << addr_bus << endl;
// Assign reverse to addr bus using range operator
addr_bus.range(0,7) = data_bus;
cout <<"Value of addr_bus : " << addr_bus << endl;
// Use bit select to set the value
addr_bus[10] = "1";
cout <<"Value of addr_bus : " << addr_bus << endl;
// Use reduction operator
parity = data_bus.xor_reduce();
cout <<"Value of parity : " << parity << endl;

return 1;
}

SystemC 2.2.0 --- Mar 18 2011 18:40:28
Copyright (c) 1996-2006 by all Contributors
ALL RIGHTS RESERVED
Value of data_bus : ZZZZZZZZ
Value of data_bus : 00001011
Value of addr_bus : XXXXXXXX00001011
Value of addr_bus : XXXXXXXX11010000
Value of addr_bus : XXXXX1XX11010000
Value of parity : 1


沒有留言: