<title=Default Programming Language (LNG\XS.LDF)>s
<keywords=xs language ldf lng xs.ldf xs.lng>


  The default programming language is described into the XS.LDF file from the
LNG directory. You can change the programming language the compiler use by
changing the XSLNG environment variable (see INSTALL.TXT), or by the
'-l lngfilename' command line parameter (to see the command line syntax, run
xsc.exe or xscl.exe or xsl.exe with no parameters).

  <link=XS.LDF Operators=XS.LDF Operators>
  <link=XS.LDF NEW Operators=XS.LDF NEW Operators>
  <link=XS.LDF Keywords=XS.LDF Keywords>
  <link=XS.LDF Declarations=XS.LDF Declarations>
    <link=XS.LDF Variable Declaration=XS.LDF Variable Declaration>
      <link=XS.LDF Basic Variable Declaration=XS.LDF Basic Variable Declaration>
      <link=XS.LDF Absolute Address Variable Declaration=XS.LDF Absolute Address Variable Declaration>
      <link=XS.LDF Variable Initialization at Declaration Time=XS.LDF Variable Initialization at Declaration Time>
        <link=XS.LDF Variable Initialization With Constants=XS.LDF Variable Initialization With Constants>
        <link=XS.LDF Static Variable Initialization With Data From a File=XS.LDF Static Variable Initialization With Data From a File>
    <link=XS.LDF Function Declaration=XS.LDF Function Declaration>
    <link=XS.LDF Structure Declaration=XS.LDF Structure Declaration>
    <link=XS.LDF Union Declaration=XS.LDF Union Declaration>
    <link=XS.LDF Label Declaration=XS.LDF Label Declaration>
    <link=XS.LDF Declaration Related Keywords=XS.LDF Declaration Related Keywords>
  <link=XS.LDF Directives=XS.LDF Directives>
  <link=XS.LDF Data Types=XS.LDF Data Types>
  <link=XS.LDF Type Modifiers=XS.LDF Type Modifiers>
  <link=XS.LDF Constants=XS.LDF Constants>
  <link=XS.LDF Identifiers=XS.LDF Identifiers>
  <link=XS.LDF Instructions=XS.LDF Instructions>
  <link=XS.LDF Block Instruction=XS.LDF Block Instruction>
  <link=XS.LDF Comment Style=XS.LDF Comment Style>
  <link=XS.LDF How To Include External Files Into Your Program=XS.LDF How To Include External Files Into Your Program>

See also :

  <link=Differences from standard C=Differences from standard C>
  <link=Pascal language influences=Pascal language influences>
  <link=Keyword List=Keyword List>
  <link=Compiler Directives=Compiler Directives>
  <link=Token Conversion Table=Token Conversion Table>
  <link=Token List=Token List>
  <link=Token Data Types=Token Data Types>
  <link=Inline Assembler=Inline Assembler>

<end>

<title=XS.LDF Operators>
<keywords=xs.ldf lng language operator operators>

XS.LDF Operator   C equivalent Syntax *)   Description

+                 +             a+b         add
-                 -             a-b         substract
*                 *             a*b         multiply
/                 /             a/b         divide
!                 !             !a          logical NOT (1 if a is not 0,
                                                         0 if a is 0)
%                 %             a%b         modulo
<<                <<            a<<b        bitwise shift left
>>                >>            a>>b        bitwise shift right
<<<               none          a<<<b       bitwise rotate left
>>>               none          a>>>b       bitwise rotate right
&                 &             a&b         bitwise AND
|                 |             a|b         bitwise OR
^                 ^             a^b         bitwise XOR
&&                &&            a&&b        logical AND
||                ||            a||b        logical OR
^^                none          a^^b        logical XOR
~                 ~             ~a          bitwise NOT
==                ==            a==b        compare if equal
<=                <=            a<=b        compare if less or equal
>=                >=            a>=b        compare if greater or equal
!=                !=            a!=b        compare if not equal
<>                !=            a<>b        compare if not equal
<->               none          a<->b       exchange
=                 =             a=b         assignment
+=                +=            a+=b        assignment a=a+b
-=                -=            a-=b        assignment a=a-b
*=                *=            a*=b        assignment a=a*b
/=                /=            a/=b        assignment a=a/b
%=                %=            a%=b        assignment a=a%b
<<=               <<=           a<<=b       assignment a=a<<b
>>=               >>=           a>>=b       assignment a=a>>b
<<<=              none          a<<<=b      assignment a=a<<<b
>>>=              none          a>>>=b      assignment a=a>>>b
-                 none          -v          change sign Eg. -i;
-                 none          -a          change sign
+                 none          +v          absolute value  Eg. +i;
+                 none          +a          absolute value
<link=sizeof=sizeof>            sizeof        sizeof(c)   size of expression/type


*) a and b are any expressions
   v is a left value expression (commonly a variable)
   c is an expression or a type

<end>
<title=XS.LDF NEW Operators>
<keywords=xs.ldf new lng language operator operators>

XS.LDF Operator   C equivalent Syntax *)   Description

<<<               none          a<<<b       bitwise rotate left
>>>               none          a>>>b       bitwise rotate right
<->               none          a<->b       exchange
<<<=              none          a<<<=b      assignment a=a<<<b
>>>=              none          a>>>=b      assignment a=a>>>b
-                 none          -v          change sign
+                 none          +v          absolute value


*) a and b are any expressions
   v is a left value expression (commonly a variable)

<end>

<title=XS.LDF Directives>
<keywords=xs.ldf ldf lng language directive directives include linkwith link>

See also : <link=Compiler Directives=Compiler Directives>

