papierkorb:test1-1.blk
Unterschiede
Hier werden die Unterschiede zwischen zwei Versionen angezeigt.
| papierkorb:test1-1.blk [2025-08-16 17:50] – ↷ Seite von projects:test1-1.blk nach papierkorb:test1-1.blk verschoben mka | papierkorb:test1-1.blk [Unbekanntes Datum] (aktuell) – gelöscht - Externe Bearbeitung (Unbekanntes Datum) 127.0.0.1 | ||
|---|---|---|---|
| Zeile 1: | Zeile 1: | ||
| - | === MID TERM EXAM === | ||
| - | < | ||
| - | Screen 0 not modified | ||
| - | | ||
| - | 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 -5 / | ||
| - | 13 | ||
| - | 14 e) 10 20 | ||
| - | 15 | ||
| - | |||
| - | |||
| - | Screen 2 not modified | ||
| - | 0 \ QUESTION 2 ( 5 MARKS ) | ||
| - | 1 Design a FORTH word SQUARE that will draw the outline of a | ||
| - | 2 square on the display. | ||
| - | 3 word WHITE ( or WW ) from out CHECKER-BOARD | ||
| - | 4 Note: Center of the square should be black!! | ||
| - | | ||
| - | 6 : WHITE | ||
| - | | ||
| - | | ||
| - | | ||
| - | 10 a) Easy Version: | ||
| - | 11 a square | ||
| - | 12 | ||
| - | 13 b) Harder Version: | ||
| - | 14 a square 2n cells horizontal | ||
| - | 15 | ||
| - | |||
| - | |||
| - | Screen 3 not modified | ||
| - | 0 \ QUESTION 3 ( 5 MARKS ) | ||
| - | 1 An open fish tank has a square base ( b inches by b inches ) | ||
| - | 2 and is h inches high. Design the word TANK , which takes | ||
| - | 3 two stack inputs, | ||
| - | 4 surface area and tank volume. | ||
| - | 5 Output display for tank should be similar to the sample below: | ||
| - | | ||
| - | 7 18 24 | ||
| - | | ||
| - | 9 Base of tank is 24 inches. | ||
| - | 10 Height of tank is 18 inches. | ||
| - | 11 | ||
| - | 12 Surface | ||
| - | 13 Volume of tank is 10368 cubic inches. | ||
| - | 14 | ||
| - | 15 | ||
| - | |||
| - | |||
| - | Screen 4 not modified | ||
| - | 0 \ QUESTION 4 ( 5 MARKS ) | ||
| - | 1 a) Show how you would create a FORTH variable called | ||
| - | | ||
| - | | ||
| - | 4 b) What are the FORTH words for fetching, | ||
| - | | ||
| - | | ||
| - | | ||
| - | 8 c) Design the word BALANCE? | ||
| - | | ||
| - | 10 d) Write OPENING-BALANCE | ||
| - | 11 to the top stack number. | ||
| - | 12 | ||
| - | 13 e) Design the word DEPOSITE | ||
| - | 14 and word WITHDRAW which subtracts top of stack from BALANCE . | ||
| - | 15 Can you over draw your account? | ||
| - | |||
| - | |||
| - | Screen 5 not modified | ||
| - | 0 \ QUESTION 5 ( 5 MARKS ) | ||
| - | 1 a) Create and 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 SUM-DATA accumulates the sum of | ||
| - | | ||
| - | | ||
| - | | ||
| - | 10 d) Write a word called ENTER-DATA that uses a indefinite loop | ||
| - | 11 ( ... BEGIN ... WHILE ... REPEAT .. ) to prompt the | ||
| - | 12 user to enter data and stores it in succesive cells of the | ||
| - | 13 DATA array. | ||
| - | 14 data entry. | ||
| - | 15 | ||
| - | |||
| - | |||
| - | Screen 6 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 7 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 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 -5 / | ||
| - | 13 | ||
| - | 14 e) 10 20 | ||
| - | 15 | ||
| - | |||
| - | |||
| - | Screen 12 not modified | ||
| - | 0 \ ANSWER TO QUESTION 2 ( 5 MARKS ) | ||
| - | 1 : WW | ||
| - | 2 \ a) Easy Version: | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | 7 \ b) Harder Version: | ||
| - | | ||
| - | | ||
| - | 10 : .ROW ( n -- ) | ||
| - | 11 CR WW 2* 2- 0 ?DO SPACE LOOP WW ; | ||
| - | 12 : .SQUARE ( n -- ) | ||
| - | 13 DUP 2 < ABORT" Can't do it!!" | ||
| - | 14 DUP .TOP DUP 2- 0 | ||
| - | 15 ?DO DUP .ROW LOOP .TOP CR CR ; | ||
| - | |||
| - | |||
| - | Screen 13 not modified | ||
| - | 0 \ ANSWER TO QUESTION 3 ( 5 MARKS ) | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | 10 CR ." Volume of tank is" 8 .R ." | ||
| - | 11 : TANK ( h b -- ) | ||
| - | 12 CR 2DUP .BH CR 2DUP .AREA .VOL CR CR ; | ||
| - | 13 | ||
| - | 14 | ||
| - | 15 | ||
| - | |||
| - | |||
| - | Screen 14 not modified | ||
| - | 0 \ ANSWER TO QUESTION 4 ( 5 MARKS ) | ||
| - | 1 ( a) VARIABLE | ||
| - | 2 \ b fetching | ||
| - | 3 \ BALANCE | ||
| - | 4 \ 5 BALANCE | ||
| - | 5 \ 2 BALANCE +! ( increment | ||
| - | 6 ( c) : BALANCE? | ||
| - | | ||
| - | 8 ( d) : OPENING-BALANCE | ||
| - | | ||
| - | 10 ( e) : DEPOSITE ( n -- ) | ||
| - | 11 | ||
| - | 12 : WITHDRAW ( n -- ) | ||
| - | 13 BALANCE @ OVER - 0< | ||
| - | 14 IF DROP ." Insufficient funds!" | ||
| - | 15 ELSE NEGATE BALANCE +! THEN ; | ||
| - | |||
| - | |||
| - | Screen 15 not modified | ||
| - | 0 \ ANSWER TO QUESTION 5: ( 5 MARKS ) | ||
| - | 1 ( a) CREATE | ||
| - | 2 ( b) : CLEAR-DATA ( -- -- ) | ||
| - | | ||
| - | 4 ( a) VARIABLE +SUM | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | 10 : #IN QUERY INTERPRET ; | ||
| - | 11 ( d) : ENTER-DATA ( -- -- ) | ||
| - | 12 CLEAR-DATA | ||
| - | 13 CR DUP . ASCII > EMIT #IN DUP 0<> | ||
| - | 14 WHILE OVER 2* DATA + ! 1+ REPEAT | ||
| - | 15 | ||
| - | |||
| - | </ | ||
papierkorb/test1-1.blk.1755359401.txt.gz · Zuletzt geändert: 2025-08-16 17:50 von mka