Skip to content

Commit

Permalink
Merge pull request #155 from TG9541/fix-pick
Browse files Browse the repository at this point in the history
fixes #154 PICK is off by one
  • Loading branch information
TG9541 authored Feb 8, 2018
2 parents c595536 + ff05793 commit 51a0fcb
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 4 deletions.
2 changes: 1 addition & 1 deletion forth.asm
Original file line number Diff line number Diff line change
Expand Up @@ -1988,6 +1988,7 @@ ZEQUAL:
HEADER PICK "PICK"
PICK:
CALLR DOXCODE
INCW X
SLAW X
ADDW X,YTEMP
LDW X,(X)
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/2OVER
Original file line number Diff line number Diff line change
@@ -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 ;
2 changes: 1 addition & 1 deletion lib/@inter
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 8 additions & 1 deletion lib/DSQRT
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand All @@ -19,3 +19,10 @@
THEN
UNTIL
;


\\ Example:

0 16 DSQRT .S \ 1024 <sp ok
0 1 DSQRT .S \ 256 <sp ok
16 0 DSQRT .S \ 4 <sp ok
10 changes: 10 additions & 0 deletions test/board.fs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@ T{e -11 5 .R e-> 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
Expand Down

0 comments on commit 51a0fcb

Please sign in to comment.