A compiler directive can be intoduced either indirectly by the pound sign (#)
or directly by tokens.

     #include

     #link   equivalent with
     uses

     #linkwith

     #maxlomem

     #minlomem

     #maxhimem

     #minhimem

     #align

     #define

     #undef

     #ifdef

     #ifndef

     #else

     #endif

<end>

<title=XS.LDF Data Types>
<keywords=data type types char byte int word long dword float real void language lng ldf xs.ldf unsigned signed double>

Basic data types, as defined into xs.ldf language file :

Name           Length (in bytes)        Range

char               1                 -128 ..  127
byte               1                   0  ..  255
unsigned char      1                   0  ..  255
shortint           2               -32768 ..  32767
word               2                   0  ..  65535
unsigned shortint  2                   0  ..  65535
unsigned short     2                   0  ..  65535
unsigned short int 2                   0  ..  65535
int                4          -2147483648 ..  2147483647
long               4          -2147483648 ..  2147483647
dword              4                   0  ..  4294967295
unsigned int       4                   0  ..  4294967295
unsigned long      4                   0  ..  4294967295
float              4             -3.4E+38 ..  3.4E+38
double             4             -3.4E+38 ..  3.4E+38
long double        4             -3.4E+38 ..  3.4E+38
void               0

See also :
  <link=XS.LDF Type Modifiers=XS.LDF Type Modifiers>
  <link=Token Data Types=Token Data Types>

<end>

<title=XS.LDF Instructions>
<keywords=instruction instr instructions xs.ldf ldf lng language
for qfor pfor cfor while do inline switch case of else if to step
__emit__ _push_ _pop_ begin end { } then default break continue goto
return with>

See also : <link=Inline Assembler=Inline Assembler>
           <link=Default Programming Language (LNG\XS.LDF)=Default Programming Language (LNG\XS.LDF)>

Instruction         Origin          Keywords or Symbols *)

for                 C,Pascal,Basic  for [to] [step] [do]  <link=for=Description>
qfor                none            none                  <link=quick for=Description>
if                  C,Pascal        if [then] [else]      <link=if=Description>
if                  C,Pascal        ?  [then] [else]      <link=if=Description>
do                  C               do [while]            <link=do=Description>
while               C,Pascal        while [do]            <link=while=Description>
switch **)          C               switch case [default] <link=switch=Description>
case **)            Pascal          case [of]             <link=case=Description>
push                none            _push_                <link=_push_=Description>
pop                 none            _pop_                 <link=_pop_=Description>
inline              Pascal,C        inline                <link=inline=Description>
inline              Pascal,C        __emit__              <link=inline=Description>
goto                Pascal,C        goto                  <link=goto=Description>
goto                Pascal,C        ^                     <link=goto=Description>
call                none            ^^                    <link=call=Description>
return **)          C               return                <link=return=Description>
break **)           C               break                 <link=break=Description>
continue **)        C               continue              <link=continue=Description>
sizeof              C               sizeof                <link=sizeof=Description>
with                Pascal          with [do]             <link=with=Description>

*) keywords put in brackets are optional in syntax
**)  extended instruction

<end>

<title=XS.LDF Keywords>
<keywords=xs.ldf ldf lng language keyword keywords>

Keyword            <link=What is a token?=Token>

__emit__           inline_k           <link=inline=description>
_pop_              pop_k              <link=_pop_=description>
_push_             push_k             <link=_push_=description>
asm                asm_k              <link=Inline Assembler=Inline Assembler>
begin              begin              <link=XS.LDF Block Instruction=XS.LDF Block Instruction>
break              break_k            <link=break=description>
byte               byte_k             <link=XS.LDF Data Types=XS.LDF Data Types>
case               case_k             <link=case=description>
cdecl              cdecl_k            <link=cdecl=description>
char               char_k             <link=XS.LDF Data Types=XS.LDF Data Types>
constructor        startcode_k        <link=startcode=description>
continue           continue_k         <link=continue=description>
default            default_k          <link=switch=switch>
destructor         endcode_k          <link=endcode=description>
do                 do_k               <link=do=description>
dword              dword_k            <link=XS.LDF Data Types=XS.LDF Data Types>
else               else_k             <link=if=description>
end                end                <link=XS.LDF Block Instruction=XS.LDF Block Instruction>
extern             external_k         <link=extern=description>
float              float_k            <link=XS.LDF Data Types=XS.LDF Data Types>
for                for_k              <link=for=description>
function           function_k         <link=function=description>
goto               goto_k             <link=goto=description>
if                 if_k               <link=if=description>
inline             inline_k           <link=inline=description>
int                long_k             <link=XS.LDF Data Types=XS.LDF Data Types>
interrupt          interrupt_k        <link=interrupt=description>
irq                irq_k              <link=irq=description>
local              private_k          <link=private=description>
long               long_k             <link=XS.LDF Data Types=XS.LDF Data Types>
of                 of_k               <link=case=description>
pascal             pascal_k           <link=pascal=description>
private            private_k          <link=private=description>
procedure          procedure_k        <link=procedure=description>
public             public_k           <link=public=description>
return             return_k           <link=return=description>
shortint           int_k              <link=XS.LDF Data Types=XS.LDF Data Types>
short              short_k            <link=XS.LDF Type Modifiers=XS.LDF Type Modifiers>
signed             signed_k           <link=XS.LDF Type Modifiers=XS.LDF Type Modifiers>
sizeof             sizeof_k           <link=sizeof=description>
step               step_k             <link=for=for>
struct             struct_k           <link=XS.LDF Structure Declaration=XS.LDF Structure Declaration>
switch             switch_k           <link=switch=description>
then               then_k             <link=if=description>
to                 to_k               <link=for=description>
typedef            type_k             <link=typedef=description>
union              union_k            <link=XS.LDF Union Declaration=XS.LDF Union Declaration>
unsigned           unsigned_k         <link=XS.LDF Type Modifiers=XS.LDF Type Modifiers>
uses               link               <link=Compiler Directives=Compiler Directives>
void               void_k             <link=XS.LDF Data Types=XS.LDF Data Types>
while              while_k            <link=while=description>
winapi             winapi_k           <link=winapi=description>
with               with_k             <link=with=description>
word               word_k             <link=XS.LDF Data Types=XS.LDF Data Types>

<end>

<title=XS.LDF Block Instruction>
<keywords=ldf language lng xs.ldf block instruction instructions begin end { }>

Pascal Style :   begin
                  <list of instructions>
                 end

C Style      : {
                 <list of instructions>
               }

Mixed        : begin
                 <list of instructions>
               }

               {
                 <list of instructions>
               end

<end>

<title=XS.LDF Comment Style>
<keywords=ldf lng language xs.ldf comment comments>

Comments are C-like :

//

and

/*  ...  */

<end>

<title=XS.LDF Structure Declaration>
<keywords=language xs.ldf ldf lng struc struct structure structures declaration declarations class classes object objects>

Syntax :

  [struct] StructName[:<baselist>]{
     [variable_declarations]
     [function_declarations]
  }

  The struct keyword is optional.
  StructName is the name of the structure.

  <baselist> contains a list of structures that this structure derives from.
  <baselist> is optional.

Three examples follow :

Eg.
      TPoint{              //structure type declaration
         long x,y,z;
      }

      Tpoint  *p1,p2,p3;    //define some structures

      main()
      {
        //...               //other instructions

        p1->x=(p2.x+p3.x)/2; //use structures

        //...
      }

Eg.
      TObject{             //structure type declaration
        long x,y,z,u,v;
        void moveto(long x,y,z);
        void draw();
      }

      void TObject::moveto(long xx,yy,zz)  //define structure functions
      {
        with(this)    //'this' is a pointer to current structure
        {
          x=xx;
          y=yy;
          z=zz;
        }
      }

      void TObject::draw()
      {
        putpixel(this->u,this->v);
      }

      void TObject::project()
      {
        with this do
         begin
           u=x/z;
           v=y/z;
         end;
      }
      //...

      main()
      {
        //...
        TObject o1;

        o1.moveto(10,20,30);

        with(o1){project();draw();}
      }

Eg.  TPixel2D{
        int x,y;
        private:
          moveto(int x,y);
     }

     TPixel3D:TPixel2D{
        int z;
        moveto(int x,y,z);
     }

     TProjPixel:TPixel3D{
        int u,v;
        project();
        draw();
     }

     TPixel2D::moveto(int x,y)
     {
        this->x=x;this->y=y;
     }

     TPixel3D::moveto(int xx,yy,zx)
     {
        with this do {x=xx;y=yy;z=zz;}
     }

     TProjPixel::project()
     {
       u=x/z;v=y/z;
     }

     TProjPixel::draw()
     {
       putpixel(this->u,this->v);
     }

See also :

  <link=XS.LDF Union Declaration=XS.LDF Union Declaration>
  
<end>

<title=XS.LDF Union Declaration>
<keywords=language xs.ldf ldf lng union unions struc struct structure structures declaration declarations class classes object objects>

A union is similar to a struct, except it
allows you to define variables that share
storage space.

 Syntax:
  union [<union name>] {
    <type> <variable names> ;
    ...
  }
  
For example,

  union int_or_long {
    int     i;
    long    l;
  } a_number;

XSCompiler will allocate enough storage in
a_number to accommodate the largest element in
the union.

Unlike a struct, the variables a_number.i and
a_number.l occupy the same location in memory.
Thus, writing into one will overwrite the
other.

Elements of a union are accessed in the same
manner as a struct.

See also :

  <link=XS.LDF Structure Declaration=XS.LDF Structure Declaration>
  

<end>

<title=XS.LDF Constants>
<keywords=xs.ldf ldf lng language const constants constant number nr numeric char character str string>

<link=XS.LDF Numeric Constants=XS.LDF Numeric Constants>
<link=XS.LDF Character Constants=XS.LDF Character Constants>
<link=XS.LDF String Constants=XS.LDF String Constants>

<end>

<title=XS.LDF Numeric Constants>
<keywords=numeric constants constant language>

Numeric constants hierarchy

  * Integer
      +decimal     - 0..9                      1023   =   1023
                   - '0d' +  0..9            0d1023   =   1023
      +hexadecimal - '0x' + 0..9,a..f,A..F   0xab4d   =  43853
                     0..9,a..f,A..F + 'h'    46abh    =  18091
      +binary      - '0b' + 0..1             0b10110  =  22
                     0..1 + 'b'              11001b   =  25
  * Real           - 0..9 + '.' + 0..9       12.0034

See also : <link=XS.LDF Constants=XS.LDF Constants>

<end>

<title=XS.LDF Character Constants>
<keywords=character constants constant language>

   Syntax : ' + character + '
   Eg.    : 'a'

   Special characters :

   '\b'   =  0x08      backspace
   '\t'   =  0x09      tab
   '\n'   =  0x0a      new line
   '\r'   =  0x0d      carriage return
   '\"'   =  "
   '\''   =  '
   '\\'   =  \


See also : <link=XS.LDF Constants=XS.LDF Constants>

<end>

<title=XS.LDF String Constants>
<keywords=string constants constant language>

   Syntax : " + character sequence + "
            ' + character sequence + '
   Eg.    : "John Smith"
            'John Smith'

   The character sequence can contain special characters.

   Eg.    : "First Name : \"John"\nLast Name : \'Smith'"
   Result : First Name : "John"
            Last Name : 'Smith'

See also : <link=XS.LDF Constants=XS.LDF Constants>

<end>

<title=XS.LDF Identifiers>
<keywords=ldf lng language identifier id identifiers>

Identifier = combination of letters,digits and underscore characters.
The first character of an identifier must be a letter or an underscore.

Eg.   John
      John1023
      _John1023
      _1023John
      _1023
      _

See also : <link=Default Programming Language (LNG\XS.LDF)=Default Programming Language (LNG\XS.LDF)>

<end>

<title=for>
<keywords=for instr instruction instructions language cfor pfor>

See also : <link=Default Programming Language (LNG\XS.LDF)=Default Programming Language (LNG\XS.LDF)>

Syntax 1 :  for ( [<expr1>] ; [<expr2>] ; [<expr3>] )<instruction>


Description : 1) evaluate <expr1>
              2) evaluate <expr2>
              3) if <expr2> is false , end for
              4) execute <instruction>
              5) evaluate <expr3>
              6) goto 2)

Eg.   for(i=0,j=100;i<100;i++,j--)printf("i=%d j=%d\n",i,j);

