papierkorb:sample2.blk
Unterschiede
Hier werden die Unterschiede zwischen zwei Versionen angezeigt.
| papierkorb:sample2.blk [2025-08-16 17:50] – ↷ Seite von projects:sample2.blk nach papierkorb:sample2.blk verschoben mka | papierkorb:sample2.blk [Unbekanntes Datum] (aktuell) – gelöscht - Externe Bearbeitung (Unbekanntes Datum) 127.0.0.1 | ||
|---|---|---|---|
| Zeile 1: | Zeile 1: | ||
| - | === EXAMPLES FOR LECTURE #2 === | ||
| - | < | ||
| - | Screen 0 not modified | ||
| - | 0 \ EXAMPLES FOR LECTURE #2 17: | ||
| - | 1 \ Last change: | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | 10 | ||
| - | 11 | ||
| - | 12 | ||
| - | 13 | ||
| - | 14 | ||
| - | 15 | ||
| - | |||
| - | |||
| - | Screen 1 not modified | ||
| - | 0 \ REVIEW - 1 | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | 10 | ||
| - | 11 ( dictionary. < | ||
| - | 12 ( printed when word is executed. ) | ||
| - | 13 ( Do not use outside a colon def.) | ||
| - | 14 | ||
| - | 15 ( outside a colon definition. | ||
| - | |||
| - | |||
| - | Screen 2 not modified | ||
| - | 0 \ REVIEW - 2 | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | 10 | ||
| - | 11 | ||
| - | 12 | ||
| - | 13 | ||
| - | 14 | ||
| - | 15 | ||
| - | |||
| - | |||
| - | Screen 3 not modified | ||
| - | 0 \ REVIEW - 3 | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | 10 | ||
| - | 11 | ||
| - | 12 | ||
| - | 13 N L ( -- -- ) ( List the next screen. ) | ||
| - | 14 B L ( -- -- ) ( List the previous screen.) | ||
| - | 15 | ||
| - | |||
| - | |||
| - | Screen 4 not modified | ||
| - | 0 \ REVIEW - 4 | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | 5 \ Create a new screen file < | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | 10 | ||
| - | 11 ( word.) | ||
| - | 12 | ||
| - | 13 | ||
| - | 14 | ||
| - | 15 ( current screen file.) | ||
| - | |||
| - | |||
| - | Screen 5 not modified | ||
| - | 0 \ EXAMPLES -1 09: | ||
| - | 1 \ Clear the data (or parameter stack). | ||
| - | 2 : CLEAR ( ?? empty ) | ||
| - | | ||
| - | | ||
| - | 5 \ Count from 0 to n . | ||
| - | 6 : COUNT_UP | ||
| - | | ||
| - | | ||
| - | | ||
| - | 10 LOOP ; | ||
| - | 11 | ||
| - | 12 | ||
| - | 13 | ||
| - | 14 | ||
| - | 15 | ||
| - | |||
| - | |||
| - | Screen 6 not modified | ||
| - | 0 \ DEBUGGER | ||
| - | 1 The debugger is designed to let the user single step through | ||
| - | 2 the execution sequence of a high level definition. This process | ||
| - | 3 is also called tracing. | ||
| - | | ||
| - | | ||
| - | | ||
| - | 7 where < | ||
| - | 8 word < | ||
| - | 9 showing the next word to be executed and the contents of the | ||
| - | 10 data stack. Press any key except C F or Q for the next step. | ||
| - | 11 | ||
| - | 12 | ||
| - | 13 | ||
| - | 14 | ||
| - | 15 UNBUG - Disconect the debugger or you may crash and burn. | ||
| - | |||
| - | |||
| - | Screen 7 not modified | ||
| - | 0 \ NEW WORDS | ||
| - | 1 \ You add the stack comments and descriptions. | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | 10 | ||
| - | 11 | ||
| - | 12 | ||
| - | 13 | ||
| - | 14 | ||
| - | 15 | ||
| - | |||
| - | |||
| - | Screen 8 not modified | ||
| - | 0 \ EXAMPLE - 2 Volume of a tank. | ||
| - | | ||
| - | 2 : TANK_VOLUME | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | 8 \ Explain | ||
| - | 9 \ Show the effect of an incomplete definition. | ||
| - | 10 \ More New Words Below. | ||
| - | 11 \ HIDE ( -- -- ) Mark last word so it cannot be found. | ||
| - | 12 \ REVEAL ( -- -- ) Mark last word so it can be found. | ||
| - | 13 \ [ Stop compiling and resume interpretation. | ||
| - | 14 \ ] Stop interpreting and resume compilation. | ||
| - | 15 | ||
| - | |||
| - | |||
| - | Screen 9 not modified | ||
| - | 0 \ EXAMPLE - 3 Volume of a tank factored. | ||
| - | | ||
| - | 2 : .ECHO ( a b c b c a ) | ||
| - | | ||
| - | | ||
| - | 5 : .FT ( -- -- ) | ||
| - | | ||
| - | | ||
| - | 8 : TANK_VOLUME | ||
| - | | ||
| - | 10 | ||
| - | 11 | ||
| - | 12 * | ||
| - | 13 | ||
| - | 14 | ||
| - | 15 | ||
| - | |||
| - | |||
| - | Screen 10 not modified | ||
| - | 0 \ EXAMPLE - 4 Surface area of closed tank | ||
| - | 1 \ New Words I made up the ones below | ||
| - | 2 \ | ||
| - | 3 \ | ||
| - | 4 \ | ||
| - | 5 \ | ||
| - | 6 \ | ||
| - | | ||
| - | 8 : TANK_AREA | ||
| - | | ||
| - | 10 5 ROLL * 2 * | ||
| - | 11 | ||
| - | 12 | ||
| - | 13 -ROT * 2 * | ||
| - | 14 | ||
| - | 15 | ||
| - | |||
| - | |||
| - | Screen 11 not modified | ||
| - | 0 \ PROBLEM - 1 | ||
| - | | ||
| - | 2 a) Write a word called | ||
| - | | ||
| - | | ||
| - | 5 b) Write a word called AREA that takes two stack items, a | ||
| - | | ||
| - | | ||
| - | 8 c) Write a word call PERIMETER that takes two stack items, a | ||
| - | | ||
| - | 10 of a rectangle. | ||
| - | 11 d) Write a word called RECTANGLE that takes two stack items, a | ||
| - | 12 length and a width, and performs the functions of a b & c . | ||
| - | 13 Did you use the .LW , AREA , and PERIMETER in your | ||
| - | 14 definition of RECTANGLE? | ||
| - | 15 ** It would be better to say: it consumes its stack parameters. | ||
| - | |||
| - | |||
| - | Screen 12 not modified | ||
| - | 0 \ PROBLEW-2 Tank volume and surface area | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | 10 | ||
| - | 11 | ||
| - | 12 | ||
| - | 13 | ||
| - | 14 | ||
| - | 15 | ||
| - | |||
| - | |||
| - | Screen 13 not modified | ||
| - | 0 \ PROBLEM - 3 | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | 10 Do your words work if you feed them upper left and lower | ||
| - | 11 right coordinates? | ||
| - | 12 | ||
| - | 13 | ||
| - | 14 | ||
| - | 15 | ||
| - | |||
| - | |||
| - | Screen 14 not modified | ||
| - | 0 \ PROBLEM - 4 Falling objects. | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | 10 You type: 1000 100 3 HEIGHT | ||
| - | 11 And see : | ||
| - | 12 | ||
| - | 13 | ||
| - | 14 Does your solution consist of one long definition? | ||
| - | 15 ( the 412 above may be wong!! ) | ||
| - | |||
| - | |||
| - | Screen 15 not modified | ||
| - | 0 \ DIVISION | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | 10 * 2 / ; | ||
| - | 11 | ||
| - | 12 | ||
| - | 13 | ||
| - | 14 | ||
| - | 15 | ||
| - | |||
| - | |||
| - | Screen 16 not modified | ||
| - | 0 \ EASY WORDS | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | 10 | ||
| - | 11 | ||
| - | 12 | ||
| - | 13 | ||
| - | 14 | ||
| - | 15 | ||
| - | |||
| - | |||
| - | Screen 17 not modified | ||
| - | 0 \ DISPLAYING A TABLE contains error!!! | ||
| - | 1 \ New word: .R ( n w -- ) | ||
| - | 2 \ | ||
| - | 3 : .ONE ( n -- ) | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | 8 : .HEADING | ||
| - | | ||
| - | 10 ." NUMBER | ||
| - | 11 : .TABLE | ||
| - | 12 | ||
| - | 13 1+ SWAP | ||
| - | 14 ?DO CR I .ONE LOOP | ||
| - | 15 CR CR ; | ||
| - | |||
| - | |||
| - | Screen 18 not modified | ||
| - | 0 \ PROBLEM - 5 | ||
| - | 1 a)Modify the previous example so that it gives a table of | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | 9 b)Repeat the above problem for spherical tanks. | ||
| - | 10 | ||
| - | 11 For a sphere | ||
| - | 12 S = 4 pi R*R | ||
| - | 13 pi = 3.1416 | ||
| - | 14 | ||
| - | 15 : *PI ( n n*pi ) 355 113 */ ; | ||
| - | |||
| - | |||
| - | Screen 19 not modified | ||
| - | 0 \ ASCII TABLE | ||
| - | 1 : .ONE ( n -- ) | ||
| - | | ||
| - | | ||
| - | 4 : .HEADING | ||
| - | | ||
| - | 6 : ATABLE | ||
| - | | ||
| - | | ||
| - | | ||
| - | 10 ?DO CR I .ONE LOOP ; | ||
| - | 11 : .TABLE | ||
| - | 12 16 0 DO I 16 * DUP 15 + | ||
| - | 13 ATABLE | ||
| - | 14 LOOP ; | ||
| - | 15 | ||
| - | |||
| - | |||
| - | Screen 20 not modified | ||
| - | 0 \ Notes on Starting Forth. 1 | ||
| - | 1 \ P 50 Replace 'S with SP@ or define | ||
| - | 2 \ | ||
| - | 3 \ Because FORTH83 loops work differently you should use: | ||
| - | | ||
| - | | ||
| - | | ||
| - | 7 \ Or just use .S that is already part of your system. | ||
| - | | ||
| - | 9 \ P 66-72 Use: n VEDIT to edit screen n . | ||
| - | 10 \ The original F83.COM fill supports the STARTING FORTH style | ||
| - | 11 \ editor. | ||
| - | 12 \ P 83 See notes for P 50 above. | ||
| - | 13 \ the F83 version is implemented. | ||
| - | 14 | ||
| - | 15 | ||
| - | |||
| - | |||
| - | Screen 21 not modified | ||
| - | 0 \ Notes on Starting Forth. 2 | ||
| - | 1 \ P 110 In F83 I J and K are used only within loops to fetch | ||
| - | 2 \ the current values of the loop counters. | ||
| - | 3 \ | ||
| - | 4 \ stack to the parameter stack without changing the | ||
| - | 5 \ | ||
| - | 6 \ Use the sequence: | ||
| - | 7 \ | ||
| - | 8 \ the return stack. | ||
| - | 9 : 2R@ R> R> R@ -ROT >R >R ; | ||
| - | 10 \ Use 2R@ for I' . | ||
| - | 11 \ | ||
| - | 12 \ P112 Use R@ instead of I , also a dot . was ommited | ||
| - | 13 \ from the definition of QUADRATIC. | ||
| - | 14 : QUADRATIC | ||
| - | 15 >R SWAP ROT R@ * + R> * + . ; | ||
| - | |||
| - | |||
| - | Screen 22 not modified | ||
| - | 0 \ Notes on Starting Forth. 3 | ||
| - | 1 \ P 119 Error in footnote! | ||
| - | 2 : R% 50 */ 1+ 2/ ; | ||
| - | 3 \ P 123 I I' and J see comments for page 110. | ||
| - | 4 \ P 131 For COMPOUND to display as in text insert a | ||
| - | 5 \ | ||
| - | 6 \ P 135 There is an error in TEST - should be 10 10 DO but | ||
| - | 7 \ even so . . the FORTH83 | ||
| - | 8 \ the one in Starting FORTH !!!! Try the following | ||
| - | 9 : -TEST DO I . ?KEY ?LEAVE ( any key exit ) -1 +LOOP ; | ||
| - | 10 : +TEST DO I . ?KEY ?LEAVE ( any key exit ) 1 +LOOP ; | ||
| - | 11 \ 9 10 +TEST loops 65534 times. | ||
| - | 12 \ 10 10 +TEST loops 65535 times. 10 10 -TEST gives | ||
| - | 13 \ 11 10 +TEST gives 10 11 10 -TEST loops 65535 times | ||
| - | 14 \ If you try any of the longer loops above press any key to | ||
| - | 15 \ abort!! | ||
| - | |||
| - | |||
| - | Screen 23 not modified | ||
| - | 0 \ Notes on Starting Forth. 4 | ||
| - | 1 \ P 137 XX will clear the stack as indicated but our definition | ||
| - | 2 \ : CLEAR DEPTH 0 ?DO DROP LOOP ; will do it without | ||
| - | 3 \ the error message. | ||
| - | 4 : CLEAR SP0 @ SP! ; | ||
| - | 5 \ P 140 In FORTH83 | ||
| - | 6 \ DO ... LOOP !! Thus any words between LEAVE and LOOP | ||
| - | 7 \ will not be executed if the condition for leaving is | ||
| - | 8 \ is satisfied. | ||
| - | 9 \ is not printed the last time. | ||
| - | 10 : HELLOS | ||
| - | 11 \ Note: ?LEAVE can replace the phrase | ||
| - | 12 \ P 142-143 | ||
| - | 13 : CLEAR-SCREEN | ||
| - | 14 | ||
| - | 15 | ||
| - | |||
| - | |||
| - | Screen 24 not modified | ||
| - | 0 \ Notes on Starting Forth. 5 | ||
| - | 1 \ P 161 In FORTH83 | ||
| - | 2 \ | ||
| - | 3 \ In FORTH83 | ||
| - | 4 \ P 164 Double number punctuation is . only! not , | ||
| - | 5 \ P 166 Use the | ||
| - | 6 \ P 169 FORTH83 | ||
| - | 7 \ | ||
| - | 8 \ P 170 Replace | ||
| - | 9 \ | ||
| - | 10 \ P 172 Replace | ||
| - | 11 \ P 174 Use the definitions below: | ||
| - | 12 : M+ S>D D+ ; : M/ M/MOD NIP ; | ||
| - | 13 : M*/ 2DUP XOR SWAP ABS >R SWAP ABS >R OVER XOR -ROT | ||
| - | 14 DABS SWAP R@ UM* ROT R> UM* ROT 0 D+ R@ UM/ | ||
| - | 15 -ROT R> UM/MOD NIP SWAP ROT ?DNEGATE ; | ||
| - | |||
| - | |||
| - | Screen 25 not modified | ||
| - | 0 \ Notes on Starting Forth. 6 | ||
| - | 1 \ P 177 In FORTH83 | ||
| - | 2 \ In FORTH83 | ||
| - | 3 \ P 178 Use ROT SIGN where ever Brodie uses SIGN !! | ||
| - | 4 \ P 202 Use CLEAR-SCREEN definition given earlier for PAGE | ||
| - | 5 \ P 204 Use +LOOP for /LOOP | ||
| - | 6 \ P 215 Type VIEW INTERPRET | ||
| - | 7 \ P 217 In F83 DEFER is used for execution vectors. | ||
| - | 8 \ P 233 In F83 the variable H is called | ||
| - | 9 \ P 235-237 | ||
| - | 10 \ P 240 Use DP instead of H ; No OFFSET in this system. | ||
| - | 11 \ P 242 F83 Uses the ONLY vocabulary structure. See the FORTH-83 | ||
| - | 12 \ | ||
| - | 13 \ P 247 Use DP instead of H . | ||
| - | 14 | ||
| - | 15 | ||
| - | |||
| - | |||
| - | Screen 26 not modified | ||
| - | 0 \ BYTE | ||
| - | 1 - the smallest piece of data that can be accessed by most modern | ||
| - | | ||
| - | 3 - consists of a cell of 8 binary bits: 01110101 <= see the byte | ||
| - | 4 - the low order bit is number | ||
| - | 5 - the high order bit is number 7. | ||
| - | 6 - the bit pattern in a byte can represent an unsigned integer: | ||
| - | | ||
| - | | ||
| - | | ||
| - | 10 - the data structure often represented by bytes is the ASCII | ||
| - | 11 | ||
| - | 12 | ||
| - | 13 21 127 common symbols, digits, letters. | ||
| - | 14 | ||
| - | 15 | ||
| - | |||
| - | |||
| - | Screen 27 not modified | ||
| - | 0 \ WORD | ||
| - | 1 - a word consists of two bytes or 16 binary bits. | ||
| - | 2 - most easily represented by four hexadecimal digits. | ||
| - | 3 - examples: | ||
| - | 4 - the bit pattern in a word can represent an unsigned integer: | ||
| - | | ||
| - | 6 - micro computers can access 65,535 memory cells (bytes) using | ||
| - | | ||
| - | 8 - the bit pattern in a word can also represent signed integers: | ||
| - | | ||
| - | 10 - In FORTH each data stack number is represented by a word. | ||
| - | 11 - In FORTH address are represented by words or unsigned integers | ||
| - | 12 thus FORTH can address or access 65535 bytes of memory. | ||
| - | 13 | ||
| - | 14 | ||
| - | 15 | ||
| - | |||
| - | |||
| - | Screen 28 not modified | ||
| - | | ||
| - | | ||
| - | 2 ONLY FORTH ALSO ALSO DEFINITIONS | ||
| - | | ||
| - | 4 CODE SPLIT | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | 10 | ||
| - | 11 | ||
| - | 12 | ||
| - | 13 | ||
| - | 14 | ||
| - | 15 | ||
| - | </ | ||
papierkorb/sample2.blk.1755359401.txt.gz · Zuletzt geändert: 2025-08-16 17:50 von mka