From ff05793342e2c0307a7f2335ac22e6dc519c7f55 Mon Sep 17 00:00:00 2001 From: Thomas Date: Thu, 8 Feb 2018 23:09:12 +0100 Subject: [PATCH] fixes #154 PICK is off by one --- forth.asm | 2 +- lib/2OVER | 2 +- lib/@inter | 2 +- lib/DSQRT | 9 ++++++++- test/board.fs | 10 ++++++++++ 5 files changed, 21 insertions(+), 4 deletions(-) diff --git a/forth.asm b/forth.asm index c678cf1..49d417f 100644 --- a/forth.asm +++ b/forth.asm @@ -1988,6 +1988,7 @@ ZEQUAL: HEADER PICK "PICK" PICK: CALLR DOXCODE + INCW X SLAW X ADDW X,YTEMP LDW X,(X) @@ -3997,7 +3998,6 @@ DOTS: CALL TOR ; start count down loop JRA DOTS2 ; skip first pass DOTS1: CALL RAT - CALL ONEP CALL PICK CALL DOT ; index stack, display contents DOTS2: CALL DONXT diff --git a/lib/2OVER b/lib/2OVER index 6ffd268..20d1542 100644 --- a/lib/2OVER +++ b/lib/2OVER @@ -1,4 +1,4 @@ \ STM8 eForth 2OVER double utility word TG9541 \ refer to github.com/TG9541/stm8ef/blob/master/LICENSE.md -: 2OVER ( d1 d2 -- d1 d2 d1 ) [ $AD00 , ( CALLR 0 ) ] 4 PICK ; +: 2OVER ( d1 d2 -- d1 d2 d1 ) [ $AD00 , ( CALLR 0 ) ] 3 PICK ; diff --git a/lib/@inter b/lib/@inter index 6508e9b..0ff2b79 100644 --- a/lib/@inter +++ b/lib/@inter @@ -14,7 +14,7 @@ : @inter ( n a -- n ) \ compile time: consumes xt of 2cell+ and @dif DUP @ 1- >R 2+ DUP BEGIN - 3 PICK OVER @ < NOT WHILE NIP [ ROT ( 2cell+ ) CALL, ] NEXT + 2 PICK OVER @ < NOT WHILE NIP [ ROT ( 2cell+ ) CALL, ] NEXT DROP DUP ELSE R> DROP THEN OVER = IF diff --git a/lib/DSQRT b/lib/DSQRT index 8eb4a23..88fdfea 100644 --- a/lib/DSQRT +++ b/lib/DSQRT @@ -7,7 +7,7 @@ $8000 ( d c ) $8000 ( d c g ) BEGIN DUP DUP UM* ( d c g g^2) - 6 PICK 6 PICK ( d c g g^2 d ) + 5 PICK 5 PICK ( d c g g^2 d ) D> IF ( d c g ) OVER XOR THEN ( d c g ) @@ -19,3 +19,10 @@ THEN UNTIL ; + + +\\ Example: + +0 16 DSQRT .S \ 1024 5 207 }T T{e -11 4 U.R e-> 5 263 }T T{e 11 4 U.R e-> 4 162 }T +\ core: stack manipulation +T{ 1 2 OVER -> 1 2 1 }T +T{ 1 2 SWAP -> 2 1 }T +T{ 1 2 3 ROT -> 2 3 1 }T +T{ 1 2 3 NIP -> 1 3 }T +T{ 1 2 3 0 PICK -> 1 2 3 3 }T +T{ 1 2 3 2 PICK -> 1 2 3 1 }T +T{ 1 2 2DUP -> 1 2 1 2 }T +T{ 1 2 3 4 2DROP -> 1 2 }T + \ core: compare operations T{ 10 -500 = -> 0 }T T{ -500 -500 = -> -1 }T