papierkorb:sample8.blk
Unterschiede
Hier werden die Unterschiede zwischen zwei Versionen angezeigt.
| papierkorb:sample8.blk [2025-08-16 17:50] – ↷ Seite von projects:sample8.blk nach papierkorb:sample8.blk verschoben mka | papierkorb:sample8.blk [Unbekanntes Datum] (aktuell) – gelöscht - Externe Bearbeitung (Unbekanntes Datum) 127.0.0.1 | ||
|---|---|---|---|
| Zeile 1: | Zeile 1: | ||
| - | === Examples for lecture number eight. === | ||
| - | < | ||
| - | Screen 0 not modified | ||
| - | 0 \ Examples for lecture number eight. | ||
| - | 1 \ Last change: | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | 10 | ||
| - | 11 | ||
| - | 12 | ||
| - | 13 | ||
| - | 14 | ||
| - | 15 | ||
| - | |||
| - | Screen 1 not modified | ||
| - | 0 \ Load screen. | ||
| - | 1 \ Typing | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | 10 | ||
| - | 11 7 9 THRU \ Load Number Format examples and Verify. | ||
| - | 12 16 18 THRU \ Load SPY | ||
| - | 13 | ||
| - | 14 ONLY FORTH ALSO EDITOR ALSO FORTH DEFINITIONS | ||
| - | 15 | ||
| - | |||
| - | |||
| - | Screen 2 not modified | ||
| - | 0 \ Review-1 Strings | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | 10 is later executed the address and count are returned. | ||
| - | 11 | ||
| - | 12 Examples: | ||
| - | 13 CREATE NAME$ ," George Smith" | ||
| - | 14 : JOB$ " FORTH Programmer" | ||
| - | 15 | ||
| - | |||
| - | |||
| - | Screen 3 not modified | ||
| - | 0 \ Review-2 COUNT TYPE EXPECT | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | 10 ERASE ( adr n | ||
| - | 11 | ||
| - | 12 | ||
| - | 13 Input a string of length n to buffer at adr . Actual number | ||
| - | 14 of characters entered is stored in a variable called SPAN. | ||
| - | 15 | ||
| - | |||
| - | |||
| - | Screen 4 not modified | ||
| - | 0 \ Review-3 Moving Strings. | ||
| - | | ||
| - | 2 CMOVE ( adrf adrt n -- ) Use when adrf > adrt | ||
| - | 3 Move n bytes from adrf to adrt. Left-most or low memory bytes | ||
| - | 4 are moved first. ( ie Move starts at beginning of string.) | ||
| - | 5 Use CMOVE to move strings down to lower memory. | ||
| - | | ||
| - | 7 CMOVE> | ||
| - | 8 Move n bytes from adrf to adrt. Right-most or high memory | ||
| - | 9 bytes are moved first. ( ie Move starts at end of string.) | ||
| - | 10 Use CMOVE> to move strings up to higher memory. | ||
| - | 11 | ||
| - | 12 MOVE ( adrf adrt n -- ) | ||
| - | 13 Move n bytes from adrf to adrt. If adrf < adrt use CMOVE> | ||
| - | 14 otherwise use CMOVE. | ||
| - | 15 Use MOVE when you can't remember whether to use CMOVE or CMOVE> | ||
| - | |||
| - | |||
| - | Screen 5 not modified | ||
| - | 0 \ Review-4 Strings | ||
| - | 1 \ Move a string at adrf and pack it at adrt with count n. | ||
| - | 2 : CPACK ( adrf adrt n -- ) | ||
| - | | ||
| - | | ||
| - | 5 \ Chopping n characters from the left of a string | ||
| - | 6 : CHOP ( adr count n adr' count' ) | ||
| - | | ||
| - | | ||
| - | 9 -TRAILING ( adr count1 | ||
| - | 10 | ||
| - | 11 \ CONVERT | ||
| - | 12 \ Convert a string at adr1+1 accumulating number into d1. | ||
| - | 13 \ Stops at first non digit character at addr2. | ||
| - | 14 \ the address of a counted or packed digit string. | ||
| - | 15 \ digit of the string will be at adr1+1 | ||
| - | |||
| - | |||
| - | Screen 6 not modified | ||
| - | 0 \ Review-5 Number formating | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | 10 used by <# but is usually present. | ||
| - | 11 # | ||
| - | 12 number BASE and remaining digits as dn' . | ||
| - | 13 # | ||
| - | 14 conversion is finished | ||
| - | 15 #> | ||
| - | |||
| - | |||
| - | Screen 7 not modified | ||
| - | 0 \ Number formating examples. | ||
| - | 1 \ Print single number as four digit hex and preserve system base | ||
| - | 2 : H. BASE @ >R 16 BASE ! | ||
| - | | ||
| - | | ||
| - | 5 \ Print 16-bit number as binary saving preserving current BASE. | ||
| - | 6 : B. BASE @ >R 2 BASE ! | ||
| - | | ||
| - | | ||
| - | 9 \ Print double number as signed dollars and cents. | ||
| - | 10 : $. ( dn -- ) | ||
| - | 11 TUCK DABS \ Save sign as third item. | ||
| - | 12 <# ROT SIGN | ||
| - | 13 | ||
| - | 14 # # ASCII . HOLD #S ASCII $ HOLD | ||
| - | 15 #> TYPE SPACE ; | ||
| - | |||
| - | |||
| - | Screen 8 not modified | ||
| - | 0 \ [IN] .ASCII | ||
| - | 1 \ Leave true flag if a <= x <= b . | ||
| - | 2 : [IN] ( x a b f ) 1+ -ROT 1- OVER < -ROT > AND ; | ||
| - | | ||
| - | 4 : .ASCII ( n -- ) \ EMIT n as printable ascii or a space. | ||
| - | | ||
| - | 6 \ Double space if i is equal to 8 . | ||
| - | 7 : ?SPACE ( i -- ) 8 = IF SPACE SPACE THEN ; | ||
| - | 8 \ Print byte right justified in field w wide. | ||
| - | 9 : .RBYTE ( n w -- ) | ||
| - | 10 >R 0 <# # # #> R> OVER - SPACES TYPE ; | ||
| - | 11 \ Based on address adr , display heading for VERIFY | ||
| - | 12 : HEAD ( adr -- ) | ||
| - | 13 CR 5 SPACES 16 0 DO I OVER + 255 AND | ||
| - | 14 I ?SPACE 3 .RBYTE LOOP | ||
| - | 15 2 SPACES 16 0 DO I OVER + 15 AND 1 .R LOOP DROP ; | ||
| - | |||
| - | |||
| - | Screen 9 not modified | ||
| - | 0 \ 1LINE VERIFY | ||
| - | 1 : 1LINE ( adr -- ) \ Verify 16 bytes from address. | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | 8 : VERIFY ( adr -- ) \ Only 32 bytes from adr with header. | ||
| - | | ||
| - | 10 DUP 1LINE DUP 16 + 1LINE HEAD CR BASE ! ; | ||
| - | 11 | ||
| - | 12 \ Dump out first 32 bytes of a word in the dictionary. | ||
| - | 13 : PEEK ' > | ||
| - | 14 \ Problem 1: Use HEAD and 1LINE to write a better memory | ||
| - | 15 \ DUMP utility. | ||
| - | |||
| - | |||
| - | Screen 10 not modified | ||
| - | 0 \ CASE ... OF ... ENDOF ... ENDCASE | ||
| - | 1 \ First look at sample7.blk | ||
| - | 2 \ CASE causes an index value to be compared to a series | ||
| - | 3 \ OF values. | ||
| - | 4 \ OF is equivalent to OVER = IF DROP | ||
| - | 5 \ ENDOF is equivalent to ELSE | ||
| - | 6 \ ENDCASE is equivalent of DROP and number of THENs | ||
| - | 7 \ When the index value equals one of the OF values, the sequence | ||
| - | 8 \ between that OF and the corresponding ENDOF is executed. | ||
| - | 9 \ Control then branches to the word following ENDCASE. | ||
| - | 10 \ If no match is found, | ||
| - | 11 | ||
| - | 12 \ The " | ||
| - | 13 \ between the last ENDOF and ENDCASE. | ||
| - | 14 \ however be preserved across this otherwise sequence so that | ||
| - | 15 \ ENDCASE | ||
| - | |||
| - | |||
| - | Screen 11 not modified | ||
| - | 0 \ Multi-way branching | ||
| - | 1 : TIS ( -- -- ) CR ." | ||
| - | 2 : TEST2 ( -- -- ) | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | 10 ASCII 6 OF | ||
| - | 11 ASCII 7 OF | ||
| - | 12 ASCII 8 OF | ||
| - | 13 ASCII 9 OF | ||
| - | 14 ASCII 0 OF | ||
| - | 15 | ||
| - | |||
| - | |||
| - | Screen 12 not modified | ||
| - | 0 \ Structure of a FORTH word definition. | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | 10 cfa -> | Addr Inner Interpr.| | ||
| - | 11 pfa -> | Parameter List | ||
| - | 12 | ||
| - | 13 | ||
| - | 14 | ||
| - | 15 | ||
| - | |||
| - | |||
| - | Screen 13 not modified | ||
| - | 0 \ View, Link, Name: Details | ||
| - | 1 View Field: | ||
| - | | ||
| - | 3 File # The File # set by the VIEWS comand is in the top | ||
| - | | ||
| - | 5 Block # Or screen # is in the low 12 bits of view field. | ||
| - | 6 Link Field: | ||
| - | | ||
| - | | ||
| - | 9 Name Field: | ||
| - | 10 | ||
| - | 11 | ||
| - | 12 0 4 Character count max is 31 | ||
| - | 13 Byte 2: 0char | ||
| - | 14 | ||
| - | 15 Last Byte : 1char 1 is delimiter. | ||
| - | |||
| - | |||
| - | Screen 14 not modified | ||
| - | 0 \ Code and Parameter fields | ||
| - | 1 Code Field : Contains pointer to ( ie address of ) the | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | 9 Parameter Field The contents of this field depends on the type | ||
| - | 10 of word. For single (16-bit) variables and | ||
| - | 11 and constants it contains their 16-bit value. | ||
| - | 12 For a colon definition it contains a list of | ||
| - | 13 the cfa's of the words that make up the colon | ||
| - | 14 | ||
| - | 15 the actual machine code for the word. | ||
| - | |||
| - | |||
| - | Screen 15 not modified | ||
| - | 0 \ Accessing a words fields. | ||
| - | | ||
| - | | ||
| - | | ||
| - | 4 > | ||
| - | 5 > | ||
| - | 6 > | ||
| - | 7 > | ||
| - | 8 VIEW> | ||
| - | 9 LINK> | ||
| - | 10 NAME> | ||
| - | 11 BODY> | ||
| - | 12 N> | ||
| - | 13 L> | ||
| - | 14 Hints: | ||
| - | 15 VIEW> | ||
| - | |||
| - | |||
| - | Screen 16 not modified | ||
| - | 0 \ SPY-VFA | ||
| - | 1 \ Display contents of field in both binary and hex. | ||
| - | 2 : .RAW ( adr -- ) | ||
| - | | ||
| - | 4 : SPY-VFA | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | 10 | ||
| - | 11 > | ||
| - | 12 ELSE ." May be in current file: " | ||
| - | 13 | ||
| - | 14 THEN ." Screen # " . \ Display screen number. | ||
| - | 15 ELSE 2DROP ." Entered at the terminal." | ||
| - | |||
| - | |||
| - | Screen 17 not modified | ||
| - | 0 \ SPY-LFA | ||
| - | | ||
| - | 2 : SPY-LFA ( cfa -- ) | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | 8 : SPY-NFA ( cfa -- ) | ||
| - | | ||
| - | 10 > | ||
| - | 11 DUP C@ 64 AND CR 11 SPACES ." Precedence bit is " | ||
| - | 12 IF " on." ELSE ." off." THEN | ||
| - | 13 DUP C@ 32 AND ." | ||
| - | 14 IF " on." ELSE ." off." THEN | ||
| - | 15 C@ 31 AND | ||
| - | |||
| - | |||
| - | Screen 18 not modified | ||
| - | 0 \ SYP-CFA | ||
| - | | ||
| - | 2 : SPY-CFA ( cfa -- ) | ||
| - | | ||
| - | | ||
| - | 5 : SPY-PFA ( cfa -- ) | ||
| - | | ||
| - | | ||
| - | 8 : SPY ( -- -- ) | ||
| - | | ||
| - | 10 | ||
| - | 11 | ||
| - | 12 | ||
| - | 13 | ||
| - | 14 | ||
| - | 15 | ||
| - | |||
| - | |||
| - | Screen 19 not modified | ||
| - | 0 \ The Smudge bit and the Precedence | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | 10 when it is encountered at compile time, it is executed rather | ||
| - | 11 than compiled. | ||
| - | 12 ['] {word} This is an IMMEDIATE word used within a definition. | ||
| - | 13 It used to compile the cfa of the following word as a | ||
| - | 14 | ||
| - | 15 [ ' {word} ] LITERAL | ||
| - | |||
| - | |||
| - | Screen 20 not modified | ||
| - | 0 \ DP HERE CURRENT #VOC CONTEXT | ||
| - | 1 DP ( -- adr ) | ||
| - | | ||
| - | 3 HERE ( -- adr ) | ||
| - | | ||
| - | 5 CURRENT ( -- adr ) | ||
| - | | ||
| - | | ||
| - | 8 #VOCS ( -- n | ||
| - | | ||
| - | 10 the search order. | ||
| - | 11 CONTEXT ( -- adr ) | ||
| - | 12 array space that holds the 8=# | ||
| - | 13 | ||
| - | 14 The CONTEXT array specifies the search | ||
| - | 15 order for the text interpreter. | ||
| - | |||
| - | |||
| - | Screen 21 not modified | ||
| - | 0 \ ORDER VOC-LINK | ||
| - | 1 ORDER ( -- -- ) Display the vocabulary names forming the | ||
| - | | ||
| - | | ||
| - | | ||
| - | 5 VOC-LINK | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | 10 VOCS ( -- -- ) List all vocabularies that exist in this | ||
| - | 11 FORTH system. | ||
| - | 12 DEFINITIONS ( -- -- ) Select the transient vocabulary ( first | ||
| - | 13 in the context array) as the compilation | ||
| - | 14 | ||
| - | 15 new word definitions will be added. | ||
| - | |||
| - | |||
| - | Screen 22 not modified | ||
| - | 0 \ VOCABULARY | ||
| - | | ||
| - | 2 VOCABULARY | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | 9 ALSO ( -- -- ) | ||
| - | 10 Push transient vocabulary making it the first resident | ||
| - | 11 vocabulary in the search order. | ||
| - | 12 | ||
| - | 13 PREVIOUS ( -- -- ) | ||
| - | 14 The inverse of ALSO, removes the most recently referenced | ||
| - | 15 vocabulary from the search order. | ||
| - | |||
| - | |||
| - | Screen 23 not modified | ||
| - | 0 \ ROOT ONLY SEAL | ||
| - | | ||
| - | 2 ROOT ( -- -- ) | ||
| - | | ||
| - | | ||
| - | 5 ONLY ( -- -- ) | ||
| - | | ||
| - | | ||
| - | | ||
| - | 9 SEAL ( -- -- ) | ||
| - | 10 Usage: SEAL FORTH will change the search order such that | ||
| - | 11 only FORTH will be searched. Used for turn-key applications. | ||
| - | 12 | ||
| - | 13 | ||
| - | 14 | ||
| - | 15 | ||
| - | |||
| - | |||
| - | Screen 24 not modified | ||
| - | 0 \ 17: | ||
| - | 1 ONLY FORTH ALSO DEFINITIONS | ||
| - | 2 VOCABULARY SOUND CR .( VOCS ) VOCS CR | ||
| - | 3 ROOT DEFINITIONS | ||
| - | 4 SOUND DEFINITIONS | ||
| - | | ||
| - | 6 \ PC! ( byte n | ||
| - | 7 \ PC@ ( n byte ) Input byte from port number n. | ||
| - | | ||
| - | 9 : | ||
| - | 10 61 PC@ | ||
| - | 11 | ||
| - | 12 | ||
| - | 13 : S.OFF ( -- -- ) \ Turn speaker off. | ||
| - | 14 61 PC@ | ||
| - | 15 FFFC AND 61 PC! ; DECIMAL | ||
| - | |||
| - | |||
| - | Screen 25 not modified | ||
| - | 0 \ TONE | ||
| - | | ||
| - | | ||
| - | 3 : TONE ( freq -- ) \ Make tone of specified frequency. | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | 10 42 PC! 42 PC! \ Store low and high byte in timer. | ||
| - | 11 S.ON ; DECIMAL | ||
| - | 12 | ||
| - | 13 | ||
| - | 14 | ||
| - | 15 | ||
| - | |||
| - | |||
| - | Screen 26 not modified | ||
| - | 0 \ SCALE 17: | ||
| - | | ||
| - | 2 : C 131 TONE ; | ||
| - | 3 : D 147 TONE ; | ||
| - | 4 : E 165 TONE ; | ||
| - | 5 : F 175 TONE ; | ||
| - | 6 : G 196 TONE ; | ||
| - | 7 : A 220 TONE ; | ||
| - | 8 : B 247 TONE ; | ||
| - | 9 : CC 262 TONE ; | ||
| - | 10 | ||
| - | 11 : BEAT 20000 0 DO LOOP ; | ||
| - | 12 | ||
| - | 13 : SCALE C BEAT D BEAT E BEAT F BEAT G BEAT | ||
| - | 14 A BEAT B BEAT CC BEAT BEAT BEAT S.OFF ; | ||
| - | 15 | ||
| - | |||
| - | |||
| - | Screen 27 not modified | ||
| - | 0 \ Recursive Factorial Function. | ||
| - | | ||
| - | 2 : FACTORIAL | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | 8 \ RECURSIVE | ||
| - | | ||
| - | 10 : FACTORIAL | ||
| - | 11 CR ." entering factorial" | ||
| - | 12 DUP 0> IF DUP 1- FACTORIAL | ||
| - | 13 ELSE DROP 1 | ||
| - | 14 THEN CR ." leaving | ||
| - | 15 | ||
| - | |||
| - | |||
| - | Screen 28 not modified | ||
| - | 0 \ 22: | ||
| - | 1 : 2** ( n 2**n ) RECURSIVE | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | 7 : FIBONACCI ( n fib ) RECURSIVE | ||
| - | | ||
| - | | ||
| - | 10 | ||
| - | 11 SWAP 2- FIBONACCI | ||
| - | 12 | ||
| - | 13 | ||
| - | 14 \ : MYSELF | ||
| - | 15 \ : RECURSE | ||
| - | |||
| - | |||
| - | Screen 29 not modified | ||
| - | 0 \ Stack Bubble Sort 12: | ||
| - | | ||
| - | 2 \ Recursive bubble sort | ||
| - | 3 : BUBBLE | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | 10 | ||
| - | 11 : SORT ( n n n n ... m m m m ... sorted ) | ||
| - | 12 DEPTH 1 > IF | ||
| - | 13 DEPTH 1- 0 DO BUBBLE | ||
| - | 14 | ||
| - | 15 | ||
| - | |||
| - | |||
| - | Screen 30 not modified | ||
| - | 0 \ Stack Bubble Sort 12: | ||
| - | | ||
| - | 2 : ASCENDING | ||
| - | 3 : COMPARE | ||
| - | | ||
| - | 5 : BUBBLE | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | 10 | ||
| - | 11 | ||
| - | 12 | ||
| - | 13 : SORT ( n n n n ... m m m m ... sorted ) | ||
| - | 14 DEPTH 1 > IF | ||
| - | 15 DEPTH 1- 0 DO BUBBLE | ||
| - | |||
| - | |||
| - | Screen 31 not modified | ||
| - | 0 \ Multi-way branching IF .. ELSE .. THEN | ||
| - | 1 : TIS ( -- -- ) CR ." | ||
| - | 2 : TEST1 ( -- -- ) | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | 10 ASCII 7 OVER = IF DROP TIS ." SEVEN " | ||
| - | 11 ASCII 8 OVER = IF DROP TIS ." EIGHT " | ||
| - | 12 ASCII 9 OVER = IF DROP TIS ." NINE " | ||
| - | 13 ASCII 0 OVER = IF DROP TIS ." ZERO " | ||
| - | 14 BEEP DROP THEN THEN THEN THEN THEN | ||
| - | 15 | ||
| - | |||
| - | |||
| - | </ | ||
papierkorb/sample8.blk.1755359401.txt.gz · Zuletzt geändert: 2025-08-16 17:50 von mka