code generation templates for script language compiling
hello all. I have been reading a few tutorials and papers on compiler design. I have found the use of templates for machine code generation from AST nodes very nice as an idea. However, I saw a paper that stored all expressions result in the %eax register. That confused me a bit, because I read that you cannot rely on that the registers will keep their values (with the exception of EBP) during calculations. For example, the suggested code template for an addition expression ( expr '+' expr ) was the following: 1. evaluate l-hand expression and store result in eax. 2. %movl %eax, %ebx 3. evaluate r-hand expression and store result in eax 4. %addl %eax, %ebx That works if both expressions are primary expressions. If however the first expression is another addition (or any other calculation), you cannot assume that the %ebx register will keep its value. Suppose I am writing a scripting language compiler for a virtual machine. Should I use the stack for intermediate expressions results, besides parameters and local variables? Is that bad practice, or it just slows down calculation? My knowledge on assembly programming is very poor; actually, I 've never written assembly code; my experience is limited on the tutorials I've read.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement