Hugh Aguilar wrote:
GaBuZoMeu wrote:
Well, exchanging stacked items without requiring auxiliary memory or registers would be easier...
I use direct,X for accessing the data-stack. Exchanging items on the stack needs Y available, but this is not a problem because Y is available:
Code:
SWAP: ; ( a b -- b a )
LDA toslo,X
LDY soslo,X
STA soslo,X
STY toslo,X
LDA toshi,X
LDY soshi,X
STA soshi,X
STY toshi,X
NEXT
Well, I've given some thought to GaBuZoMeu's suggestion and I think that I will upgrade EXA to support the direct,X addressing mode. When I do this, I get:
Code:
SWAP: ; ( a b -- b a )
LDA toslo,X
EXA soslo,X
STA toslo,X
LDA toshi,X
EXA soshi,X
STA toshi,X
NEXT
This is two instructions shorter, and SWAP is a very common Forth word, so this is worthwhile.
With ROT the difference is even greater:
Code:
ROT: ; ( a b c -- b c a ) ; without EXA
LDA toslo,X
LDY soslo,X
STA soslo,X
STY toslo,X
LDA toshi,X
LDY soshi,X
STA soshi,X
STY toshi,X ; -- a c b
LDA toslo,X
LDY roslo,X
STA roslo,X
STY toslo,X
LDA toshi,X
LDY roshi,X
STA roshi,X
STY toshi,X ; -- b c a
NEXT
ROT: ; ( a b c -- b c a ) ; with EXA
LDY toslo,X
LDA soslo,X
EXA roslo,X
STA toslo,X
STY soslo,X
LDY toshi,X
LDA soshi,X
EXA roshi,X
STA toshi,X
STY soshi,X
NEXT
I'll hold off on a new update on the document because this is a minor change. I may have some other changes to do.
This upgrade, adding the direct,X addressing mode to EXA, is Forth-centric --- I doubt that it would help C at all.
I would be interested adding instructions to help C compilers produce better code. I'm not familiar with C for the 65c02 however, so I don't know what would be helpful. Do any of you have experience with C on the 65c02, or are all of you only interested in assembly-language programming?