Exemple #1
0
static int three_register_execute(UM_machine machine,
                                  Um_instruction instruction)
{
        unsigned op = Bitpack_getu(instruction, BITS_PER_OP_CODE, 28);
        unsigned A = Bitpack_getu(instruction, BITS_PER_REG_NUM, 6);
        unsigned B = Bitpack_getu(instruction, BITS_PER_REG_NUM, 3);
        unsigned C = Bitpack_getu(instruction, BITS_PER_REG_NUM, 0);

        switch(op){
                case 0: //
                        movc(machine, A, B, C);
                        return 1;

                case 1:
                        segl(machine, A, B, C);
                        return 1;
                        
                case 2:
                        segs(machine, A, B, C);
                        return 1;

                case 3:
                        add(machine, A, B, C); 
                        return 1;

                case 4:
                        mult(machine, A, B, C);
                        return 1;

                case 5:
                        divi(machine, A, B, C);
                        return 1;

                case 6:
                        nand(machine, A, B, C);
                        return 1;

                case 7:
                        return 0;

                case 8:
                        map(machine, B, C);
                        return 1;

                case 9: 
                        unmap(machine, C);
                        return 1;

                case 10:
                        out(machine, C);
                        return 1;

                case 11:
                        in(machine, C);
                        return 1;

                case 12:
                        loadp(machine, B, C);
                        return 1;
                default:
                        return 0;
        }
}
Exemple #2
0
int main(int argc, char* argv[])
{
        if(argc != 3) {
                fprintf(stderr, "wrong number of files\n");
                exit(1);
        }

        FILE *fp = fopen(argv[1], "r");

        FILE *write = fopen(argv[2], "wb");

        if (fp == NULL) {
                fprintf(stderr, "can't open read file\n");
                exit(1);
        }

        if (write == NULL) {
                fprintf(stderr, "can't open write file\n");
                exit(1);
        }

        char line[100];

       // char* opcode = NULL;
        uint32_t opcode;
        uint32_t value;
        uint32_t ra;
        uint32_t rb;
        uint32_t rc;

        int num_inst = 0;

        if (fgets(line, 100, fp) != NULL) {
                sscanf(line, "%d", &num_inst);
        }

        //uint32_t data[num_inst];

        //int i = 0;
        uint32_t word;

        while (fgets(line, 500, fp) != NULL) {
                sscanf(line, "%u %u %u %u %u", &opcode, &value, &ra, &rb, &rc);
                //op = convert_opcode(opcode);
                word = make_inst(opcode, value, ra, rb, rc);
                //i++;
                for (int j = 3; j>= 0; j--) {
                        putc((unsigned char)Bitpack_getu(word, 8, j*8), write);
                }

        }
/*
        for (int i = 0; i < num_inst; i++) {
                fprintf(stderr, "%u\n", data[i]);
        }
*/
        //fwrite(data, sizeof(uint32_t), num_inst, write);

        fclose(fp);
        fclose(write);

        return 0;

}