Assignment and Data Transfer. 32-bit data – TML Programming Details

The TML instructions presented in this paragraph show you the options you have to:

1.Assign a value to a 32-bit long or fixed TML data
2.Assign a value to the high (16MSB) or low (16LSB) part of a 32-bit long or fixed data
3.Transfer in 2 consecutive memory locations, a 32-bit value or the value of a 32-bit long or fixed TML data

In the first case, the destination is a 32-bit TML data: TML parameter or user variable and the source can be:

A 32-bit immediate value
A 32-bit TML data: TML register, parameter, variable or user variable (direct or negated)
A 16-bit TML data left shifted by 0 to 16
2 consecutive memory locations, indicated through a pointer variable

In the second case, the destination is the high or low part of a 32-bit TML data: TML parameter or user variable and the source can be:

A 16-bit immediate value
A 16-bit TML data: TML register, parameter, variable or user variable

In the third case, the destination is 2 consecutive memory locations, indicated through a pointer variable and the source can be:

A 32-bit immediate value
A 32-bit TML data: TML parameter, variable or user variable

Programming Examples

1) Source: 32-bit immediate value, Destination: 32-bit TML data. The immediate value can be decimal or hexadecimal. The destination can be either a long or a fixed variable

       long_var = 100000;        // set user variable long_var with value 100000

       long_var = 0x100000;        // set user variable long_var with value 0x100000

       fixed_var = 1.5;                // set user variable fixed_var with value 1.5 (0x18000)

       fixed_var = 0x14000;        // set user variable fixed_var with value 1.25 (0x14000)

2) Source: 32-bit TML data, Destination: 32-bit TML data.

       var_dest = var_source;        // copy value of var_source in var_dest

       var_dest = -var_source;        // copy negate value of var_source in var_dest

Remark: source and destination must be of the same type i.e. both long or both fixed

3) Source: 16-bit immediate value (decimal or hexadecimal) or 16-bit TML data, Destination: high or low part of a 32-bit TML data. The 32-bit TML data can be either long or fixed

       long_var(L) = -1;                // write value –1 (0xFFFF) into low part of long_var

       fixed_var(H) = 0x2000;        // write value 0x2000 into high part of fixed_var

       long_var(L) = int_var;        // copy int_var into low part of long_var

       fixed_var(H) = int_var;        // copy int_var into high part of fixed_var

4) Source: 16-bit TML data left shifted 0 to 16. Destination: 32-bit TML data. The 32-bit TML data can be either long or fixed

       long_var = int_var << 0;        // copy int_var left shifted by 0 into long_var

       fixed_var = int_var << 16;        // copy int_var left shifted by 16 fixed_var

Remarks:

The left shift operation is done with sign extension. If you intend to copy the value of an integer TML data into a long TML data preserving the sign use this operation with left shift 0
If you intend to copy the value of a 16-bit unsigned data into a 32-bit long variable, assign the 16-bit data in low part of the long variable and set the high part with zero.

Examples:

var = 0xFFFF;        // As integer, var = 1, as unsigned integer var = 65535

lvar = var << 0;        // lvar = -1 (0xFFFFFFFF), the 16MSB of lvar are all set to 1 the

// sign bit of var

lvar(L) = var;        // lvar(L) = 0xFFFF

lvar(H) = 0;                // lvar(H) = 0. lvar = 65535  (0x0000FFFF)

5) Source: 2 consecutive memory locations, indicated through a pointer variable, Destination: 32-bit TML data. The memory locations can be of 3 types: RAM for data (dm), RAM for TML programs (pm), EEPROM SPI-connected for TML programs (spi). The pointer variable indicates first of the 2 memory locations. If the pointer variable is followed by a + sign, after the assignment, it is incremented by 2. The destination can be either a long or a fixed TML data

       p_var = 0x4500;              // set 0x4500 in pointer variable p_var

       var1 = (p_var),spi; // var1 = value of  the EEPROM memory location 0x4500

       var1 = (p_var+),spi; // var1 = value of  the EEPROM memory location 0x4500,

                                     // then set p_var = 0x4502

       p_var = 0x8200;              //  set 0x8200 in pointer variable p_var

       var1 = (p_var),pm;   // var1 = value of  the RAM memory location 0x8200 for TML

     // programs

       var1 = (p_var+),pm; // var1 = value of  the RAM memory location 0x8200 for TML

                                     // programs, then set p_var = 0x8202

       p_var = 0xA00;              //  set 0xA00 in pointer variable p_var

       var1 = (p_var),dm;   // var1 = value of  the RAM memory location 0xA00 for TML

     // data

       var1 = (p_var+),dm; // var1 = value of  the RAM memory location 0xA00 for TML

                                     // data, then set p_var = 0xA02

