1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
#include "opcodes.h"
#include "hash.h"
#include "optable.h"
OpcodeInfo opcodeTable[NOF_OPCODES] = {
{ "mov", OPCODE_MOV_MASK, 2 },
{ "or", OPCODE_OR, 2 },
{ "and", OPCODE_AND, 2 },
{ "sub", OPCODE_SUB, 2 },
{ "add", OPCODE_ADD, 2 },
{ "cmp", OPCODE_CMP, 2 },
{ "jmp", OPCODE_JMP | OPCODE_JMP_JMP, 1 },
{ "je", OPCODE_JMP | OPCODE_JMP_JE, 1 },
{ "jne", OPCODE_JMP | OPCODE_JMP_JNE, 1 },
{ "ja", OPCODE_JMP | OPCODE_JMP_JA, 1 },
{ "jae", OPCODE_JMP | OPCODE_JMP_JAE, 1 },
{ "jb", OPCODE_JMP | OPCODE_JMP_JB, 1 },
{ "jbe", OPCODE_JMP | OPCODE_JMP_JBE, 1 },
{ "jsr", OPCODE_JMP | OPCODE_JMP_JSR, 1 },
{ "not", OPCODE_NOT, 1 },
{ "push", OPCODE_STACK | OPCODE_STACK_PUSH, 1 },
{ "pop", OPCODE_STACK | OPCODE_STACK_POP, 1 },
{ "nop", OPCODE_NOP, 0 },
{ "hlt", OPCODE_HLT, 0 },
{ "ret", OPCODE_RET, 0 }
};
intHashTable opcode_ht;
void opcode_table_init( )
{
int i;
inthash_init( &opcode_ht, NOF_OPCODES );
for( i = 0; i < NOF_OPCODES; i++ ) {
inthash_set( &opcode_ht, opcodeTable[i].mnemonic, i );
}
}
void opcode_table_done( )
{
inthash_done( &opcode_ht );
}
OpcodeInfo *lookup_opcode( char *mnemonic )
{
int idx;
idx = inthash_get( &opcode_ht, mnemonic );
if( idx >= 0 ) {
return &opcodeTable[idx];
}
return 0;
}
|