computer organization
c m s c 311  
f a l l   2 0 0 2  

Purpose

The goal of this project is to implement a representation of a register. This is a software emulation of a register. The register supports the following information:

Location of File

Go to ~chf11001/Proj/P1/, and there should be Register.h and RegisterInterface.java for C++ and Java respectively. Create Register.cpp or finish Register.java.

C++ Specifications

Bit Specifications (Java)

Bit

Private Instance Variables

Represents a single bit.

Variable Description
boolean value Represents a single bit. When value is true, the bit is 1, otherwise it's 0.

Public Methods

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 .


RegisterInterface Specifications (Java)

Register

Private Instance Variables

Variable Description
??? bit Pick a reasonably type to store an array of Bit objects (as defined above). The ??? means you get to pick the type for storing an array of bits. (There is a container class that begins with Array...look it up in the Java API at Sun's website).

Public Methods

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 getBitAt( 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 throw ArrayIndexOutOfBoundsException (this is already a built-in exception).

String getSignedDecimal() ;
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() ;
Return the value in the register as a String. Treat the value as unsigned. Use as few digits as needed.
String getHex() ;
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 ) ;
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 ) ;
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).
??? bitwiseNot() ;
Bitwise negation. Flip all the bits. Figure out the appropriate return value by determining how the C version of bitwise negation modifies variables.
??? bitwiseAnd( Register other ) ;
??? bitwiseOr( Register other ) ;
??? bitwiseXor( Register other ) ;
Bitwise AND, bitwise OR, and bitwise XOR.

You should determine what return type is appropriate for these bitwise operations.

??? bitwiseAndSelf( Register other ) ;
??? bitwiseOrSelf( Register other ) ;
??? bitwiseXorSelf( 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., &=, |=, ^=.

??? addSigned( Register other ) ;
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.

??? addSignedSelf( Register & other ) ;
Do a signed addition that behaves like operator+=. Again, ignore overflow.
??? addUnsigned( Register & other ) ;
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( Register other ) ;
Do an unsigned addition that behaves like operator+=. Again, ignore overflow.
??? minus( Register other ) ;
Do a signed subtraction. Hint: think two's complement. Ignore overflow.
??? minusSelf( Register other ) ;
Do a signed subtraction that behaves like operator+=. Hint: think two's complement. Again, ignore overflow.
??? addUnsigned( Register other ) ;
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.

??? negate() ;
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
left up down right home

Web Accessibility