6) Source: 32-bit immediate value (decimal or hexadecimal) or a 32-bit TML data. Destination: 2 consecutive memory locations indicated through a pointer variable. The memory locations can be of 3 types: RAM for data (dm), RAM for TML programs (pm), EEPROM SPI-connected for TML programs (spi). The pointer variable indicates first of the 2 memory locations. If the pointer variable is followed by a + sign, after the assignment, it is incremented by 2. The source can be either a long or a fixed TML data.

       p_var = 0x4500;                // set 0x4500 in pointer variable p_var

       (p_var),spi = 200000;        // write 200000 in the EEPROM memory location 0x4500

       (p_var+),spi = var1;        // write var1 value in the EEPROM memory location

// 0x4500, then set p_var = 0x4502

       p_var = 0x8200;                // set 0x8200 in pointer variable p_var

       (p_var),pm = 3.5;                // write value 3.5 in RAM memory location 0x8200 for

// TML programs

       (p_var+),pm = var1;        // write var1 value in RAM memory location 0x8200 for

// TML programs, then set p_var = 0x8202

       p_var = 0xA00;                // set 0xA00 in pointer variable p_var

       (p_var),dm = -1L;                // write –1 (0xFFFFFFFF) in the RAM memory location

// 0xA00

       (p_var+),dm = var1;        // write var1 value in the RAM data memory location

// 0xA00, then set p_var = 0xA02

When this operation is performed having as source an immediate value, the TML compiler checks the type and the dimension of the immediate value and based on this generates the binary code for a 16-bit or a 32-bit data transfer. Therefore if the immediate value has a decimal point, it is automatically considered as a fixed value. If the immediate value is outside the 16-bit integer range (-32768 to +32767), it is automatically considered as a long value. However, if the immediate value is inside the integer range, in order to execute a 32-bit data transfer it is necessary to add the suffix L after the value, for example: 200L or –1L.

Examples:

user_var = 0x29E;                // write CPOS address in pointer variable user_var

(user_var),dm = 1000000;        // write 1000000 (0xF4240) in the CPOS parameter i.e

// 0x4240 at address 0x29E and 0xF at address 0x29F

(user_var+),dm = -1;        // write -1 (0xFFFF) in CPOS(L). CPOS(H) remains

// unchanged. CPOS is (0xFFFFF) i.e. 1048575,

// and user_var is incremented by 2        

user_var = 0x29E;                // write CPOS address in pointer variable user_var

(user_var+),dm = -1L;        // write –1L long value (0xFFFFFFFF) in CPOS i.e.

// CPOS(L) = 0xFFFF and  CPOS(H) = 0xFFFF,

// user_var is incremented by 2

user_var = 0x2A0;                // write CSPD address in pointer variable user_var

(user_var),dm = 1.5;        // write 1.5 (0x18000) in the CSPD parameter i.e

// 0x8000 at address 0x2A0 and 0x1 at address 0x2A1

Remark: The TML assignment instructions with source an immediate value or a TML data and destination a TML data, use a short address format for the destination. The short address format requires a destination address between 0x200 and 0x3FF or between 0x800 and 0x9FF. This restriction is respected now by all the predefined or user-defined TML data, hence you can use the above assignment instructions without checking the variables addresses.

However, considering possible future developments, the TML also includes assignment instructions using a full address format where the destination address can be any 32-bit value. The following commands support full addressing:

       long_var,dm = 100000;        // set long_var = 100000 in using full addressing

       long_var,dm = 0x100000; // set long_var = 0x100000 using full addressing

       var_dest,dm = var_source; // copy value of var_source in var_dest using

// full addressing

See also:

Assignment and Data Transfer. 16-bit data – TML Programming Details

TML Description