|HLL expression -> ASM email@example.com (Alexei A. Frounze) (2001-03-26)|
|Re: HLL expression -> ASM firstname.lastname@example.org (Dan Bishop) (2001-03-27)|
|Re: HLL expression -> ASM email@example.com (Alexei A. Frounze) (2001-03-31)|
|Re: HLL expression -> ASM firstname.lastname@example.org (Ben L. Titzer) (2001-03-31)|
|Re: HLL expression -> ASM email@example.com (Randall Hyde) (2001-03-31)|
|Re: HLL expression -> ASM firstname.lastname@example.org (Marco van de Voort) (2001-04-04)|
|Re: HLL expression -> ASM email@example.com (Alexei A. Frounze) (2001-04-10)|
|Re: HLL expression -> ASM firstname.lastname@example.org (Bill A.) (2001-04-10)|
|[1 later articles]|
|From:||"Dan Bishop" <email@example.com>|
|Date:||27 Mar 2001 23:48:29 -0500|
|Organization:||Texas A&M University, College Station, Texas|
|Posted-Date:||27 Mar 2001 23:48:29 EST|
Here's a simple, but inefficient method:
Do a postorder transversal of the tree. When a value/variable is reached,
emit code to push it on to the CPU stack. For "operator" nodes, pop two
values from the stack, perform the operation, and push the result back onto
"Alexei A. Frounze" <firstname.lastname@example.org> wrote
> I know how to parse the source, how to evaluate expressions several
> similar ways: recursively or using stack(s). OK, that works perfectly,
> no problems. And I can create a tree for the expression as well.
> Now, how do I transform the tree/whatever (let's say only integer
> values/vars involved in the expression) into an ASM piece of code w/o
> consuming extra memory for partial results, just using CPU registers?
[If you pretend the registers are the stack and assign the "pushed"
values to registers, you can get code that's not bad considering how
easy this technique is. -John]
Return to the
Search the comp.compilers archives again.