Syntax 2 :

  for <variable> [:]= <expr1> to <expr2> [step <expr3>] [do] <instruction>

Description : 1) evaluate <expr1>
              2) let <variable> = <expr1>
              3) evaluate <expr2>
              4) if <variable> is greater than <expr2>, end for
              5) execute <instruction>
            * 6) evaluate <expr3>
            * 7) add <expr3> to <variable>
              8) goto 3)
 *) if <expr3> is not present, it is considered to be 1

Eg.   for i:=1 to 100 step 2 do printf("i=%d\n",i);
      for i=1 to 100 printf("i=%d\n",i);
      for i=1 to 100 do printf("i=%d\n",i);

<end>

<title=quick for>
<keywords=quick for instruction qfor language>

See also : <link=Default Programming Language (LNG\XS.LDF)=Default Programming Language (LNG\XS.LDF)>

Syntax : <const1>..<const2> : <instruction>

Description : execute <instruction> <const2> - <const1> times.

Eg. : i=0;
      1..100:printf("i=%d\n",i++);

See also : <link=for=for>

<end>

<title=_push_>
<keywords=push _push _push_ instruction language>

See also : <link=Default Programming Language (LNG\XS.LDF)=Default Programming Language (LNG\XS.LDF)>

Syntax : _push_ <expr>

Description : evaluates <expr> and pushes its value into the system stack.

Eg. : _push_ i+2*j;
      _pop_ i;

      _push_(i); //save i
      //modify i
      _pop_(i); //restore i


The value pushed will be 4 bytes long.

Warning : because this instruction uses the system stack, use it carrefully.
Be sure you don't forget to pop the value from the stack, until the end of
the function.

See also : <link=_pop_=_pop_>

<end>

<title=_pop_>
<keywords=pop _pop _pop_ instruction language>

See also : <link=Default Programming Language (LNG\XS.LDF)=Default Programming Language (LNG\XS.LDF)>

Syntax : _pop_ <variable>

Description : pops a 4 byte long value from the system stack and places it
              into <variable>.

Warning : because this instruction uses the system stack, use it carrefully.

Eg. : _push_ i+2*j;
      _pop_ i;

      _push_(i); //save i
      //modify i
      _pop_(i); //restore i

See also : <link=_push_=_push_>

<end>

<title=while>
<keywords=while do instruction language>

See also : <link=Default Programming Language (LNG\XS.LDF)=Default Programming Language (LNG\XS.LDF)>

Syntax : while <expr> [do] <instruction>

Description : 1) evaluate <expr>
              2) if <expr> is 0, end while
              3) execute <instruction>
              4) goto 1)

Eg. :  while(i--)printf("i=%d\n",i);
       while i do begin printf("i=%d\n",i);i++; }

See also : <link=do=do>

<end>

<title=do>
<keywords=do while instruction language>

See also : <link=Default Programming Language (LNG\XS.LDF)=Default Programming Language (LNG\XS.LDF)>

Syntax : do <instruction> [while] <expr>

Description : 1) execute <instruction>
              2) evaluate <expr>
              3) if <expr> is not 0, goto 1)
              4) end do

Eg.  :  do {
             printf("i=%d\n",i);
             i--;
           }while(i>0);

        do printf("i=%d\n",i--) i>0;

See also : <link=while=while>

<end>

<title=inline>
<keywords=inline __emit__ emit instruction language>

See also : <link=Default Programming Language (LNG\XS.LDF)=Default Programming Language (LNG\XS.LDF)>

Syntax : inline   [(] <constlist> [)]
         __emit__ [(] <constlist> [)]

Description : insert a list of constants directly into code.
              <constlist> can contain one or more constants, separated by
              commas.

Eg. :  inline(0xc3);      //insert 'ret' opcode
       inline 0xfb,0xcf;  //insert 'sti' and 'iretd' opcodes

See also : <link=Inline Assembler=Inline Assembler>

<end>

<title=if>
<keywords=if conditional instruction language>

See also : <link=Default Programming Language (LNG\XS.LDF)=Default Programming Language (LNG\XS.LDF)>

Syntax : if <expression> [then] <instruction1>
         ? <expression> [then] <instruction1>
         if <expression> [then] <instruction1> else <instruction2>
         ? <expression> [then] <instruction1> else <instruction2>

Description : 1) evaluate <expression>
              2) if <expression> is not 0, execute <instruction1>
              2') if <expression> is 0, execute <instruction2>
              3) end if

Eg. : if a>0 then printf("a>0");
             else if(a<0)printf("a<0")
                    else printf("a=0");

<end>

<title=goto>
<keywords=goto jump instruction language>

See also : <link=Default Programming Language (LNG\XS.LDF)=Default Programming Language (LNG\XS.LDF)>

Syntax : goto <label>
         goto <expression>

         ^ <label>
         ^ <expression>

Description : Control is unconditionally transferred to the location
              specified either by <label> or <expression>.
              <label> can be declared AFTER the goto instruction.

Eg. :
       again:

       //other instructions

       goto again;
       ^again

       ^EAX;
       ^(address+10)

       func()
       {
       }
       .
       .
       .
       goto func;

See also : <link=call=call>
           <link=XS.LDF Label Declaration=XS.LDF Label Declaration>

<end>

<title=call>
<keywords=call instruction language>

See also : <link=Default Programming Language (LNG\XS.LDF)=Default Programming Language (LNG\XS.LDF)>

Syntax : ^^ <label>
         ^^ <expression>

Description : Issue a near call instruction to the location specified by
              <label> or <expression>.

Eg. : func()
      {
      }
      .
      .
      .

      ^^func;

      ^^(EBX);

      ^^(funcaddress[10]);

See also : <link=goto=goto>

<end>

<title=switch>
<keywords=switch case default instruction language>

See also : <link=Default Programming Language (LNG\XS.LDF)=Default Programming Language (LNG\XS.LDF)>

Syntax : switch <expression>
         {
            case <expression list> : <instruction list 3>
            case <expression interval> : <instruction list 2>
            case <expression interval list> : <instruction list 4>
            ...
            [ default : <default instruction list>]
         }

