pfw:template
Unterschiede
Hier werden die Unterschiede zwischen zwei Versionen angezeigt.
Beide Seiten der vorigen RevisionVorhergehende ÜberarbeitungNächste Überarbeitung | Vorhergehende Überarbeitung | ||
pfw:template [2023-02-06 20:31] – uho | pfw:template [2023-09-04 19:18] (aktuell) – ↷ Seite von en:pfw:template nach pfw:template verschoben uho | ||
---|---|---|---|
Zeile 1: | Zeile 1: | ||
- | ===== Template | + | ===== Template |
- | ==== «name» | + | So - you want to describe a new idea? Great. |
- | Explain in a few words what the idea of this description is. | + | We give some guidelines how to do it. Below we describe |
- | The reader should understand what this is about so that s/he can decide whether or not it is worthwhile | + | |
- | What is the problem. How is the problem solved? | + | Just edit this text and adapt it to your idea. If in doubt you can always save a draft and come back later. |
- | Continue also to explain background information and the idea proper. Is there a trick? | + | Thanks for your contribution, |
- | ==== Implementation ==== | + | The Project Forth Works Team |
- | Discuss a typical (possibly naïve) implementation that best allows to understand the implementation. | + | ---- |
- | More sophisticated/ | + | |
- | ==== Implementation in pseudo code ==== | + | ===== DUMP memory algorithm: display content of main memory ===== |
- | //Use pseudo code following this style:// | + | ==== DUMP idea ==== |
- | '' | + | A DUMP utility is a software tool that allows to inspect main memory and display it in a user readable form. |
- | | + | Typically output is composed of several lines that have the structure: |
- | + | ||
- | Set «variable» | + | Display bytes starting in memory at a given address in hex (or other radix). Behind them is the ASCII representation of these bytes. |
- | | + | |
+ | The DUMP utility is normally called '' | ||
+ | |||
+ | |||
+ | ==== DUMP Implementation ==== | ||
+ | |||
+ | One way to implement DUMP is to iterate | ||
+ | at the start address and increment the address by 16 in each loop iteration. (If you want a different number of bytes in each line, adjust accordingly). | ||
+ | |||
+ | When you display memory in a single line you first output the current address and then have two loops that run one after the other iterating both from 0 to 15. | ||
+ | The first loop outputs bytes with two hexadecimal digits (or in decimal, or whatever you intend) and the second loop outputs the individual bytes as ASCII characters. | ||
+ | |||
+ | As some characters might control the output in a special way (so called control character such as 07 bell, 0A linefeed, 0C formfeed) it is wise to just output a period | ||
+ | instead of the actual character, in order to get a well formatted display. | ||
+ | |||
+ | |||
+ | ==== Pseudo code for the DUMP implementation ==== | ||
+ | |||
+ | //What [[en: | ||
+ | |||
+ | < | ||
+ | Function: dump-line ( address -- ) | ||
+ | output address (possibly right aligned) | ||
+ | output ":" | ||
| | ||
- | | + | |
- | ... | + | output byte in memory at (address+i) as two hexadecimal digits (or in another radix if desired) |
- | ELSE: | + | output some space |
- | ... | + | |
| | ||
- | WHILE: | + | LOOP i from 0 to 15: |
- | | + | |
+ | |||
+ | Function: dump ( address length -- ) | ||
+ | WHILE length is positive: | ||
+ | dump-line at address | ||
+ | increase address by 16 | ||
+ | decrease length by 16 | ||
+ | </ | ||
+ | |||
+ | ==== Minimal Forth implementation of DUMP: ==== | ||
+ | |||
+ | |||
+ | You can find a [[https:// | ||
+ | |||
+ | You can use it as follows: | ||
+ | |||
+ | <code forth> | ||
+ | ok | ||
+ | Create x 100 allot ok | ||
+ | x 100 dump | ||
+ | 03D694: 05 61 6C 6C 6F 74 08 00 DF 14 00 00 C1 00 08 00 | ||
+ | 03D6A4: 1F 18 00 00 C1 00 08 00 6F 10 00 00 C1 00 08 00 | ||
+ | 03D6B4: 4F 10 00 00 C2 00 08 00 1F 13 00 00 C2 00 08 00 | ||
+ | 03D6C4: 8F 30 00 00 C2 00 08 00 DF 14 00 00 C2 00 08 00 ? | ||
+ | 03D6D4: 1F 18 00 00 C2 00 08 00 6F 10 00 00 C2 00 08 00 | ||
+ | 03D6E4: 4F 10 00 00 C3 00 08 00 8F 30 00 00 C3 00 08 00 | ||
+ | 03D6F4: 5F 13 00 00 _... ok | ||
+ | </ | ||
+ | |||
+ | As the original Minimal Forth has no output facility other than '' | ||
+ | this implementation seems to be over complicated. | ||
+ | |||
+ | We extended Minimal Forth to [[https:// | ||
+ | more useful small Forth. | ||
+ | |||
+ | A DUMP utility in **GenericForth** can be found in [[en: | ||
+ | This example is factored using the pseudo code description. The character output has been factored into the useful word PEMIT ( char -- ) too. | ||
+ | |||
+ | |||
+ | ==== Various DUMP Implementations ==== | ||
- | //For defining words use:// | + | Other DUMP implementations can be found at the end of this description. |
- | '' | + | Your system might lack right justified number output or even BASE for printing numbers in other radix systems. The sample implementation in [[en:pfw:twomoredumps.f|twomoredumps.f]] show how to circumvent |
- | Define: ( u -- ) | + | |
- | Reserve RAM space | + | |
- | allocate ROM space | + | |
- | Action: ( -- a ) | + | |
- | Leave start address of this | + | |
- | '' | + | |
- | ==== Generic Forth implementation: | ||
- | Try to implement the pseudo code using the words in [Generic Forth](https:// | + | ==== Background information ==== |
- | mentioning and explaining all other additional words that your implementation requires. | + | |
- | Hardware details may come to the surface, but minimise them! | + | |
- | //Also show how your implementation is used by giving some examples.// | + | More about the DUMP utility can found at the [[https://en.wikipedia.org/wiki/Hex_dump|Wikipedia page for hexdump]] |
+ | Some Forth DUMP implementations display a fixed amount of bytes and leave the updated address on the stack so that | ||
+ | you can invoke DUMP repeatedly to display successive regions of memory. | ||
- | ==== Various other Implementations | + | ==== Possible pitfalls with DUMP ==== |
- | Present additional (possibly more sophisticated) implementations, | + | Some systems have hardware memory protection that is triggered if you access memory outside the reserved area. |
- | Try to state precisely what implementations you present | + | The dump utility can do so by trying |
+ | terminate your session. If necessary a suitable test for the validity of used addresses might be reasonable on such systems so that | ||
+ | dump can issue a normal error message (or display dummy data) in theses cases and leave the system / session otherwise intact. | ||
- | ==== Background information and possible Pitfalls | + | ==== Contributions |
- | Please give references to data sheets, | + | < |
- | Also describe any problems that may arise in connection with the idea you are describing. | + | |
- | What were stumbling blocks, what things are important for others to know? | + | |
- | --- | + | You have another approach to DUMP? |
- | For a simple example idea have a look at [The DUMP utility](https:// | + | Please add it at the end of this document. |
+ | ~~DISCUSSION~~ |
pfw/template.1675711903.txt.gz · Zuletzt geändert: 2023-02-06 20:31 von uho