0

命令awが、次のように 32 ビット構造で定義されたコード 010 であるとします。

bits 31-25  unused (all 0s)
bits 24-22: code
bits 21-19: argument 1
bits 18-16: argument 2
bits 15-0:  offset (a 16-bit, 2's complement number with a range of -32768 to 32767)

番号が 8454151 の場合、コードがaw.

8454151 >> 22 のように 22 ビットをシフトしようとしましたが、0 になり続けawます。

4

2 に答える 2

2

命令が特定の操作であるかどうかを確認する必要がある場合、必要なサイクルが最も少ないコードは次のようになります。

const uint32_t mask = 7 << 22;    // Shift 3 set bits by 22 in order to build 
                                  // a mask where bits 22-24 are set.
const uint32_t inst_aw = 2 << 22; // Shift the opcode by 22 to build a comparable value

uint32_t instruction = ...;       // Your instruction word

if ((instruction & mask) == inst_aw) {
  // Do your thing
}

とにかく、「命令デコーダー」または「インタープリター」のようなものを構築する必要がある場合は、命令コードによってインデックス付けされた命令名 (または関数ポインター) を持つルックアップ テーブルを使用することをお勧めします。

/*! \brief Instruction names lookup table. Make sure it has always 8 entries 
           in order to avoid access beyond the array limits */
const char *instruction_names[] = {
  /* 000 */ "Unknown instruction 000",
  /* 001 */ "Unknown instruction 001",
  /* 010 */ "AW",
  ...
  /* 111 */ "Unknown instruction 111"
};


uint32_t instruction = ...;
unsigned int opcode = (instruction >> 22) & 0x07; // Retrieving the opcode by shifting right 22 
                                                  // times and mask out all bit except the last 3

printf("Instruction is: %s", instruction_names[opcode]);
于 2013-01-25T07:43:35.610 に答える
0

ビットシフトが機能するはずです。必ずデータ型を確認してください。数値と 0x01C000 を「AND」して比較することもできます。

于 2013-01-25T07:21:54.350 に答える