Description : 1) evaluate <expression>
              2) for every case
                2.1) evaluate expressions from the list or interval
                2.2) if <expression> is equal with a expression from the
                     list, or it's in one of the intervals, then execute
                     the associated instruction list
                2.3) continue with next case
              3) execute default instruction list, if exists.

Eg. : switch(a+b)
      {
        case 0:printf("0");break;
        case 0..b:printf("0..b");break;

        case 'a'..'z','A..'Z','_','0..9':printf("identifier character");break;

        case min..max:printf("in range min..max");break;

        default: printf("default instruction");
      }

See also : <link=case=case>
           <link=break=break>

<end>

<title=return>
<keywords=return instruction language>

See also : <link=Default Programming Language (LNG\XS.LDF)=Default Programming Language (LNG\XS.LDF)>

Syntax : return [<list of expressions>]

Description : Exits immediatly from the currently executing functions to the
              calling routine, optionally returning a number of values equal
              to the number of results the function must return, as declared.

Eg. :  1) func1()
          {
            //other instructions
            if(a>0)return;     //exit from function if a>0
          }

       2) int func2(int a,int b)
          {
            return(a+b);      //exit from func2 and return value of a+b
          }

       3) float,float splitfloat(float f)
          //split a float number into its integer and fractional components
          {
            return ftol(f),f-ftol(f);
          }

<end>

<title=sizeof>
<keywords=sizeof operator language>

See also : <link=Default Programming Language (LNG\XS.LDF)=Default Programming Language (LNG\XS.LDF)>

Syntax : sizeof <expression>
         sizeof <type>

Description : returns the size, in bytes, of the specified expression or type.

Eg. : nitems = sizeof(tab)/sizeof(tab[0]);
      nitems = sizeof(tab)/sizeof(float);
      memset(buf,0,sizeof(buf));
      memset(buf,0,sizeof(int));

   See also : <link=XS.LDF Data Types=XS.LDF Data Types>

<end>

<title=break>
<keywords=break instruction language>

See also : <link=Default Programming Language (LNG\XS.LDF)=Default Programming Language (LNG\XS.LDF)>

Syntax : break ;
         break <constant expression> ;

Description : Passes control to the next statement following the
              innermost or the specified enclosing while,do,for,case or
              switch instruction.

              break(0) has the same effect with break;

Eg. :
                 while (...)
                  {
                    do{

                        for( ....)
                        {
                           break(2); Ŀ
                           break(1); Ŀ 
                           break; Ŀ   
                        }              
                                   <   
                      }while(...)       
                                     < 
                  }                      
                                      <

See also : <link=continue=continue>
           <link=switch=switch>

<end>

<title=continue>
<keywords=continue instruction language>


Syntax : continue ;
         continue <constant expression> ;

Description : Passes control to the end  of the innermost
              or the specified enclosing while,do,for,case or switch
              instruction, at which point the loop continuation is
              re-evaluated.

              continue(0) has the same effect with continue;

Eg. :
                 while (...)
                  {
                    do{

                        for( ....)
                        {

                           continue;   Ŀ
                           continue(1);  Ŀ
                           continue(2);    Ŀ
                        }              <     
                                              
                      }while(...)         <   
                                               
                  }                           <


See also : <link=break=break>

<end>

<title=XS.LDF Label Declaration>
<keywords=label declaration declarations language labels>

See also : <link=Default Programming Language (LNG\XS.LDF)=Default Programming Language (LNG\XS.LDF)>

Syntax :

      identifier:

Description :  Defines a local label, with the specified name.
               This declaration is also accepted by the Inline Assembler,
               into asm statements.

Eg. :  again:

       //other instructions

       goto again;

       asm{
         again:

         //other instructions

         jmp again
       }


See also : <link=goto=goto>
           <link=call=call>
           <link=Inline Assembler=Inline Assembler>

<end>

<title=XS.LDF Declarations>
<keywords=xs.ldf ldf lng language declaration declarations>

 <link=XS.LDF Variable Declaration=XS.LDF Variable Declaration>
 <link=XS.LDF Function Declaration=XS.LDF Function Declaration>
 <link=XS.LDF Label Declaration=XS.LDF Label Declaration>
 <link=XS.LDF Structure Declaration=XS.LDF Structure Declaration>

 <link=XS.LDF Declaration Related Keywords=XS.LDF Declaration Related Keywords>

<end>

<title=XS.LDF Declaration Related Keywords>
<keywords=declaration keywords language declarations>

<link=cdecl=cdecl>
<link=constructor=constructor>
<link=destructor=destructor>
<link=extern=extern>
<link=function=function>
<link=interrupt=interrupt>
<link=irq=irq>
<link=private=local>
<link=private=private>
<link=pascal=pascal>
<link=procedure=procedure>
<link=public=public>
<link=winapi=winapi>
<link=XS.LDF Structure Declaration=struct>

<end>

<title=cdecl>
<keywords=cdecl language c>

See also : <link=XS.LDF Declaration Related Keywords=XS.LDF Declaration Related Keywords>

Syntax 1 :  cdecl <function declaration>

Description : Declares a C-style function (the caller cleans up the stack).

Syntax 2 :  cdecl:

Description : All the following declarations will be C-style.

Eg. :   pascal:

        func1(int a,b);  //Pascal-style

        cdecl func2(int a,b); //C-style

        cdecl:

        pascal func3(int a,b); //Pascal-style

        func4(int a,b); //C-style

See also : <link=pascal=pascal>

<end>

<title=pascal>
<keywords=pascal language>

See also : <link=XS.LDF Declaration Related Keywords=XS.LDF Declaration Related Keywords>

Syntax 1 :  pascal <function declaration>

Description : Declares a Pascal-style function (it will clean up the stack
              on exit). A call to a Pascal-style function will be smaller
              and faster.

Syntax 2 :  pascal:

Description : All the following declarations will be Pascal-style.

Eg. :   pascal:

        func1(int a,b);  //Pascal-style

        cdecl func2(int a,b); //C-style

        cdecl:

        pascal func3(int a,b); //Pascal-style

        func4(int a,b); //C-style

