Hi guys,
do any of u know how to extract a certain amount of bits from a parameter(instruction) and return the bits as a integer in a range .
for example i would like to extract the opcode field i would extract from bits 31 to 26.
but if i wan to extract from bits 25 to 21 for R type registers, how can i go about it? Some help pls?
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void displayBits( unsigned value );
int main()
{
unsigned long x; /*user input variable*/
printf("Enter an long integer: ");
scanf ("%ld", &x );
displayBits( x );
return 0; /*indicates sucessful termination*/
} /*end main*/
/* display bits of an unsigned integer value*/
void displayBits( unsigned value )
{
unsigned c; /* counter */
/* define displayMask and left shift 31 bits */
unsigned displayMask = 1 << 31;
printf("%10ld = ", value);
/*loop through bits */
for ( c=1; c<=8; c++){
putchar( value & displayMask ? '1' :'0');
value <<= 1; /*shift value left by 1*/
if( c% 8 ==0){ /*output space after 8 bits*/
putchar( ' ' );
}/*end if*/
}/*end for*/
putchar(' \n ');
}/* end function displayBits */