Home of the Muppet Imperial Moderator Corps

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...
Permalink Aspiring College Developer 
September 20th, 2006 10:47pm
...you could try posting to some kind of web forum...
Permalink 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.
Permalink  
September 20th, 2006 11:17pm
Why don't you use something based on strstr() and a switch statement? Gawd, are you stoopid or summat? :-) :-) :-)
Permalink Send private email 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*);
Permalink Send private email Clay Dowling 
September 21st, 2006 9:24am
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.
Permalink Send private email Clay Dowling 
September 21st, 2006 9:26am

This topic is archived. No further replies will be accepted.

Other topics: September, 2006 Other topics: September, 2006 Recent topics Recent topics