See also : <link=cdecl=cdecl>

<end>

<title=winapi>
<keywords=winapi win windows win32 language function functions>

See also : <link=XS.LDF Declaration Related Keywords=XS.LDF Declaration Related Keywords>

Syntax  :  winapi <function declaration>

Description : Declares a Windows API - style function (it doesn't modify
              EBX,ESI and EDI registers); EBX, EDI and ESI registers are
              pushed at the begining at the function and poped at its end.
              The 'winapi' keyword should be used in association with
              <link=pascal=pascal> keyword.

<end>

<title=extern>
<keywords=extern external language>

See also : <link=XS.LDF Declaration Related Keywords=XS.LDF Declaration Related Keywords>

Syntax : extern <data definition>
         extern <function prototype>

Description : Indicates that the storage place or the function body is
              defined elsewhere (usually in a separate source code module).
              Keyword extern is optional, but recommended for a function
              prototype.

Eg. :   extern int number_of_parameters;
        extern func(int a,b);

See also : <link=private=local>
           <link=private=private>
           <link=public=public>

<end>

<title=private>
<keywords=private local language>

See also : <link=XS.LDF Declaration Related Keywords=XS.LDF Declaration Related Keywords>

Syntax : local <data definition>
         private <data definition>
         local <function prototype>
         private <function prototype>

         local:
         <declarations>       //local declarations
         public:
         <declarations>       //public declarations
         private:
         <declarations>       //local declarations


Description : Indicates a local declaration. Local declarations are not
              visible from another file. Local variables and functions can
              not be accessed from external files. This is similar with
              class' private declaration.

              Local declarations are  usefull if your program is divided
              into multiple files.

              Example :
                in C, if you use in one file the 'i' variable you cannot use
                the 'i' variable in another file. On linking phase, there
                will be 2 different variables with the same name.

                If you make the declarations of the 'i' variable local,
                then that declarations are not visible for the linker,
                so everything will be O.K.

              In conclusion, this is very useful if you want to have some
              variables and functions that mustn't be accessed and are
              not even visible from other files.

              local is the same with private.

              Declarations are by default public.

Eg. :   local  int number_of_parameters;
        private func(int a,b);

See also : <link=extern=extern>
           <link=public=public>

<end>

<title=public>
<keywords=public language>

See also : <link=XS.LDF Declaration Related Keywords=XS.LDF Declaration Related Keywords>

Syntax : public <data definition>
         public <function prototype>

         public:
         <declarations>       //public declarations


Description : Indicates a public declaration. Public declarations are
              visible from another files. Public variables and functions can
              be accessed from external files. This is similar with
              class' public declaration. Use public declarations to make
              an interface with other files.

              Example : You want to create a library. In a library are
                        public functions and variables, that can be used
                        by programs that include the library, and there
                        are internal functions and variables, that must not
                        be accessed by the main program. When you create
                        the library, make first kind of functions and
                        variables public and the second kind <link=private=private>.

              Declarations are public by default.

Eg. :   public int number_of_parameters;

        public func(int a,b);

        public:
        int a,b;
        func2(){
        //...
        }

See also : <link=extern=extern>
           <link=private=private>
           <link=local=local>

<end>

<title=interrupt>
<keywords=interrupt interupt language>

See also : <link=XS.LDF Declaration Related Keywords=XS.LDF Declaration Related Keywords>

Syntax : interrupt <function declaration>

Description : Defines a function as an interrupt handler.
              The function ends with an 'IRETD' instruction.
              The registers are not saved.

Eg. :   #include xtender.xh,stdio.xh

        interrupt int0()
        {
          asm pushad                //save registers
          printf("Divide by 0");
          asm popad                 //restore registers
          exit();                   //exit from program
        }

        main()
        {
           setintnear(0,&int0);     //set your own interrupt handler
           int i=0;
           i=10/i;                  //divide by 0
        }

See also : <link=irq=irq>

<end>

<title=irq>
<keywords=irq language>

See also : <link=XS.LDF Declaration Related Keywords=XS.LDF Declaration Related Keywords>

Syntax : irq <function declaration>

Description : Defines a function as an IRQ handler.

              1)Interrupt flag is cleared.
              2)General and segment registers are saved.

              3)Function code is executed

              4)Segment registers are restored
              5)EOI signal is sent to the IRQ controler.
              6)General registers are restored

              7)Function ends with 'IRETD'

Eg. :   #include xtender.xh,directk.xh,stdio.xh

        dword count;
        irq timer()
        {
          asm mov ds,cs:DSselector  //make ds point to the program data segment
          asm mov es,ESselector     //make es point to the begining of system memory

          printf("timer count=%d\n",count++);
        }

        main()
        {
           dword oldsel,oldofs;
           oldsel,oldofs=getirqvect(0);  //save old IRQ0 handler
           setirqnear(0,&timer);         //set your own IRQ0 handler
           _dk_getch();                  //wait for a key to be pressed
           setirqvect(0,oldsel,oldofs);  //restore old IRQ0 handler
        }

See also : <link=interrupt=interrupt>

<end>

<title=XS.LDF Variable Declaration>
<keywords=xs.ldf ldf lng var variable declaration>

See also : <link=XS.LDF Declarations=XS.LDF Declarations>

<link=XS.LDF Basic Variable Declaration=XS.LDF Basic Variable Declaration>
<link=XS.LDF Absolute Address Variable Declaration=XS.LDF Absolute Address Variable Declaration>
<link=XS.LDF Variable Initialization at Declaration Time=XS.LDF Variable Initialization at Declaration Time>

<link=XS.LDF Declaration Related Keywords=XS.LDF Declaration Related Keywords>

<end>

<title=XS.LDF Basic Variable Declaration>
<keywords=variable declaration>

Syntax :

   <type_var> <var_list>;

Description : Declare a list of variables with the same type - <type_var> .
              <type_var> can be a <link=XS.LDF Data Types=basic data type> or
              a structure type.
              <var_list> contains a list of variables, separated by spaces
              or commas and ended with a semicolon.


