|
|
c m s c 311
f a l l 2 0 0 2 |
| Bit |
| Variable | Description |
| bool value | Represents a single bit. When value is true, the bit is 1, otherwise it's 0. |
| Bit() ; |
| Default constructor. Sets value to false. |
| int getValue() const ; |
| Returns 0 if value is false, and 1 if value is true. |
| Bit & set() ; |
| Sets value to true. Return * this . |
| Bit & clear() ; |
| Sets value to false. Return * this . |
| Bit & flip() ; |
| Sets value to its negated value (i.e., flips true to false and vice versa). Return * this . |
| Bit & operator=( int valueIn ) ; |
| Sets value to false if valueIn is 0, otherwise set it to true. |
| Bit & operator=( bool valueIn ) ; |
| Sets value to valueIn. |
| Register |
| Variable | Description |
| ??? bit | Pick a reasonably type to store an array of Bit objects (as defined above). Hint: don't use an array of bits (although you can). The ??? means you get to pick the type for storing an array of bits. |
| int _size | Stores the number of bits, but only if needed (for example, if you choose an approriate class for the array of Bit, then that class may already keep track of the size), making this instance variable unnecessary. |
| Register( int numBits = 32 ) ; |
| Default constructor. Creates a register with numBits bits. If the number of bits is less than 1, then set numBits to 32 bits. The user can pick an arbitrary size register. |
| Bit & operator[]( int index ) ; |
|
Return the bit (by reference) at index. Assume user will
not go out-of-bounds. If you want to throw an exception, then name
the exception class exactly
ArrayIndexOutOfBoundsException (read up on C++ exceptions if you
wish). Note: this is the same name as the Java exception thrown.
|
| const Bit & operator[]( int index ) const ; |
| Return the bit (by reference) at index. (Same thing as previous, but it will return by const reference). Can also throw exception as above. |
| string getSignedDecimal() const ; |
| Return the value in the register as a string. Treat the value as signed (thus, it may have a leading minus sign). Use as few digits as needed (minimum of 1). |
| string getUnsignedDecimal() const ; |
| Return the value in the register as a string. Treat the value as unsigned. Use as few digits as needed. |
| string getHex() const ; |
| Return the value in the register as a string. Treat the value as unsigned. The string should represent the value written in hexadecimal. The result should have a 0x (zero followed by x) prepended (i.e., in front), and use lowercase letters for a, b, c, d, e, f. Use as few hex digits as needed (minimum 1). For example, you might have 0xcafe001 as a result. |
| Register signExtend( int totalBits ) const ; |
| Create a copy of this register, but with totalBits bits. The register should be sign-extended if totalBits > numBits. If totalBits <= numBits, return a copy of the register (which has numBits bits). |
| Register zeroExtend( int totalBits ) const ; |
| Create a copy of this register, but with totalBits bits. The register should be zero-extended if totalBits > numBits (i.e., the high bits are all 0's, but the low bits are copied). If totalBits <= numBits, return a copy of the register (which has numBits bits). |
| ??? operator~() ; |
| Bitwise negation. Flip all the bits. Figure out the appropriate return value by determining how the C version of bitwise negation modifies variables. |
| ??? operator&( const Register & other ) ; ??? operator|( const Register & other ) ; ??? operator^( const Register & other ) ; |
|
Bitwise AND, bitwise OR, and bitwise XOR.
You should determine what return type is appropriate for these bitwise operations. |
| ??? operator&=( const Register & other ) ; ??? operator|=( const Register & other ) ; ??? operator^=( const Register & other ) ; |
|
Bitwise AND, bitwise OR, and bitwise XOR.
You should determine what return type is appropriate for these bitwise operations, by basing it on C's versions of these operators: i.e., &=, |=, ^= |
| ??? operator+( const Register & other ) const ; |
|
Do a signed addition. If the size of other register
is smaller than this register's size, then create a SIGN extended
copy of the other register so that the copy has as many bits
as the this register.
If other has more bits than this, and this has N bits, then only use the lowest N bits of other to do the addition. Perform signed addition while ignoring overflow. The result should have numBits bits. This addition should "behave" like addition of int variables, when it comes to determining what (or what NOT to) modify. Thus, you should determine what return type is appropriate for addition. |
| ??? operator+=( const Register & other ) ; |
| Do a signed addition that behaves like operator+=. Again, ignore overflow. |
| ??? addUnsigned( const Register & other ) const ; |
|
Do an unsigned addition. If the size of other register
is smaller than this register's size, then create a ZERO extended
copy of the other register so that the copy has as many bits
as the this register.
If other has more bits than this, and this has N bits, then only use the lowest N bits of other to do the addition. Perform unsigned addition while ignoring overflow. The result should have numBits bits. This addition should "behave" like addition of int variables, when it comes to determining what (or what NOT to) modify. Thus, you should determine what return type is appropriate for addition. |
| ??? addUnsignedSelf( const Register & other ) ; |
| Do an unsigned addition that behaves like operator+=. Again, ignore overflow. |
| ??? operator-( const Register & other ) const ; |
| Do a signed subtraction. Hint: think two's complement. Ignore overflow. |
| ??? operator-=( const Register & other ) ; |
| Do a signed subtraction that behaves like operator+=. Hint: think two's complement. Again, ignore overflow. |
| ??? addUnsigned( const Register & other ) const ; |
|
Do an unsigned addition. If the size of other register
is smaller than this register's size, then create a ZERO extended
copy of the other register so that the copy has as many bits
as the this register.
If other has more bits than this, and this has N bits, then only use the lowest N bits of other to do the addition. Perform unsigned addition while ignoring overflow. The result should have numBits bits. This addition should "behave" like addition of int variables, when it comes to determining what (or what NOT to) modify. Thus, you should determine what return type is appropriate for addition. |
| ??? operator-() ; |
|
Overloaded unary minus operator. Negates the value in the
register treating the binary value as signed. Hint: how
does this differ (if at all) from bitwise negation?
Determine an appropriate return type by thinking about how unary minus affects int variables. |
|
See the class syllabus for policies concerning email Last Modified: Fri Sep 27 19:41:52 EDT 2002 |
|
|
|
|
|