Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Forth Mac > Re: 16 bits arr...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 2 of 4 Topic 95 of 161
Post > Topic >>

Re: 16 bits array cells being erased

by ward@[EMAIL PROTECTED] (ward mcfarland) Jan 22, 2005 at 06:33 AM

jd <jeandal34@[EMAIL PROTECTED]
> wrote:

> Hi,
> 
> I am running MacForth 5.2 on a Mac and have very strange things
> happening with my arrays. When i create an array and enter a value in
> the first cell as follows:
> create MyArray 12 allot
> 221 MyArray !

221 == hex 000000DD

This stores DD in MyArray + 3 (3 = byte offset)

> 
> if i view the content of the first cell the value is right:
> MyArray @[EMAIL PROTECTED]
 . 
> 221
> 
> However if i now enter a value in the second cell of the 16 bit array:
> 230 MyArray 2 + !

This stores hex 000000E6 in
MyArray + 2 (2 = byte offset)

+DUMP can be your friend here to see what is being stored where.


For 4 bytes per array element, you need to do

create MyArray 12 4 * allot ( to make an array of 12 longs)
or
create MyArray 12 CELLS allot

and access as:

230  MyArray 2 4 * + !
or
230  MyArray 2 cells + !



If you want a simpler style, use MacForth's 1ARRAY word as follows:

12 4 1ARRAY MyArray

Then

221 0 Myarray !
230 1 MyArray !

0 MyArray @[EMAIL PROTECTED]
 .
221

1 MyArray @[EMAIL PROTECTED]
 .
230



Now, if you wanted only 1 BYTE per element originally, then you should
have used C@[EMAIL PROTECTED]
 and C! to access the elements.

  -- ward
 




 4 Posts in Topic:
16 bits array cells being erased
jeandal34@[EMAIL PROTECTE  2005-01-21 09:09:26 
Re: 16 bits array cells being erased
ward@[EMAIL PROTECTED] (  2005-01-22 06:33:18 
Re: 16 bits array cells being erased
ward@[EMAIL PROTECTED] (  2005-01-23 07:52:44 
Re: 16 bits array cells being erased
Roelf Toxopeus <these3  2005-01-23 00:03:43 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat Nov 22 13:38:30 CST 2008.