Eg. : //simple declaration
      byte a, *b, **c, d[100], *e[100], ***f;

      //declared variables : a - byte
      //                     b - pointer to byte
      //                     c - pointer to pointer to byte
      //                     d - vector of 100 bytes
      //                     e - vector of 100 pointers to byte
      //                     f - pointer to pointer to pointer to byte

See also :

  <link=XS.LDF Absolute Address Variable Declaration=XS.LDF Absolute Address Variable Declaration>
  <link=XS.LDF Variable Initialization at Declaration Time=XS.LDF Variable Initialization at Declaration Time>

<end>

<title=XS.LDF Absolute Address Variable Declaration>
<keywords=absolute addresss variable declaration>

Syntax :

    <variable declaration> = [ absolute address ] ;

Description : The declared variable will have the specified absolute address,
              instead of an address inside program space, like normal
              variables. When the program reads from or writes to variable,
              it will read from or write to the absolute address specified
              at declaration.

Eg. :
        #include stdio.xh

        //declare variable runtime at absolute address 0x46c
        //where the count of 55ms ticks since CPU reset is stored
        //(see ROM-BIOS Data Area for more details)

        dword runtime=[0x46c];

        main()
        {
           int hour,min,sec;

           sec=runtime*55/1000;
           min=sec/60;
           hour=min/60;
           sec-=min*60;
           min-=hour*60;

           printf("runtime = %d 55ms ticks\n(time  %-02d:%-02d:%-02d seconds)\n",runtime,hour,min,sec);
        }



  <link=XS.LDF Basic Variable Declaration=XS.LDF Basic Variable Declaration>
  <link=XS.LDF Variable Initialization at Declaration Time=XS.LDF Variable Initialization at Declaration Time>

<end>

<title=XS.LDF Variable Initialization at Declaration Time>
<keywords=variable file initialization initialize init declaration>

  <link=XS.LDF Variable Initialization With Constants=XS.LDF Variable Initialization With Constants>
  <link=XS.LDF Static Variable Initialization With Data From a File=XS.LDF Static Variable Initialization With Data From a File>

<end>

<title=XS.LDF Variable Initialization With Constants>
<keywords=initialization const constants declaration variable>

A. Simple Initialization

Syntax : <variable declaration> = <expression>

Description : Initialize the declared variable with the value of the specified
              expression. If the variable is static, the expression must
              contain only constants.

Eg. :  int a=10,b,c=20;
       char *c="this is a string"; //initialize pointer c with the address
                                   //of the string

B. Vector Initialization

Syntax : <vector declaration> = { [<expr0>] , [<expr1>] , ... , [<exprn>] }

Description : Initialize the elements of the vector with the specified
              expressions. Vector must be static. Expressions must be
              constant expressions and can contain addresses of other
              variables.

Eg. : int a[10]={1,2,3,4,5,6,7,8,9,10};
      char c[]="This is a string"; //Initialize char vector c with the
                                   //specified string. Size of c will be
                                   //the size of the string
      byte d[]={0,1,,2,,,,6};      //d memory map :
                                   //0 1 0 2 0 0 0 6
                                   //d has 7 elements
     char *strings[]={ &string0,
                       &string1,
                       &string2
                     };

C. Matrix Initialization

Syntax :

  <vector declaration> = {
                           { [<expr00>] , [<expr01>] , ... , [<expr0n>] },
                           { [<expr10>] , [<expr11>] , ... , [<expr1n>] },
                           ...
                           { [<exprm0>] , [<exprm1>] , ... , [<exprmn>] }
                         };

Description : Initialize the elements of a m x n matrix with the specified
              expressions. Matrix must be static. Expressions must be
              constant expressions and can contain addresses of other
              variables.

Eg. : int a[3][3]={{1,2,3},{4,,6},{7}};

See also : <link=XS.LDF Static Variable Initialization With Data From a File=XS.LDF Static Variable Initialization With Data From a File>


<end>

<title=XS.LDF Static Variable Initialization With Data From a File>
<keywords=static variable initialization file>

This way you can include external files into your program.
See also : <link=XS.LDF How To Include External Files Into Your Program=XS.LDF How To Include External Files Into Your Program>

Syntax : <variable declaration> = < filename > ;
         <variable declaration> = < filename [ offset ] >;

Description : Initialize the declared variable with data from the specified
              file, starting from the 0 or from the specified offset .
              This is VERY useful if you want to include big program
              resources ( text, images, sounds ).

              THE SPECIFIED FILE WILL BE INCLUDED INTO YOUR PROGRAM. So, if
              you change the data file, you have to compile the program again.



Eg. :   #include stdio.xh

        char text[]=<file.txt>; //size of text will be the size of the file

        main()
        {
           printf("%s",text);
        }

See also :  <link=XS.LDF Variable Initialization With Constants=XS.LDF Variable Initialization With Constants>

<end>

<title=XS.LDF How To Include External Files Into Your Program>
<keywords=include extern external files data resource resources program>


  You can include into your program external files (texts, tables, images,
sounds etc) initializing a variable with data from a file.
  (<link=XS.LDF Static Variable Initialization With Data From a File=XS.LDF Static Variable Initialization With Data From a File>)

A. You want to include a text file (mytext.txt) with an unknown size.

   Step 1. Declare a char buffer with unknown size and initialize it from
           the desired text file.

           char buf[]=<mytext.txt>;

   Step 2. You can get the size of the buf variable (and the size of
           the mytext.txt file) using sizeof operator.

           long size=sizeof(buf);

   Step 3. You can now print the text on the screen.

           puts(buf);

B. You want to include a portion with a certain size

   byte buf[1024]=<myfile.ext>; //include the first 1024 bytes


C. You want to include a portion with an unknown size, starting from a
   specified file offset

   byte buf[]=<myfile.ext[128]>; //include all the file without the first
                                 //128 bytes

D. You want to include a portion with a certain size, starting from a
   specified file offset

   float buf[1024]=<myfile.ext[128]>; //include 1024*4 bytes, starting from
                                      //offset 128


