Find the answer to your Linux question:
Results 1 to 1 of 1

Thread: cpu simulator

Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    Question cpu simulator


    I am having a look at a computer simulator for the spear32.

    As far as I understood the simulator works like this:

    There is an array static union opcode_t progmem [CODESIZE] which hold the complete binary intruciton file. opcode_t is a union with stuct elemtens representing the different instruction classes.

    union opcode_t
    uint16_t reg : 4;
    int16_t val : 8;
    uint16_t op : 4;
    } ldiop __attribute__((packed));
    uint16_t raw;
    } __attribute__((packed));

    The attribute supresses padding.
    Data is then loaded form the binary file tinot the progemem progmem[address].raw = data; in the function void read_program_bin(FILE *file).

    The core procedure is basically a switch case instruction. Now my question is the following. It seems that the core function goes through every possible instruction using the struct as some kind of mask on the progmem array. But what i dont understand is, that the raw file is loaded into th progmem using up in our case 16 bit. But doesnt the union use up more than 16bit but 16 * all the structs inside? Or do i get something wrong? How do i know that e.g progmem[pc].imm7op.op and progmem[pc].imm5op.op are poiting to the same instrucion on the progmem?

    switch (progmem[pc].imm7op.op)
    case 0x06: /* CMPI_LT */
    cond = ((WORD_T)reg[progmem[pc].imm7op.reg] < (WORD_T)progmem[pc].imm7op.val);
    case 0x07: /* CMPI_GT */
    cond = ((WORD_T)reg[progmem[pc].imm7op.reg] > (WORD_T)progmem[pc].imm7op.val);
    case 0x17: /* CMPI_EQ */
    cond = ((WORD_T)reg[progmem[pc].imm7op.reg] == (WORD_T)progmem[pc].imm7op.val);
    default: decoder_check++;
    Attached Files Attached Files

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts