Jump to content
IGNORED

Xforth question...


danwinslow

Recommended Posts

In the following lines of Forth :

 

0500 VARIABLE SET-ADDRESS

01 C,

0000 , 0000 , 00 C,

 

I'm not really sure whats going on. Is the 0500 that precedes the VARIABLE some kind of address specification, or an initial value perhaps? Also, what are the commas doing...I am guessing that this lays out a block of memory named SET-ADDRESS, whose first word is initialized to 0500, is followed by an ( un-named ) byte (c=character?), followed by a word, followed by another word, followed by a byte, for a total length of 8.

 

Am I close?

Link to comment
Share on other sites

In the following lines of Forth :

 

0500 VARIABLE SET-ADDRESS

01 C,

0000 , 0000 , 00 C,

 

I'm not really sure whats going on. Is the 0500 that precedes the VARIABLE some kind of address specification, or an initial value perhaps? Also, what are the commas doing...I am guessing that this lays out a block of memory named SET-ADDRESS, whose first word is initialized to 0500, is followed by an ( un-named ) byte (c=character?), followed by a word, followed by another word, followed by a byte, for a total length of 8.

 

Am I close?

 

Yes you are close.

 

The (Fig-)Forth Word VARIABLE takes a 16bit value from the stack (the $0500, as we are in Base 16), creates a new WORD called "SET-ADDRESS", reserves 2 Byte (16 bit) in the Forth Dictionary and stores the 16bit value in the two byte. The new Word "SET-ADDRESS" will put the Address of the reserved 2 bytes on the stack when executed. So we can retrieve the value of the variable with

 

SET-ADDRESS @

 

where "@" is the forth word to read 16bit value at an address suplied on the stack.

 

The "," and "C," words store a 16bit or 8bit value in the dictionary, in this case just behind the 2 bytes named with the word SET-ADDRESS. This is an easy was to build up any kind of data structure. Print the Address if SET-ADDRESS and examine the memory there

 

SET-ADDRESS .

 

will give you the memory location of the variable "SET-ADDRESS", which is the starting point for the datastructure containing the USB Packet to set the USB Address to an USB Device.

 

In F83 or ANSI Forth (like VolksForth) the same would be

 

CREATE SET-ADDRESS 0500 , 01 C, 0000 , 0000 , 00 C,

 

Carsten

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...