Normally, when an assembler assembles a file, it parses the file, and then uses tables and such to decide how to translate it to assembly.
What I've been thinking of doing is using a form of a context free language that then assebles the code based upon how it evaluates. eg.
Code: Select all
(reg "EAX" 1)
(reg "AX" 1)
(reg "AL" 1)
(reg "AH" 4)
(modrm m16 (0x06 a))
(modrm reg16 (bin (0x18 5) ((reg a) 3)))
(instr "AAA" 0x37)
(instr "ADD" "AL" imm8 (0x04 a))
(instr "ADD" rm16 imm16 (0x81 (modrm a) b))
The lispy-code could be compiled into bytecode, which could be called from the main assembler. eg.
Code: Select all
char *assembled_code = eval_cfg(cfl_vm, "instr", line);
Because of the overloading of the definitions, when called, eval_cfg would simply evaluate the given string, and return the result.
What do you think? Have I lost my mind?
Alboin