|RE: stack-based vs. register-based email@example.com (Scott J. McCaughrin) (2001-01-28)|
|Re: stack-based vs. register-based firstname.lastname@example.org (Scott Moore) (2001-02-01)|
|From:||Scott Moore <email@example.com>|
|Date:||1 Feb 2001 17:41:17 -0500|
|Organization:||Cisco Systems Inc.|
|Posted-Date:||01 Feb 2001 17:41:17 EST|
"Scott J. McCaughrin" wrote:
> The first complete Pascal compiler I wrote was targeted for a stack
> machine, and it was a real pain after having written phases of other
> compilers for non-stack targets.
> The biggest drawback is the 0-operand mode of the stack architecture
> vs. 2- or 3-operand mode with register operands. The LIFO nature of
> the stack leads to much larger code generated, even after optimiza-
> tion, than with registers.
> Yes, it is true that being stack-based frees you from the pitfalls
> of register-based code, but you also lose the advantages.
I have used a method (admittedly only once) that crossed the two on an
atom limited compilation scheme (no operands larger than a word or
register) for a CLI compiler.
Pick a register for the left accumulator. For unary operands, you
just operate on the accumulator (ie., negate, etc). For binary
operands, evaluate the left side, push that on the stack, then
evaluate right. Then pop the original left into a second register and
perform the operation (ie., a*b).
The scheme tends to perform stacking only when required, and does not
use inefficient stack operanded instructions. The disadvantage is it
does not make much use of more registers than 2. Also I have not
particularly thought much about extending it to non-atomic operands.
The simplicity of the scheme made it perfect for a CLI or one line
Of course, if you are willing to live with the atomic operands
limitation (even C can be compiled using only atoms) then forming a
real register allocation scheme is pretty trivial, like getreg,
PS. "Atom" as the term for single word operands is probally my own
Scott A. Moore is firstname.lastname@example.org
Return to the
Search the comp.compilers archives again.