Exemplo n.º 1
0
Arquivo: um.c Projeto: brettgurman/UM
static UM_instruction get_next_instruction(FILE *fp)
{ 
        int c;
        UM_instruction next_instruction = 0;

        /* bitpack the instruction, 1 byte at a time */
        for(unsigned i=0; i < BYTES_PER_INSTRUCTION; i++){
                c = getc(fp);
                next_instruction = 
                Bitpack_newu(next_instruction, BITS_PER_CHAR,
                             24-(BITS_PER_CHAR * i), c);
        }

        return next_instruction;
} 
Exemplo n.º 2
0
uint64_t Bitpack_news(uint64_t word, unsigned width, unsigned lsb,
	int64_t value)
{	
	assert(lsb > 0);
	assert(!((with + lsb) >= 64));
	if(!(Bitpack_fitsu(value, width))) RAISE(Bitpack_Overflow);	
	uint64_t allones = 1;
	for(unsigned i = width; i != 1; i /= 2)
	{
		allones *= 2;
	}
	allones--; /*Converts to all 1's*/
	value = value & allones; /*Converts to unsigned*/
	return Bitpack_newu(word, width, lsb, value);
}
Exemplo n.º 3
0
/*	INIT_SEGMENT
 *  Input: A file pointer
 *
 *     This function creates a Seq_T and reads the file at
 *     the given file pointer and packs every four characters
 *     into a 32 bit instruction code and places it in the
 *     next space in the sequence. This sequence is then 
 *     placed at the 0th position in the segment memory sequence.
 *
 *  Output: N/A
 */
void init_segment(FILE* input, const char* file_name)
{
	struct stat buffer;
	int status;
	stat(file_name, &buffer);
	status = buffer.st_size / 4;
	Seg_array seg_array = initialize_seg_array(status);
	unsigned a;

	while ((int)(a = fgetc(input)) != EOF){
		unsigned b = fgetc(input);
		unsigned c = fgetc(input);
		unsigned d = fgetc(input);

		Um_Instruction instruct = 0;
		instruct = Bitpack_newu(instruct, 8, 24, a);
		instruct = Bitpack_newu(instruct, 8, 16, b);
		instruct = Bitpack_newu(instruct, 8, 8, c);
		instruct = Bitpack_newu(instruct, 8, 0, d);
		seg_array->segment[seg_array->num_elements] = instruct;
		seg_array->num_elements++;
	}
	SEG_MEMORY[0] = seg_array;
}
Exemplo n.º 4
0
int main(int argc, char* argv[])
{
    (void) argc;
    (void) argv;
    if(Bitpack_fitsu(5,3)) printf("5 fits 3 unsigned\n");
    if(!Bitpack_fitsu(8,3)) printf("8 doesn't fit 3 unsigned\n");
    if(Bitpack_fitss(1, 3)) printf("1 fits 3 signed\n");
    if(!Bitpack_fitss(5,3)) printf("5 doesn't fit 3 singed\n");

    if(Bitpack_fitss(-8, 4)) printf("-8 fits 4 signed\n");
    if(!Bitpack_fitss(-100000000000000, 4)) printf("too big doesn't fit\n");
    
    if(!Bitpack_fitsu(5, 0)) printf("unsigned width 0\n");
    if(!Bitpack_fitss(5, 0)) printf("signed width 0\n");
    unsigned long temp = ~7;
    fprintf(stderr, "%lu\n", ~temp); 

    //uint64_t width = atoi(argv[1]);
    //uint64_t lsb = atoi(argv[2]);
    //uint64_t value = atoi(argv[3]);
    /*uint64_t unsignedValue;
    printf("%lu %lu %lu\n", width, lsb, value);
    uint64_t i = Bitpack_newu(unsignedValue, width, lsb, value);
    printf("%lu stored in %lu bit: %lu\n", value, lsb,
            Bitpack_getu(i, width, lsb));
*/
    //unsigned u = 20;
    int a = 275;
    uint64_t j = Bitpack_newu(j, 9, 23, a);
    printf("val: %d lsb: %d bit: %ld\n", a, 23,
            Bitpack_getu(j, 9, 23));
    j = Bitpack_news(j, 5, 18, -15);
    //j = Bitpack_newu(j, 5, 13, 31);
    printf("val: %d lsb: %d bit: %ld\n", a, 23,
            Bitpack_getu(j, 9, 23));


    return 0;
}
Exemplo n.º 5
0
/*This is the apply function for reading from the input file. For each index in 
  the UArray2_T, this function reads the next word from input and stores the 
  word*/
static void store_compressed(int i, int j, UArray2_T uarray2, 
                             void *elem, void *cl)
{
        (void) i;
        (void) j;
        (void) uarray2;

        FILE *input = *((FILE**)cl);
        uint64_t word = 0;

        int lsb = INIT_LSB;
        int value = 0;

        while (lsb >= 0) {
                value = fgetc(input);
                if (value == -1) {
                        return;
                }
                word = Bitpack_newu(word, BITWIDTH, lsb, value%256);
                lsb -= BITWIDTH;
        }
        *(uint64_t *)elem = word;
}