Sub-Registers

Top  Previous  Next

As we explained before in VM Commands, Sub-Register is a register that is divided into smaller parts. Each part can be used as if it is virtually separate.

 

The only consideration is the maximum value a divided Sub-Register can hold. See the table:

 

Subdivide into

Allowed Values

No division

0..65535

2 Sub-Registers

0..255

4 Sub-Registers

0..15

8 Sub-Registers

0..3

16 Sub-Registers

0..1

 

To divide Register, you can use Sub-Registers Setup button:

 

clip0174

 

Here you can select GPRM register and then Subdivide it into 2, 4, 8 or 16 parts:

 

clip0175

 

Subdividing inside the code.

 

To make sure the subdivision is set correctly each time you run script you can set up the registers from code using SUBDIVIDE command. The best place is similarly to the ALIAS, before any block.

 

SUBDIVIDE GPRM1 2

 

PRE "Menu 1"

GPRM1.A = 2

 

This divides the GPRM1 into 2 parts.

 

Usage

If you look at the diagram on Sub-Registers Setup, it shows you the naming convention for each sub-registers.

The sub-registers are defined as A, B, C, D... etc after the register (or alias name) and a dot.

 

Example

GPRM1.A = 2

GPRM1.B += 1

if (Counter.D == 2) then..

 

Sub-Registers and GPRM12 (Temp)

The internal code to unfold sub-register on DVD will use GPRM12. That means after any Sub-Register operation GPRM12 will be changed.

 

Example

GPRM12 = 3

GPRM1.A +=10

//GPRM12 is no longer 3

 

GPRM12 = 3

if (GPRM1.A > 2) LinkPGCN 2

//GPRM12 is no longer 3

 

It is therefore not safe to use GPRM12 to store values if you are using Sub-Registers.

 

Alternative Safe usage of GPRM12
if you really need to use GPRM12 (you run out of registers) you still can, but make sure you don't carry any value in GPRM12 behind any Sub-Register operation (including if comparison). You can however safely assign value from/to GPRM12 and Sub-Register.

 

Example:

GPRM12 = 3

GPRM12 += GPRM3

// or any other normal operation with GPRM12

// assign GPRM12 to sub-register is OK.

GPRM1.A = GPRM12

//GPRM12 is now changed, we can use it again for other new things until any sub-reg operation

GPRM12 = 0

 

Example

//Assigning value to GPRM12 from subregister is OK

GPRM12 = GPRM1.A

GPRM12 += 2

//or any other normal operations with GPRM12 until any sub-register operation

 

Avoid un-necessary Sub-Register operations

Unfolding and folding Sub-Registers takes up to 5 lines of VM command on a DVD.

A code like this:

GPRM1.A += 2

actually takes 7 lines of vm code as it uses both folding and unfolding code.

 

if you write a simple code like this:

 

// here we do all operations directly on Sub-Registers

GPRM1.A += 2

GPRM1.A *= 2

if (GPRM1.A >6) LinkPGCN 2

if (GPRM1.A >3) LinkPGCN 3

 

it will expands it into 20 lines of code. This is because each Sub-Register operation will need to be expanded separately.

 

Instead we can write a smarter code where we avoid unnecessary operation on Sub-Registers by first assigning sub-register into a normal register, then doing operations on the normal register and eventually sending the register back to Sub-Register if needed:

 

// this code does the same as the one above

// but first we assign the subregister into normal register

GPRM0 = GPRM1.A

// then do the operations on full register

GPRM0 += 2

GPRM0 *= 2

// then set it back

GPRM1.A = GPRM0

// compare the full register instead of sub-register - saves lines of VM commands on DVD

if (GPRM0 >6) LinkPGCN 2

if (GPRM0 >3) LinkPGCN 3

 

the above script will create only 12 lines of VM code on the DVD.