VM Sub-Registers |
Top Previous Next |
Normally we have 16 GPRM registers GPRM0-GPRM15. The Abstraction Layer reserves GPRM11-GPRM15, so we have ten registers to play with.
A GPRM register is a double-BYTE word, that means it can have values 0..65535.
For some interactive projects we don't need to enter such high number (65535) but we would love to rather have more registers instead. The solution is to create Virtual Registers by Sub-dividing the GPRM registers into smaller parts and use these parts to store separate data. In order to work with these subdivided registers, you need to enter special GET or SET code each time you work with the Sub-register that will mask the bites in the register. For most of the people it is not easy to do it by hand, so The GPRM Sub-Registers wizard will help you with this.
First you need to decide how many Sub-registers you would like to create from the Register. (Each GPRM register can be divided into different number of Sub-Registers or left undivided) The number of parts will directly affect the maximum number that can be entered into each Sub-Register.
We see that if we divide a register into 16 parts, we can only store 0 or 1 (because each sub-register is now 1 bit) This could be useful for some projects, we can use for example 5 registers to create in total 80 one bit Sub-Registers.
VM Code If we use the sample image above and divide GPRM0 into 4 Sub-Registers (each can have values 0..15) and then we would like to enter a value 1 into Sub-Registers "C" then the code the wizard will generate will be this:
GPRM12 = 1 GPRM12 &= 0x0F GPRM12 *= 0x10 GPRM0 &= 0xFF0F GPRM0 |= GPRM12
Note: GPRM12 is be used as temporary variable. The code is generated cleanly so it can be easily adapted later without going to the wizard again. If we for example change our mind and want to enter value 5 or use a register for our input value, we just need to change the first line GPRM12 = 5 or GPRM12 = GPRM6.
Similarly if we would like to get a value from our register we will generate GET code:
GPRM12 = GPRM0 GPRM12 /= 0x10 GPRM12 &= 0x0F
In this code we receive the value from the C Sub-Register of GPRM0 in the temp registers GPRM12. Then we can use it later in our code. You can have it generate the code with other register or you can replace the GPRM12 with a new register later in the code.
The software remembers the Register subdivision and saves it to the project file. It is important to understand that this is a virtual subdivision. The registers are still, the same, we just pack a more data into them using the GET or SET code. |