TEIMSI
Developer's platform of programming text codes
Home|Utilities|Forum|Documentation

Table of contents -> Chapter 16 - TEIMSI Variables

In this chapter will be described the access to variables from assembler language and the internal properties.

The modality or mode.

The modality is a property that determines how the data fields of a "regvar" structure are treated; it's used to store TEIMSI variables. For an example, we'll study this instruction:

	var message1="Hello world! number77=";

This instruction declares within the root module the "message1" variable, which contains a static text (with length of 21 bytes). The static mode (or modality) is one of three possible kind of variable's modality: static mode (which has a fixed content placed in the data section), dynamic mode, for example when it was created the "message1" variable.

The variable "message1" will now have dynamic mode, because it has created a copy allocating memory for which it no longer has a static value of constant data.

And finally this temporary mode, which is internal to the compiler and does not reach us directly any variable with this mode, as an example when analying:

		var message1=trim(ucase("Hello world! number77="));

At some point the compiler obtained the variable ucase("Hello world! number77=") this variable is temporary and internal, but instead if we get the result of "trim" function that processes such temporary variable. Is temporary because it arises from the output of a string (in this case a constant) and is used to create the output variable of interest (with dynamic mode), indeed the function imode() tells us which mode a variable has, see the following example:


		alert("Static mode ? = " + (imode("Hello world! number77=")==_mod_stat)  )		// is true

		var thevariable="Hello world! number77="

		alert("Dynamic mode ? = " + (imode(thevariable)==_mod_dina)  )				// is true

		alert("Temporal mode ? = " + (imode(trim("Hello world! number77="))==_mod_engi)  )	// is true

The importance of "what mode has a variable" resides mostly variable of type string and array type, in which you have assigned a memory space because each memory space on those data types is assigned to a function in assembler (called NwMemory) which gives us a handle that is long integer unsigned used to determine at runtime of instruction; the position of the string or array.

In the following example its usage is shown:


var str1="hello user"+_c0
_direct{
	mov eax, [str1+reg.vo]
	NWPOS_eax
	invoke MessageBox,0, esi, esi, 0
}

The "NWPOS_eax" macro loads the pointer to the string at "esi" register supossing that "eax" contains the handle to the string in memory assigned by NwMemory, no other data register is modified by the macro-instruction. For additional information see also Using the memory handling functions

An usual mistake is to think that the pointer to a string is always the same, but there's a possibility of change by using some TEIMSI function on a subsequent instruction, like it is shown next:

		var str1="hello user"+_c0
		_direct{
			mov eax, [str1+reg.vo]
			NWPOS_eax
			push esi
		}
		var str2="the sky is blue"+_c0;
		_direct{
			pop esi
			invoke MessageBox,0, esi, esi, 0
		}

The previous example shows bad code done, because the pointer to the string str1 could have changed. That's why we should only rely in the string's handle instead of the pointer which can change in execution time. The following example is okay:

		var str1="hello user"+_c0
		_direct{
			mov eax, [str1+reg.vo]
			push eax
		}
		var str2="el cielo es azul"+_c0;
		_direct{
			pop  eax
			NWPOS_eax
			invoke MessageBox,0, esi, esi, 0
		}


Type of variables.

There are three types of variables:

1)- Public variables

2)- Local variables

3)- Variables of parameters passed to the TEIMSI function.


Note: It's not the same type of variable than the data type of a variable.

The main distinction between them arises when dealing with data in them from assembly language.


1)- Public variables.

The public variables can be accessed from any function.

The following example manipulates the value of public variables from assembly, it doesn't matter if the code within the "direct" block is inside a function or not:

	; //########################################################################################################

		var str1="hello user", double1=2.3, integer1=2381, matrix1=array(43,21,11), boolean1=true

		_direct{
			mov eax, [str1+reg.vo]
			NWPOS_eax
			mov dword [esi], 'Hell'			;	modifies the string 

			; //##################

			mov ecx, [str1+reg.nu]
			mov [integer1+reg.vo], ecx		;	modifies the value of the "integer1" variable


			; //##################

			fld1
			fld1
			faddp st1, st
			fsqrt
			fstp qword [double1+reg.vo]		;	modifies the value of the "double1" variable

			; //##################

		
			;	An array is a string with a list of variables in it, the beginning has the long integer (dword) that says how many items you have, then 
			;	 there is the integer indicating the total size of the current string for the array counting the initial 8 bytes, and then comes a sequence of structures 
			;	 "regvar" (size of 16 bytes or 4 dwords) with items which are TEIMSI variables. 
			;
			;	Successively this will add the number 3 to each item of the "matrix1" array:


			mov eax, [matrix1+reg.vo]					;	First put into "esi" the pointer to the string with the "regvar" structures table.
			NWPOS_eax

			mov ecx, [esi]						;	Verifies that the array has some item.
			cmp ecx, 0
			jz ejemplo_j1
				dec ecx						;	Will walk through the array's items from the last to the first.
				
				ejemplo_c1:
					mov edi, ecx
				
					shl edi, 4					;	Make now: edi = ecx * 16
				
					lea edi, [esi+edi+8]				;	"edi" now points to a regvar structure.
				
					cmp dword [edi+reg.ty], syslong		;	Make sure the item in the array is a long integer.  ("reg.ty" is equivalent to "regvar.vtype")
					jnz ejemplo_n1
				
						add dword [edi+reg.vo], 3		;	Add 3 to the array's item.
				
					ejemplo_n1:
				
				dec ecx
				jns ejemplo_c1
			ejemplo_j1:


			; //##################

			xor [boolean1+reg.vo], 1		;	modifies the value of the "boolean1" variable

		}


		alert("String str1 = " + str1 + _nl + "Length of the string str1 = " + integer1)
		alert("Square root of 2 = " + double1)
		alert("Items of the array \"matrix1\" after adding 3 to its items="+_nl+ implode(_nl, matrix1))
		alert("The variable \"boolean1\" now applies: " + boolean1)


	; //########################################################################################################


2)- Local variables

The TEIMSI local variables to a function can be treated as public from assembler, the distinction is that the "regvar" structure is not located in the data section but in the local stack (accessed through the "ebp" register).


3)- Parameters variables passed to the function in TEIMSI.

The variables in the function parameters must be accessed (from within the procedure) by first loading the pointer to the "regvar" structure of the variable, that means the variable name is not the pointer to a "regvar" structure but a place in the local stack that houses the pointer to that "regvar" structure. The following example shows how to read the value of a variable passed as parameter:

	; //##################

	main(35.4332)

	function main(thevariable){

		var result=0.0
		_direct{
			mov ebx, [thevariable]			;	This step must be done with any data type that has a variable TEIMSI in the local parameters.
			fld qword [ebx+reg.vo]
			fsqrt
			fstp qword [result+reg.vo]
		}

		alert(result);
	}

	; //##################



Go to top