papierkorb:test1-2.blk
Unterschiede
Hier werden die Unterschiede zwischen zwei Versionen angezeigt.
| papierkorb:test1-2.blk [2025-08-16 17:50] – ↷ Seite von projects:test1-2.blk nach papierkorb:test1-2.blk verschoben mka | papierkorb:test1-2.blk [Unbekanntes Datum] (aktuell) – gelöscht - Externe Bearbeitung (Unbekanntes Datum) 127.0.0.1 | ||
|---|---|---|---|
| Zeile 1: | Zeile 1: | ||
| - | === MID TERM EXAM 2 === | ||
| - | < | ||
| - | Screen 0 not modified | ||
| - | 0 \ 13: | ||
| - | 1 \ Last change: | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | 10 | ||
| - | 11 | ||
| - | 12 | ||
| - | 13 | ||
| - | 14 | ||
| - | 15 | ||
| - | |||
| - | Screen 1 not modified | ||
| - | 0 \ QUESTION 1 ( 5 MARKS ) | ||
| - | 1 Show the resulting stack after return is pressed. | ||
| - | | ||
| - | 3 Example: | ||
| - | | ||
| - | | ||
| - | 6 a) 13 17 23 31 | ||
| - | | ||
| - | 8 b) 13 31 17 23 | ||
| - | | ||
| - | 10 c) 23 17 13 | ||
| - | 11 | ||
| - | 12 d) 11 5 -14 | ||
| - | 13 | ||
| - | 14 e) 25 50 10 | ||
| - | 15 | ||
| - | |||
| - | |||
| - | Screen 2 not modified | ||
| - | 0 \ QUESTION 2 ( 5 MARKS ) | ||
| - | 1 Design the FORTH word EIGHT that will draw the outline of the | ||
| - | 2 number eight on the display. | ||
| - | 3 word WHITE ( or WW ) from the CHECKER-BOARD | ||
| - | | ||
| - | 5 : WHITE | ||
| - | | ||
| - | 7 The word EIGHT takes no stack parameters. | ||
| - | 8 The output should look exactly like the X X | ||
| - | 9 figure at right except that it will not | ||
| - | 10 be made from X' | ||
| - | 11 you should demonstrate your knowledge of | ||
| - | 12 factoring (ie your definition of EIGHT X X | ||
| - | 13 should not be one great big word!). | ||
| - | 14 | ||
| - | 15 | ||
| - | |||
| - | |||
| - | Screen 3 not modified | ||
| - | 0 \ QUESTION 3 ( 5 MARKS ) | ||
| - | 1 A closed rectangular tank has a square base, b cm by b cm, | ||
| - | 2 and is h cm high. | ||
| - | 3 a) Write the word AREA that takes two stack inputs base, and | ||
| - | | ||
| - | | ||
| - | 6 b) Write the word VOLUME that takes two stack inputs base, and | ||
| - | | ||
| - | | ||
| - | 9 c) Write the word TANK that takes two stack inputs base, and | ||
| - | 10 height and uses the words AREA and VOLUME above to produce | ||
| - | 11 the following report when executed as shown below: | ||
| - | 12 4 5 TANK | ||
| - | 13 The surface area is 112 square centimeters. | ||
| - | 14 THe volume is | ||
| - | 15 | ||
| - | |||
| - | |||
| - | Screen 4 not modified | ||
| - | 0 \ QUESTION 4 ( 5 MARKS ) | ||
| - | 1 a) Show how you would create a FORTH variable called | ||
| - | | ||
| - | | ||
| - | | ||
| - | 5 b) Design the word STATUS? | ||
| - | | ||
| - | | ||
| - | 8 c) Write INITIAL-SETTING | ||
| - | | ||
| - | 10 | ||
| - | 11 d) Write the word OPEN which adds the top stack number to VALVE | ||
| - | 12 and word CLOSE which subtracts top stack number from VALVE . | ||
| - | 13 e) Can the value of VALVE ever become less than 0 using CLOSE ? | ||
| - | 14 Can the value of VALVE ever exceed 100 using OPEN ? | ||
| - | 15 Fix OPEN and CLOSE so that VALVE is always between 0 and 100. | ||
| - | |||
| - | |||
| - | Screen 5 not modified | ||
| - | 0 \ QUESTION 5 ( 5 MARKS ) | ||
| - | 1 a) Create an array called DATA that will hold 50 16bit numbers. | ||
| - | | ||
| - | 3 b) Write a word called CLEAR-DATA which initializes | ||
| - | | ||
| - | | ||
| - | 6 c) Write a word called COUNT-DATA that counts the number of | ||
| - | | ||
| - | | ||
| - | 9 d) Write a word called SUM-DATA that leaves the sum of all non | ||
| - | 10 zero entries in the array DATA in the variable SSUM . | ||
| - | 11 | ||
| - | 12 e) Write a word called SUM-SQR that leaves the sum of squares | ||
| - | 13 of all non zero entries in the array DATA in the variable | ||
| - | 14 | ||
| - | 15 | ||
| - | |||
| - | |||
| - | Screen 8 not modified | ||
| - | 0 \ 32 bit square root KS 4TH DIM V4N1P9 | ||
| - | | ||
| - | 2 : EASY-BITS ( drem1 partial.root1 count | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | 9 : 2' | ||
| - | 10 >R D2* DUP 0< | ||
| - | 11 IF | ||
| - | 12 ELSE D2* R@ 2DUP U< | ||
| - | 13 | ||
| - | 14 | ||
| - | 15 THEN THEN ; | ||
| - | |||
| - | |||
| - | Screen 9 not modified | ||
| - | 0 \ 32 bit square root KS 4TH DIM V4N1P9 | ||
| - | 1 : 1' | ||
| - | | ||
| - | | ||
| - | | ||
| - | 5 \ 32-bit unsigned radicand to 16-bit unsigned square root | ||
| - | 6 : SQRT ( ud | ||
| - | | ||
| - | | ||
| - | 9 \ Display square root of 16-bit number with 3 decimal places. | ||
| - | 10 : .SQRT ( n -- ) \ n must be < 4096 | ||
| - | 11 16 * 62500 UM* | ||
| - | 12 | ||
| - | 13 | ||
| - | 14 : TEST 100 0 DO CR I 5 .R SPACE I .SQRT LOOP ; | ||
| - | 15 | ||
| - | |||
| - | |||
| - | Screen 11 not modified | ||
| - | 0 \ ANSWER TO QUESTION 5 ( 5 MARKS ) 20: | ||
| - | 1 Show the resulting stack after return is pressed. | ||
| - | | ||
| - | 3 Example: | ||
| - | | ||
| - | | ||
| - | 6 a) 13 17 23 31 | ||
| - | | ||
| - | 8 b) 13 31 17 23 | ||
| - | | ||
| - | 10 c) 23 17 13 | ||
| - | 11 | ||
| - | 12 d) 11 5 -14 | ||
| - | 13 | ||
| - | 14 e) 25 50 10 | ||
| - | 15 | ||
| - | |||
| - | |||
| - | Screen 12 not modified | ||
| - | 0 \ ANSWER TO QUESTION NUMBER 2 ( 5 MARKS ) | ||
| - | | ||
| - | 2 : WHITE | ||
| - | 3 : .TOP ( -- -- ) | ||
| - | | ||
| - | 5 : .ROW ( -- -- ) | ||
| - | | ||
| - | | ||
| - | 8 : EIGHT ( -- -- ) | ||
| - | | ||
| - | 10 3 0 DO CR .ROW LOOP | ||
| - | 11 CR .TOP | ||
| - | 12 3 0 DO CR .ROW LOOP | ||
| - | 13 CR .TOP | ||
| - | 14 | ||
| - | 15 | ||
| - | |||
| - | |||
| - | Screen 13 not modified | ||
| - | 0 \ ANSWER TO QUESTION 3 ( 5 MARKS ) 18: | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | 10 | ||
| - | 11 CR ." The volume is " VOLUME . | ||
| - | 12 | ||
| - | 13 CR ; | ||
| - | 14 | ||
| - | 15 | ||
| - | |||
| - | |||
| - | Screen 14 not modified | ||
| - | 0 \ ANSWER TO QUESTION 4 ( 5 MARKS) | ||
| - | 1 ( a) VARIABALE | ||
| - | | ||
| - | 3 ( b) : STATUS? ( -- -- ) | ||
| - | | ||
| - | | ||
| - | 6 ( c) : INITIAL-SETTING | ||
| - | | ||
| - | | ||
| - | 9 ( d) : OPEN ( n -- ) VALVE +! ; | ||
| - | 10 : CLOSE ( n -- ) NEGATE | ||
| - | 11 | ||
| - | 12 ( e) : OPEN ( n -- ) VALVE @ + 100 MIN VALVE ! ; | ||
| - | 13 : CLOSE ( n -- ) VALVE @ SWAP - 0 MAX VAVLE ! ; | ||
| - | 14 | ||
| - | 15 | ||
| - | |||
| - | |||
| - | Screen 15 not modified | ||
| - | 0 \ ANSWER TO QUESTION 5: ( 5 MARKS ) | ||
| - | 1 ( a) CREATE | ||
| - | 2 ( b) : CLEAR-DATA ( -- -- ) | ||
| - | | ||
| - | 4 ( a) VARIABLE N | ||
| - | | ||
| - | | ||
| - | 7 ( c) | ||
| - | | ||
| - | | ||
| - | 10 ( d) | ||
| - | 11 : SUM-DATA | ||
| - | 12 50 0 DO I DATA@ ?DUP IF SSUM +! THEN LOOP ; | ||
| - | 13 ( e) | ||
| - | 14 : SUM-SQR | ||
| - | 15 50 0 DO I DATA@ ?DUP IF DUP * SSQR +! THEN LOOP ; --> | ||
| - | |||
| - | |||
| - | Screen 16 not modified | ||
| - | 0 \ Used for testing solution. | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | 10 | ||
| - | 11 | ||
| - | 12 | ||
| - | 13 | ||
| - | 14 | ||
| - | 15 | ||
| - | |||
| - | </ | ||
papierkorb/test1-2.blk.1755359401.txt.gz · Zuletzt geändert: 2025-08-16 17:50 von mka