Assignment and Data Transfer. 16-bit variable – TML Programming Details |
The TML instructions presented in this paragraph show you the options you have to:
In the first case, the destination is a 16-bit TML data: TML register, TML parameter or user variable and the source can be:
In the second case and the destination is a memory location indicated through a pointer variable and the source can be:
Programming Examples 1) Source: 16-bit immediate value, Destination: 16-bit TML data. The immediate value can be decimal or hexadecimal user_var = 100; // set user variable user_var with value 100 user_var = 0x100; // set user variable user_var with value 0x100 (256) label1: user_var = label; // set user variable user_var with label1 value 2) Source: 16-bit TML data, Destination: 16-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 3) Source: high or low part of a 32-bit TML data, Destination: 16-bit TML data. The 32-bit TML data can be either long or fixed int_var = long_var(L); // copy low part of long_var in int_var int_var = fixed_var(H); // copy high part of fixed_var in int_var 4) Source: a memory location indicated through a pointer variable, Destination: 16-bit TML data. The memory location can be of 3 types: RAM for data (dm), RAM for TML programs (pm), EEPROM SPI-connected for TML programs (spi). If the pointer variable is followed by a + sign, after the assignment, the pointer variable is incremented by 1 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 // p_var = 0x4501 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 fior //TML programs, then set p_var = 0x8201 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 = 0xA01 5) Source: the result of the checksum. Destination: 16-bit TML data. The checksum is performed with all locations situated between 2 memory addresses. These are specified either as immediate values or via 2 pointer variables. The memory can be of 3 types: RAM for data (dm), RAM for TML programs (pm), EEPROM SPI-connected for TML programs (spi).
// between EEPROM memory addresses 0x4000 and 0x4500 start = 0x9000; // set start address = 0x9000 end = 0x9100; // set end address = 0x9100 checksum, pm start, stop, var1; // var1=checksum value computed // between RAM (for TML programs) addresses 0x9000 and 0x9100 pointed by the TML // variables start and stop 6) Source: 16-bit immediate value (decimal or hexadecimal) or 16-bit TML data. Destination: a memory location indicated through a pointer variable. The memory location can be of 3 types: RAM for data (dm), RAM for TML programs (pm), EEPROM SPI-connected for TML programs (spi). If the pointer variable is followed by a + sign, after the assignment, the pointer variable is incremented by 1 p_var = 0x4500; // set 0x4500 in pointer variable p_var (p_var),spi = -5; // write value –5 in the EEPROM memory location // 0x4500 (p_var+),spi = var1; // write var1 value in the EEPROM memory location // 0x4500, then set p_var = 0x4501 p_var = 0x8200; // set 0x8200 in pointer variable p_var (p_var),pm = 0x10; // write value 0x10 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 = 0x8201 p_var = 0xA00; // set 0xA00 in pointer variable p_var (p_var),dm = 50; // write value 50 in the RAM memory location 0xA00 for // TML data (p_var+),dm = var1; // write var1 value in the RAM memory location 0xA00 // for TML data, then set p_var = 0xA01 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 16-bit value. The following commands support full addressing: int_var,dm = 100; // set int_var = 100 using full addressing int_var,dm = 0x100; // set int_var = 0x100(256) 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. 32-bit data – TML Programming Details |