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

Purpose

The goal of this project is to translate instructions to and from a binary representation. A rather useful function for you to use is: write a function which takes an unsigned int and translates it to a 32 character string consisting of 0's and 1's.

The only thing you have to be careful about is that C++ strings number the characters from left to right (i.e. index 0 in the MSB), while "real" bitstrings number right to left (index 0 is the LSB).

You will need to implement the following two functions:

Public Methods

static string binToStringInstr( unsigned int instr ) ;
The instruction is represented as a 32 bit unsigned int (thus, it's in "machine language" format). Translate this to the appropriate string (thus, if the instruction means "add $r1, $r2, $r3", that's the string that should be returned. Return the string "UNKNOWN" if you can't tell what instruction it is.
static unsigned int stringToBinInstr( string instr ) ;
The instruction is now written as a string. Convert this to an unsigned int. For example, the string could be "add $r1, $r2, $r3". You should translate the string to an unsigned int which is the machine language translation of "add".

You should handle:

  • Mixture of upper/lowercase letters (make it case-insensitive).
  • Unusual spacing. The only space that's guaranteed is the one after the instruction itself (there may be no spaces before or after the commas).
  • Comments. There may be a comments at the end. Comments begin with the character "#". You should ignore all characters beginning with "#" to the end of the string.
You may assume registers are numbered from $r0 up to $r31 and that they are valid. We won't indicate registers using $t0, $v0, etc. (however, for extra credit, you can translate valid alternate register names as described by the book).

Location of File

Go to ~sch1101/Proj/P3/, and there should be Translate.h. Those implementing it in Java should make the appropriate conversions.
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