1

I really feel it is difficult to understand the J1 Forth CPU programming.

I have basic understanding of Forth, but I couldn't understand the words defined in J1 Forth programming like d# and h#...and how is it dealing with I/O peripherals?

1 Answer 1

2

The existence of the d# and h# words is just a consequence of the chosen compiler implementation method.

The code written for J1 is actually running on the hosting Forth system. The program for J1, though looking exactly like a Forth source, is just a list of words that are executed by hosting system (Gforth) sequentially, as read from file. And only when the word is executed, it adds the actual J1 instruction to the final image.

With that approach, only words that are executing are able to produce instructions for J1. Numeric literals aren't those words, so they had to be wrapped with calls to d# (decimal number) or h# (hexadecimal number). Without wrapping, literals would put numbers on the compiler stack and won't add any instruction for J1 to execute.

The peripherals are typically mapped into memory space or I/O space. You'd put a value to write, and the address of peripheral on stack, and issue the store command appropriate for the selected space. Address spaces may be distinct, or just one common - depending on the actual J1 version or implementation details. The original J1 had a single address space; your RAM and peripherals would be addressed uniformly with ! and @ words. The J1a version has dedicated I/O space, and include additional io@ / io! words.

Personally I find the J1a a better version. But I don't use the SwapForth - a complete Forth system for J1a, and instead extended the cross.fs to include the words, primitives and facilities I need, because I really need only an offline compiler rather than a complete system capable of building own code on the fly.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.