<end>


<title=XS.LDF Function Declaration>
<keywords=func function declaration procedure proc routine language>

See also : <link=Default Programming Language (LNG\XS.LDF)=Default Programming Language (LNG\XS.LDF)>

A. C Style
B. Extended Style
C. Pascal Style


A. C Style

Syntax :  <result type> <funcname> ( <parameter list> ) <instruction>

Description :  A. <result type>
                <result type> can be any type ( maximum 4 bytes long).
                Structures cannot be passed as parameters or returned as
                results. Pointers to structures must be used instead.
                If <result type> is missing, then the function do not return
                any result (the same as if <result type> is void).

               B. <funcname>
                <funcname> is the name of the function (an identifier).

               C. <parameter list>
                <parameter list> is the list of parameters passed to function.
                The list has the same syntax like normal variable declaration.

               D. <instruction>
                 <instruction> can be an expression, an instruction or
                 a block instruction.
                 If <instruction> is not present, then the functions is just
                 declared (and it will be defined later).

Eg.  void func(int a,int b,int c,byte d); //is equivalent to
     func(int a,b,c;byte d); //and
     func(int a,b,c,byte d);

     int suma(int a,int b){ return a+b;} is equivalent to
     int suma(int a,b)return a+b;


B. Extended C Style

 The differences from C style are :

     - the function can return multiple results (not only one)
     - the results can be returned in specified registers
     - default values can be assigned to parameters and results
     - parameters can be passed in registers

 Syntax : <result list> <funcname> ( <parameter list> ) <instruction>

 Description (see also C-Style description):

 <result list> contains <results>, separated by commas. It can be empty.
 <result> syntax :  <type>[ = <register>][ = <constant expression>]

 <constant expression> is the default value associated to the result.
 <register> can be any general register, but its size must be equal to the
 size of the associated <type> .
 By default, the first result is returned into accumulator register
 (EAX/AX/AL - depends on the type of the result), the second result is
 returned into ECX/CX/CL register, and so on, in the following order :
   1st : EAX/AX/AL
   2nd : ECX/CX/CL
   3rd : EDX/DX/DL
   4th : EBX/BX/BL
   5th : ESI/SI
   6th : EDI/DI

 <parameter> syntax : <identifier>[ = <register>][ = <constant expression>]

 <register> can be any general register, but its size must be equal to the
 size of the type of the associated parameter.

 <constant expression> is the default value associated to the parameter.
 If when the function is called, a parameter is missing, it is considered
 to be equal to its default value.

 Eg. :
        int,byte func1(); //the function returns two results
                          // 1st result - int type - EAX register
                          // 2nd result - byte type - CL register

        int=EDX,byte=3 func2(); //the function returns two results
                              // 1st result - int type - EDX register
                              // 2nd result - byte type - BL register
                              //            - default value = 3;

        int=EBX,word=3 func3(int a=ECX,byte b=BH;dword c=EDX=100,d,int e=1)
        {
           return a+b+c+d+e; //the first result is a+b+c+d+e and the second
                             //because is missing from the return instruction
                             //list, it will be 3 (its default value)
        }
          //the function has 5 parameters
          //1st - a - int - passed through ECX register
          //2nd - b - byte - passed through BH register
          //3rd - c - dword - passed through EDX register default value = 100
          //4th - d - dword - passed through stack
          //5th - e - int - passed through stack default value = 1


        x,y=func3(1,2,3,4,5);//The function receives the following parameters
                             // a = 1 (in EDX)
                             // b = 2 (in BH)
                             // c = 3 (in EDX)
                             // d = 4 (in stack)
                             // e = 5 (in stack)
                             //
                             //results : x = first result (in EBX)
                             //          y = second result (in SI) = 3

        x=func3(1,2,,4,5);   //The function receives the following parameters
                             // a = 1 (in EDX)
                             // b = 2 (in BH)
                             // c = 100 (in EDX)
                             // d = 4 (in stack)
                             // e = 5 (in stack)
                             //
                             //results : x = first result (in EBX)

C. Pascal Style

Syntax :

  function <funcname> ( <parameter list> ) : <result type> ; <instruction>
  procedure <funcname> ( <parameter list> ) ; <instruction>

Description : See the above descriptions.

Eg.
     procedure drawpixel(int x,y,byte col);
     begin
       pixelmap[x][y]=col;
     end;

     function getpixel(int x,y):byte;
     {
       return pixelmap[x][y];
     }

<end>

<title=with>
<keywords=with language instruction keyword>

The with instruction is a shorthand method for referencing the fields of
a structure.

Syntax : with <structure_variable> [do] <instruction>

Description : <structure_variable> is an expression that contains the address
              of a structure variable

              Within <instruction> the fields of the specified structure can
              be accessed using only their field indentifiers.

Eg. :
       Tpixel{
         int x,y;
       }

       Tpixel pixel[100];

       with pixel[i] do
          begin
             x++;
             y-=10;
          end

      // is equivalent with :

      pixel[i].x++;
      pixel[i].y-=10;

      // and with :

      with(pixel[i])
      {
        x++;
        y-=10;
      }


<end>

<title=XS.LDF Type Modifiers>
<keywords=signed unsigned long short language>

   Ŀ
    signed,unsigned,long,short (type modifiers) 
   

A type modifier alters the meaning of the base <link=XS.LDF Data Types=data type>
to yield a new type.

Each of these type modifiers can be applied to the base type <link=XS.LDF Data Types=int>.

The modifiers signed and unsigned can also be applied to the base type <link=XS.LDF Data Types=char>.

In addition, long can be applied to double.

When the base type is omitted from a declaration, int is assumed.

 Examples:
  unsigned short int si;   //equivalent with <link=XS.LDF Data Types=word>
  unsigned char      ch;   //equivalent with <link=XS.LDF Data Types=byte>
  signed   int       i;    //equivalent with <link=XS.LDF Data Types=int>
  unsigned long int  l;    //equivalent with <link=XS.LDF Data Types=long>

NOTE : These type modifiers are optional and exist only for C compatibility.

<end>

