For languages, such as C, that allow functions to be treated like other kinds of data, functions for handling operands can be stored in the instruction table. Each instruction has the particular function that is needed for dealing with its operands stored in its instruction data entry. Often, there are different levels of granularity possible in the classification involved in a table-driven design. Code A portion of a simple example of table-driven design can be found in instructionTable. This example deals with code generation for a simple assembly language.
All operands are integer literals representing immediate values, addresses, or register numbers.
Since the information in the table is known in advance, the table is constructed as an initialized array. The correctness of this approach depends on putting the instruction mnemonics in alphabetical order. The instruction set for this example is simple enough that there are only four categories of instructions, based on the types of all operands for an instruction. For more complex instruction set, individual classification of operands may lead to better code organization. If this is done then the structs in the instruction data table contain one member for each operand in an instruction in addition to the instruction base code.