home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power-Programmierung
/
CD1.mdf
/
forth
/
compiler
/
fpc
/
tutor
/
l6p080
< prev
next >
Wrap
Text File
|
1990-07-15
|
4KB
|
104 lines
╔════════════════════════════════════════════════════╗
║ Lesson 6 Part 080 F-PC 3.5 Tutorial by Jack Brown ║
╚════════════════════════════════════════════════════╝
┌─────────────────────────────────────────────┐
│ Re-definition of Number Display Operators │
└─────────────────────────────────────────────┘
\ A re-definition of Forths Number Display Operators using
\ our modified output formatting words which will allow us
\ to watch their normally transparent operation by setting
\ S&PAD ON .
\ Convert an unsigned 16 bit number to a string.
: (U.) ( un -- addr len )
0 <# #S #> ;
\ Output as an unsigned single number with trailing space.
: U. ( un -- )
(U.) ( addr len ) TYPE SPACE ;
\ Output as an unsigned single number right justified in a field
\ w wide.
: U.R ( un w -- )
>R (U.) ( addr len ) \ save w and convert.
R> OVER - ( addr len count ) \ count = # of leading spaces
SPACES TYPE ;
\ Convert a signed 16 bit number to a string.
: (.) ( n -- addr len )
DUP ABS 0
<# #S ROT SIGN #> ;
\ Output as a signed single number with a trailing space.
: . ( n -- )
(.) TYPE SPACE ;
\ .R Output as a signed single number right justified.
: .R ( n w -- )
>R (.) ( addr len ) \ save w and convert
R> OVER - ( addr len count ) \ count = # of leading spaces
SPACES TYPE ;
\ Convert an unsigned double number to a string.
: (UD.) ( ud -- addr len )
<# #S #> ;
\ Output as unsigned double number with a trailing space
: UD. ( ud -- )
(UD.) ( addr len ) TYPE SPACE ;
\ Output as an unsigned double number right justified in
\ a field w wide.
: UD.R ( ud w -- )
>R (UD.) ( addr len )
R> OVER - ( addr len count )
SPACES TYPE ;
\ Convert a signed double number to a string.
: (D.) ( dn -- addr len )
TUCK DABS ( sign |dn| )
<# #S ROT SIGN #> ( addr len ) ;
\ Output as a signed double number with a trailing space.
: D. ( dn -- )
(D.) ( addr len ) TYPE SPACE ;
\ Output as a signed double number right justified
\ in a field w wide.
: D.R ( dn w -- )
>R (D.) ( addr len )
R> OVER - ( addr len count )
SPACES TYPE ;
Now you can try the number display operators and watch see what is
happening as they run. For example:
HEX -123 . <enter>
[3] FEDD 123 0
7575 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
[3] FEDD 12 0
7575 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 33 3
[3] FEDD 1 0
7575 00 00 00 00 00 00 00 00 00 00 00 00 00 00 32 33 23
[3] FEDD 0 0
7575 00 00 00 00 00 00 00 00 00 00 00 00 00 31 32 33 123
[2] 0 0
7575 00 00 00 00 00 00 00 00 00 00 00 00 2D 31 32 33 -123
[2] 7581 4
7575 00 00 00 00 00 00 00 00 00 00 00 00 2D 31 32 33 -123 -123
What is happening above is that every time <# , # , #S , HOLD or #>
is executed we get a stack dump and dump of the area below our new PAD
You can follow along in the definition of . and (.) to check on how
they work. Remember that if you want to turn off this display of the
internals temporarily you just store a false flag in the variable S&PAD
S&PAD OFF \ No display
┌─────────────────────────────────────┐
│ Please Move to Lesson 6 Part 090 │
└─────────────────────────────────────┘