Q: How do I determine the top of the Open Firmware dictionary?
A: Use the word here , which will place the address of the top of the dictionary onto the data stack. Try this colon definition.
: x here . 1 cells allot here . ;
|
When executed, X will output the top address of the dictionary twice. Here is how that happens. here places the top dictionary address onto the stack and . displays that address.
Then 1 is placed onto the stack and the cells word converts
that number to the number of bytes in a cell and places that number onto the stack.
Next the allot word takes the number from the top of the stack and
allocates that number of bytes in the dictionary.
Finally, here will place the new address on the stack and .
will output the number.
Note that the difference between the two addresses is 4 bytes, which is expected for a 32-bit architecture such as the Motorola 750 microprocessor.
Here is another important point about the words cells and cell+ . Use these words in looping algorithms and your code will be portable. cells is the correct word for address arithmetic. Then no matter what the register size of the microprocessor is, cells and cell+ will do the conversion.
|