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

Table of contents -> Chapter 6 - CPU registers elements


It's advisable to have knowledge about the instruction set for 386 model processors (see Cpu386.html file Links) since it will help the whole documentation and chapter's understanding.

A "Byte" can be an integer between 0 and 255 inclusive, which may also represent one of the 256 characters of the ASCII table. As an example, it can be said that almost all the characters of this documentation have their own corresponding ASCII decimal code, for the letter "a" it's 97. A "Byte" can be expressed in the binary numerical system, then 8 Bits (binary Digits) are enough to represent any byte (256 = 2^8 = 2 x 2 x 2 x 2 x 2 x 2 x 2 x 2).

A "Word" (word) is represented with two "Bytes" or 16 bits, is an integer between 0 and 65535 included.

A "Dword" (double word) is represented with four "Bytes" or 32 bits, is an integer between 0 and 4294967295 included. The variables of type TEIMSI integer have this size of 4 bytes also known as long integer. A TEIMSI long integer is represented by a value between -2147483648 and 2147483647 (signed long integer), the hexadecimal notation of -2147483648 is "80000000H" and 2147483647 is "7FFFFFFFh" the -1 is "FFFFFFFFh" and so on. With this representation of negative integers known as BCD (decimal decoded binary) consistency of results is maintained by the addition and subtraction with the instructions of the CPU called "add" and "sub" (for multiplication and division is not the case, that's why the "imul" and "idiv" instrucctions for signed integers are useful; also "mul" and "div" are used for unsigned integers).

You can see that when the highest bit is one, the integer (signed) is negative. If the sum of two numbers gives greater or equal to 2^32, the bits in position 32 or higher are not used, for example: -4 + 7 = 3, in hexadecimal notation that is FFFFFFFCh + 00000007h = 100000003h but using only the 4 "Bytes" turns out to be 00000003h or equal to 3.

In TEIMSI, representation by the "alert" function of long integers is considered to be negative (with sign) to avoid the representation of the sign there's needed an internal conversion maneuver as in the following example:

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

	var num=-123	//	Negative integer, in the hexadecimal representation is FFFFFF85h which in our decimal numerical system is 4294967173.

	alert(num)	//	Show the -123 integer

	_direct{
		push dword 0				;	Save into the local stack the integer value of 8 bytes ("Qword") or double "Dword", then load it into the Coprocessor and save it as a double precision decimal number.
		push dword [num+regvar.vofix]

			fild qword [ss:esp]
			fstp qword [num+regvar.vofix]
	
			mov [num+regvar.vtype], sysdbl	;	Change the data type from integer to double, no other change is required in the "regvar" structure for this variable called "num" because it is neither a string or an array.

		pop  eax eax					;	(Adds 8 to "esp")
	}

	alert(num)	//	Shows the "4294967173" floating point number

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


With the "movsx" and "movzx" instructions of the CPU, it's possible to transfer a smaller value from a register or memory into a bigger operand. The instruction "movsx" copies signed values and "movzx" only copies the bottom to the destination register, leaving the top with zeros as shown in the following example:

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

	var num1=0, num2=0

	_direct{
		mov bl, 131	;	The expression of the integer 131 to hexadecimal is 83h, and to binary is 10000011b. If the byte is unsigned, then it values -125 = 131 - 256.

		movsx eax, bl
		movzx ecx, bl

		mov [num1+reg.vo], eax
		mov [num2+reg.vo], ecx
	}
	//	When the highest bit (bit 7) of the 131 byte equals 1, the number is negative.

	alert("The 131 signed Byte converted to Dword values: "+num1)
	alert("The 131 unsigned Byte converted to Dword values: "+num2)

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

You can load and save the long integers from the math Coprocessor, as in the following example.

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

	var num1=154, num2=-425, result=0.0	//	For the TEIMSI compiler distinguish between an integer and a floating 
							//	point number you must add a dot "." into its "var" definition.

	_direct{
		fild  [num1+reg.vo]
		fidiv [num2+reg.vo]
		fstp qword [result+reg.vo]		;	Puts "num1" divided by "num2" into "result"

		fild  [num1+reg.vo]			;	Puts (num1*num1 + num2*num2) into "num1".
		fld st
		fmulp st1, st
		fild  [num2+reg.vo]
		fld st
		fmulp st1, st
		faddp st1, st
		fistp dword [num1+reg.vo]

	}

	alert("154/-425 = " + result)
	alert("154*154 + 425*425 = "+num1)

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


See also the chapters "TEIMSI Variables" and "Basic examples of using Teimsi"


Go to top