extra stack operators
extra stack operators
on the OLPC wiki, there's NIP ( a b -- b ) and TUCK ( a b -- b a b ) and -ROT ( a b c -- c a b ) which I call LROT, but what is the word which has the stack diagram ( a b c -- b a c ) ? Is it UNDER?
- GARTHWILSON
- Forum Moderator
- Posts: 8775
- Joined: 30 Aug 2002
- Location: Southern California
- Contact:
Re: extra stack operators
I haven't heard of that or of LROT, but NIP, TUCK, and -ROT are pretty standard.
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?
- barrym95838
- Posts: 2056
- Joined: 30 Jun 2013
- Location: Sacramento, CA, USA
Re: extra stack operators
Ooh, may I try? (utter noob)
: UNDER >R SWAP R> ;
... or ...
: UNDER ROT SWAP ;
I don't know what to call it, but UNDER sounds as good as any, as long as that name isn't habitually used for something different.
Mike
: UNDER >R SWAP R> ;
... or ...
: UNDER ROT SWAP ;
I don't know what to call it, but UNDER sounds as good as any, as long as that name isn't habitually used for something different.
Mike
Re: extra stack operators
Mike,
Both of your definitions have the equivalent and proper stack effect ( a b c -- b a c ). I would choose the latter because it's two bytes shorter. In Brodie's "Thinking Forth" one of the things he says, to paraphrase badly from a book I read 30 years ago, "Naming the word properly is half the work of writing the word." In this case, it would be greatly preferred to write code that another Forth programmer would understand so I'm seeking the recognizable name for what I'm now calling UNDER.
I've really taken myself to school this past couple days, on the short bus. Stupid mistake after stupid mistake, violating principles that were once well known to me. I wrote this pretty short word (Copy) and then a monolithic word (Delete) and then a huge monolithic word (Paste) where everything fell apart with the line wrap table. Yes, that thing you suggested I dispense with entirely on the other thread. I'm keeping it in mostly because of the "nativeness" of it, and because of the long string literals. Today I did a fair amount of (literal) gardening and redesigned everything relating to copy/delete/paste into tiny reusable chunks of code. It's all headerless anyway, I don't know why I resisted this path. I see light at the end of the tunnel.
Update: I just learned on comp.lang.forth that UNDER is taken, and it does something else. It's probably not RSWAP either, which I'm pretty sure swaps two words on the return stack ( R: a b -- R: b a ).
: UNDER ( a b -- a a b ) >R DUP R> ;
Both of your definitions have the equivalent and proper stack effect ( a b c -- b a c ). I would choose the latter because it's two bytes shorter. In Brodie's "Thinking Forth" one of the things he says, to paraphrase badly from a book I read 30 years ago, "Naming the word properly is half the work of writing the word." In this case, it would be greatly preferred to write code that another Forth programmer would understand so I'm seeking the recognizable name for what I'm now calling UNDER.
I've really taken myself to school this past couple days, on the short bus. Stupid mistake after stupid mistake, violating principles that were once well known to me. I wrote this pretty short word (Copy) and then a monolithic word (Delete) and then a huge monolithic word (Paste) where everything fell apart with the line wrap table. Yes, that thing you suggested I dispense with entirely on the other thread. I'm keeping it in mostly because of the "nativeness" of it, and because of the long string literals. Today I did a fair amount of (literal) gardening and redesigned everything relating to copy/delete/paste into tiny reusable chunks of code. It's all headerless anyway, I don't know why I resisted this path. I see light at the end of the tunnel.
Update: I just learned on comp.lang.forth that UNDER is taken, and it does something else. It's probably not RSWAP either, which I'm pretty sure swaps two words on the return stack ( R: a b -- R: b a ).
: UNDER ( a b -- a a b ) >R DUP R> ;
- barrym95838
- Posts: 2056
- Joined: 30 Jun 2013
- Location: Sacramento, CA, USA
Re: extra stack operators
chitselb wrote:
... : UNDER ( a b -- a a b ) >R DUP R> ;
Using your criteria for compactness, we could successfully change this to
: UNDER ( a b -- a a b ) OVER SWAP ;
right? I'm sure that actual execution speed is a toss-up, since OVER and SWAP are probably more complex primitives than >R DUP and R>, but it's definitely a cell shorter, all else being equal. ROTSWAP would be most efficient as a primitive on my 'm32, with no ITC size penalty ... assuming that it would be used often enough to be preferred over ROT SWAP in a real program, which I have yet to write.
Code: Select all
UNDER: ; ( a b -- a a b )
.dw .+1
ldb 0,x
stb 0,-x
bra _next
ROTSWAP: ; ( a b c -- b a c )
.dw .+1
exa 0,x ; a c b
exa 1,x ; b c a
bra SWAP+1 ; b a c
SWAP: ; ( a b -- b a )
.dw .+1
exa 0,x
_next:
ldu 0,y+
jmp (0,u+)
Re: extra stack operators
Seems to me that it would be useful to have a stack manipulator word for every permutation of stack diagram, and these should have universally accepted names.
( a --
dup ( a -- a a )
?dup ( a -- a a | 0 )
drop ( a -- )
( a b --
over ( a b -- a b a )
swap ( a b -- b a )
under ( a b -- a a b )
nip ( a b -- b )
tuck ( a b -- b a b )
2dup ( a b -- a b a b )
( a b c --
rot ( a b c -- b c a )
FLIP ( a b c -- b a c )
-rot ( a b c -- c a b )
FLOP ( a b c -- c b a )
I'm going to call them FLIP and FLOP for now, until I find out what the names are supposed to be.
( a --
dup ( a -- a a )
?dup ( a -- a a | 0 )
drop ( a -- )
( a b --
over ( a b -- a b a )
swap ( a b -- b a )
under ( a b -- a a b )
nip ( a b -- b )
tuck ( a b -- b a b )
2dup ( a b -- a b a b )
( a b c --
rot ( a b c -- b c a )
FLIP ( a b c -- b a c )
-rot ( a b c -- c a b )
FLOP ( a b c -- c b a )
I'm going to call them FLIP and FLOP for now, until I find out what the names are supposed to be.
Re: extra stack operators
barrym95838 wrote:
Ooh, may I try? (utter noob)
: UNDER >R SWAP R> ;
... or ...
: UNDER ROT SWAP ;
I don't know what to call it, but UNDER sounds as good as any, as long as that name isn't habitually used for something different.
Mike
: UNDER >R SWAP R> ;
... or ...
: UNDER ROT SWAP ;
I don't know what to call it, but UNDER sounds as good as any, as long as that name isn't habitually used for something different.
Mike
- programandala.net
- Posts: 8
- Joined: 13 Dec 2015
- Location: Spain
- Contact:
Re: extra stack operators
barrym95838 wrote:
: UNDER ( a b -- a a b ) OVER SWAP ;
Marcos Cruz (programandala.net)
- programandala.net
- Posts: 8
- Joined: 13 Dec 2015
- Location: Spain
- Contact:
Re: extra stack operators
chitselb wrote:
Seems to me that it would be useful to have a stack manipulator word for every permutation of stack diagram, and these should have universally accepted names.
chitselb wrote:
FLIP ( a b c -- b a c )
FLOP ( a b c -- c b a )
I'm going to call them FLIP and FLOP for now, until I find out what the names are supposed to be.
FLOP ( a b c -- c b a )
I'm going to call them FLIP and FLOP for now, until I find out what the names are supposed to be.
Marcos Cruz (programandala.net)
Re: extra stack operators
programandala.net wrote:
I don't think it would be practical, even feasible. There are many different stack operations you can do, and most of them can be defined using others. The standard operations have names related to their functions, because the functions are simple.
That's the problem I just mentioned. It would be hard to remember not only which one is `flop` and which one is `flip`, but also what they actually do!
chitselb wrote:
FLIP ( a b c -- b a c )
FLOP ( a b c -- c b a )
I'm going to call them FLIP and FLOP for now, until I find out what the names are supposed to be.
FLOP ( a b c -- c b a )
I'm going to call them FLIP and FLOP for now, until I find out what the names are supposed to be.
- barrym95838
- Posts: 2056
- Joined: 30 Jun 2013
- Location: Sacramento, CA, USA
Re: extra stack operators
I would be tempted to name them bca, bac, cab, and cba, but I have a perverse affinity for three-letter mnemonics.
Mike B.
Mike B.
Re: extra stack operators
Mike, the TLM's you propose are valid hex numbers. Could get (a little too) interesting... 
In 1988 my 65C02 got six new registers and 44 new full-speed instructions!
https://laughtonelectronics.com/Arcana/ ... mmary.html
https://laughtonelectronics.com/Arcana/ ... mmary.html
- programandala.net
- Posts: 8
- Joined: 13 Dec 2015
- Location: Spain
- Contact:
Re: extra stack operators
nyef wrote:
Even within the standard, I have a hard time remembering which way round ROT goes. It seems like every time I need to use it, I either look it up or I do "1 2 3 ROT .S DROP 2DROP" to figure it out.
Marcos Cruz (programandala.net)
- barrym95838
- Posts: 2056
- Joined: 30 Jun 2013
- Location: Sacramento, CA, USA
Re: extra stack operators
Dr Jefyll wrote:
Mike, the TLM's you propose are valid hex numbers. Could get (a little too) interesting... 
: wxy drop ;
: yzz dup ;
: yzx rot ;
: yzy over ;
: zwx 2over ;
... meh, could cause brain damage in large quantities.
Mike B.
Re: extra stack operators
programandala.net wrote:
I don't think it would be practical, even feasible. There are many different stack operations you can do, and most of them can be defined using others. The standard operations have names related to their functions, because the functions are simple.
programandala.net wrote:
That's the problem I just mentioned. It would be hard to remember not only which one is `flop` and which one is `flip`, but also what they actually do!
"flip" would probably sound better as 3REVERSE. (I hope I didn't get "flip" and "flop" mixed up.