Host Engineering Forum

General Category => Do-more CPUs and Do-more Designer Software => Topic started by: MAEdwards on June 04, 2015, 02:41:14 PM

Title: SET Instruction with V_Register and Index
Post by: MAEdwards on June 04, 2015, 02:41:14 PM
Greetings Everyone!

I am looking for a a little help with my scenario.

Often times I want to set an individual bit in a Word or Double Word.

When using a User Memory Block in the following configuration:
-Name: Whatever
-Data Type: Bit
-Range: 0-31
I can create: SET Whatever[Index].

When I am using a V_Register I can create: SET V0:0

However, I have not been to create:
SET V0:Index or SET V0[Index]

Is there a Casting convention that I am failing to see OR am I having an Instruction and Data Type incompatibility issue?
Any help would much much appreciated.
Title: Re: SET Instruction with V_Register and Index
Post by: franji1 on June 04, 2015, 03:24:39 PM
There is no "indirect" casting mechanism, e.g. to cast to a variable bit of a V WORD.

HOWEVER, if you ever need to do any "indirect" manipulation, make the DATA-TYPE of the user data-block be the SMALLEST SIZE of indirection you think you need.  If it's BITs, make your data-block a block of BITs, EVEN IF you want to use them as REALs (because you can always cast to LARGER):

MyBlock as bits, but I want to use them as 100 REALs (so it would be 3200 "bits" long, cuz each REAL is 32 bits)

Now I can easily reference bits individually:
MyBlock0
MyBlock1

or as REALs
MyBlock0:R  // the first REAL
MyBlock32:R  // the second REAL (yes, ID's need to bump by 32 at a time)
MyBlock64:R  // the third
MyBlock96:R  // the fourth

But I can indirectly reference bits (array index is BIT ID)
MyBlock[V0]
where V0 is the bit ID

And I can even look at REALs them indirectly as arrays
MyBlock[V0]:R
where V0 is still the bit ID, hence it should equal 0 then 32 then 64 then 96 then ... (not 0, 1, 2, remember the index is still a BIT ID).

Note: V0 actually COULD be anything, but even that is handled:
e.g. V0 equal to 0..31 resolves to ID of 0, V0 equal to 32..63 resolves to ID of 32, V0 equal to 64..95 resolves to 64, V0 of 96..127 resolves to ID of 96
Cast to REAL or Signed Word (:SW) or Unsigned Byte (:UB), but the BASE data-block is BITs.

Conclusion: You can use array indexing to casts of LARGER sizes.  Array index works on the ID portion, but you cannot use indexing on the CAST side (past the ":").  Hence, make your data-blocks data-type be the SMALLEST size needed for "indirect casting".
Title: Re: SET Instruction with V_Register and Index
Post by: BobO on June 04, 2015, 03:52:43 PM
You can create essentially the same mechanism by using bits as the base type, then doing aggregation casts to get the larger element.
Title: Re: SET Instruction with V_Register and Index
Post by: MAEdwards on June 04, 2015, 05:01:21 PM
Thanks Franji1 and BobO!

I was afraid that this was the case.  I had already had success utilizing your suggestions, but was failing to execute the indexed V WORD.

I will use the User Data Blocks for now.
Thanks again for your help.
Title: Re: SET Instruction with V_Register and Index
Post by: Controls Guy on June 04, 2015, 05:45:31 PM
Or to set bit V10 in D1000, do

Code: [Select]
MATH D1000 D1000 | (1 << V10)
to clear

Code: [Select]
MATH D1000 D1000 & (1 << V10)
NOTE:  2**V10 is equivalent to 1 << V10 but is much slower.
Title: Re: SET Instruction with V_Register and Index
Post by: b_carlton on June 04, 2015, 06:19:04 PM
Quote
MATH D1000 D1000 & (1 << V10)

I think it would have to be an AND with the NOT of 1 << V10

Possibly :

D1000 & ~(1 << V10)
Title: Re: SET Instruction with V_Register and Index
Post by: Controls Guy on June 04, 2015, 06:27:03 PM
Wups -- typing faster than thinking fault!   ;D

Thanks for catching it!