简体   繁体   English

如何在Forth转储一个单词?

[英]How to dump a word in Forth?

The aim is to create a Forth word in the dictionary and then print out the memory content of that word. 目的是在字典中创建一个Forth单词,然后打印出该单词的内存内容。 The first step is easy. 第一步很简单。 The : main word is created like described in tutorial. : main单词的创建方式如教程中所述。 After creating the word, the dictionary pointer is moved to the next position, so I have to subtract some items from it and now it's possible to dump out the memory area in which the word was created: 创建单词后,字典指针移动到下一个位置,所以我必须从中减去一些项目,现在可以转出创建单词的内存区域:

\ create a dummy routine
: main 1 dup + . ;

\ put dictionary pointer to the stack
\ and subtract 50 indizies
dp 50 - 

\ print out 20 cells to the screen from dp-50 until dp+50
\ but where is my newly created routine ": main"?
100 dump

bye
------
gforth "a.fs"

7F81DF443FC6: 00 00 20 17  12 AF 60 55 - 00 00 04 00  00 00 00 00  .. ...`U........
7F81DF443FD6: 00 00 A0 58  14 AF 60 55 - 00 00 10 00  00 00 00 00  ...X..`U........
7F81DF443FE6: 00 00 FF FF  FF FF FF FF - FF FF 00 00  00 00 00 00  ................
7F81DF443FF6: 00 00 50 82  49 DF 81 7F - 00 00 F8 3F  44 DF 81 7F  ..P.I......?D...
7F81DF444006: 00 00 08 82  49 DF 81 7F - 00 00 F0 81  49 DF 81 7F  ....I.......I...
7F81DF444016: 00 00 32 00  00 00 00 00 - 00 00 00 00  00 00 00 00  ..2.............
7F81DF444026: 00 00 00 00 

Unfortunately, the memory region shown by the dump command doesn't have a section which starts with : main and the statements inside the word 1 dup ... are also missing. 不幸的是,dump命令显示的内存区域没有以: main开头的部分,而单词1 dup ...中的语句也缺失。 So where exactly is the newly created word? 那么新创建的单词到底在哪里? How can I see the raw bytes in the memory? 如何查看内存中的原始字节?

1) There is a predefined word see which should do what you want and looking into the respective sources should give you a hint. 1)有一个预定义的单词, see哪个应该做你想要的,并查看相应的来源应该给你一个提示。

2) Your approach only works for a certain memory model, ie putting names and code into the same region, which is far from guaranteed. 2)您的方法仅适用于某种内存模型,即将名称和代码放入同一区域,这远远不能保证。 (I'm not sure, whether it would work for Gforth ). (我不确定,它是否适用于Gforth )。 From dup , 1 , + , etc. you would recognize nothing, since they are replaced by the corresponding addresses or call instructions. dup1+等,你什么都不会识别,因为它们被相应的地址或通话指令取代。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM