Lookup Table in C?
I'm writing a sort of assembler in C where it takes the asm code and generates a binary file. Since the instructions are 1:1 for actual binary code would using a lookup table be the best method for translating "add", "sub", "mov", etc to their binary equivalents? If statements seem slow and tedious.
If so, does anybody know any good resources? In perl/python obiviously the hash types made things easier...and yes I googled...
Aspiring College Developer
September 20th, 2006 10:47pm
...you could try posting to some kind of web forum...
worldsSmallestViolin
September 20th, 2006 10:59pm
If you want a hash type like perl python make one.
Init a big array.
Get Key, convert to number.
Put at that spot in the array.
September 20th, 2006 11:17pm
Why don't you use something based on strstr() and a switch statement? Gawd, are you stoopid or summat? :-) :-) :-)
bon vivant
September 20th, 2006 11:35pm
struct lookup_entry {
const char *instruction;
const unsigned int code;
};
struct lookup_entry lookup_table[] = {
{"add", 0x01},
{"mul", 0x02},
{"mov", 0x03},
...
{NULL, 0}
};
unsigned int lookup_instruction(const char*);
I'd write the lookup_instruction(const char*) function for you as well, but then I'd have to charge you a fat wad of cash.