How many transistors in the 6502 processor?

From: Gunther Schadow <gunther_at_aurora.regenstrief.org>
Date: Tue May 22 23:00:52 2001

Cameron Kaiser wrote:
>
> > >FWIW, the later 65CE02 deals with both these issues. You can "move" zero
> > page
> > >anywhere in memory you want on the fly (so that you can pick a memory
> > page
> > >and optimize access to it), and the stack pointer is now 16-bit. The
> > 65CE02's
> > >most well-known usage was in its guise as the CSG 4510 in the mythical
> > >Commodore 65 (see
> >
> >
> > Yes but can you push parameters onto the stack prior to the call?
>
> Not without some trickery. You'd have to pull two bytes (the return address),
> pull the parameters, and then push the return address back on. Works but
> kludgy. No improvement here over the vanilla 6502.

I see, the 6502 draws a LOT of attention, mine too ... may be too
late? Anyhow, having just revived my memories with a C=64 from ebay
and looking into LUnix for it :-) I've been thinking about how to
make stack frames on the 6502. Clearly with a stack between $0100
and $01ff it is a bit tight. But, if the 65CE02 should have a 16
bit SP, what should be the problem with putting arguments on the
stack? Why do you need to move the return address? You don't pull
the arguments, you LDA them! That's what the TSX opcode must be
for after all, the X register acting as some sort of base pointer!

caller: LDA argN
        PHA
        ...
        LDA arg1
        PHA
        JSR callee
        TSX
        INX N
        TXS

callee: TSX
        LDA $0101+1,X ; for arg1
        ...
        LDA $0101+N,X ; for argN
        ...
        RTS

See, no PLA involved at all. In fact as I remember the PHA and
PLA opcodes where among the most cycle expensive you could have.
So, one could even speed up the argument placement:

caller: TSX
        DEX N
        TXS
        LDA arg1
        STA $00FF+1,X
        ...
        LDA argN
        STA $00FF+N,X
        JSR callee
        TSX
        INX N
        TXS

Just to challenge the 8-bit SP a little, let's put local variables
onto the stack :-)

callee: TSX
        DEX M ; reserve space for M local variables
        TXS
        LDA $00FF+1,X ; for loc1
        ...
        LDA $00FF+M,X ; for locM
        ...
        LDA $0101+M+1,X; for arg1
        ...
        LDA $0101+M+N,X; for argN
        ...
        TSX
        INX M
        TXS
        RTS

Now we just need some frame-pointer mechainsm on the zero page and we
can do everything the ix86 can do :-)

It took me so many years to find out why the TSX makes sense :-)

regards
-Gunther

-- 
Gunther Schadow, M.D., Ph.D.                    gschadow_at_regenstrief.org
Medical Information Scientist      Regenstrief Institute for Health Care
Adjunct Assistent Professor        Indiana University School of Medicine
tel:1(317)630-7960                         http://aurora.regenstrief.org
Received on Tue May 22 2001 - 23:00:52 BST

This archive was generated by hypermail 2.3.0 : Fri Oct 10 2014 - 23:34:09 BST