The MASM Forum

Specialised Projects => Compiler Based Assembler => Topic started by: Emil_halim on October 15, 2013, 11:35:23 PM

Title: masm with spinx c--
Post by: Emil_halim on October 15, 2013, 11:35:23 PM
Hi all

sorry if this is a wrong place to post this topic.

because i liked sphinx c-- so much , so i have decided to extend it's features.

i have no source code of c-- , then i made a sphinx c-- translator then let c-- do the rest of work.

first i am working in masm translator to c-- , so you can insert an masm code directly with c-- code with out
or with a little  changes.

here is a working example , it has 3 masm porcs, taken from masm examples and  masm library.



/***************************************
*           Sphinx C--                 * 
*                                      *
*      demo  By Emil Halim             *
*                                      *
***************************************/


#pragma option w32c       //create Windows console EXE.
#pragma option OS         //speed optimization


#includepath "D:\Ext_c--\winlib" 

#include <windows.h> 
#include <MSVCRT.H-->
 
#pragma option ia


//#pragma option LST
#define NULL 0

dword app_path( dword buffer)
{
^^
   ; ---------------------------------------------------------
   ; call this procedure with the address of a 260 byte buffer
   ; return the path with a trailing "\" at address "buffer"
   ; ---------------------------------------------------------

   invoke GetModuleFileName,0,buffer,260

    mov ecx, buffer
    add ecx, eax            ; add length
    add ecx, 1

  @@:                       ; scan backwards to find last "\"
    sub ecx, 1
    cmp BYTE PTR [ecx], "\"
    je @F
    cmp ecx, buffer
    jge @B

  @@:
    mov BYTE PTR [ecx+1], 0 ; truncate string after last
^^   
}

dword app_name(dword buffer)
{
^^
  ; ---------------------------------------------------------
  ; call this procedure with the address of a 260 byte buffer
  ; returns the file name at address "buffer"
  ; ---------------------------------------------------------
    push ebx

    invoke GetModuleFileName,NULL,buffer,260

    mov ecx, buffer
    add ecx, eax                    ; add length
    add ecx, 1

  @@:                               ; scan backwords to find last "\"
    sub ecx, 1
    cmp BYTE PTR [ecx], "\"
    je @F
    cmp ecx, buffer
    jge @B

  @@:
    add ecx, 1
    mov eax, buffer
    or ebx, -1

  @@:                               ; overwrite buffer with file name
    add ebx, 1
    movzx edx, BYTE PTR [ecx+ebx]
    mov [eax+ebx], dl
    test dl, dl
    jnz @B

    pop ebx
  ^^ 
}

#pragma option LST

^^
; #########################################################################

GetCL proc ArgNum:DWORD, ItemBuffer:DWORD

  ; -------------------------------------------------
  ; arguments returned in "ItemBuffer"
  ;
  ; arg 0 = program name
  ; arg 1 = 1st arg
  ; arg 2 = 2nd arg etc....
  ; -------------------------------------------------
  ; Return values in eax
  ;
  ; 1 = successful operation
  ; 2 = no argument exists at specified arg number
  ; 3 = non matching quotation marks
  ; 4 = empty quotation marks
  ; -------------------------------------------------

    LOCAL lpCmdLine      :DWORD
    LOCAL cmdBuffer[192] :BYTE
    LOCAL tmpBuffer[192] :BYTE

    push esi
    push edi

    invoke GetCommandLine
    mov lpCmdLine, eax        ; address command line

  ; -------------------------------------------------
  ; count quotation marks to see if pairs are matched
  ; -------------------------------------------------
    xor ecx, ecx            ; zero ecx & use as counter
    mov esi, lpCmdLine
   
    @@:
      lodsb
      cmp al, 0
      je @F
      cmp al, 34            ; [ " ] character
      jne @B
      inc ecx               ; increment counter
      jmp @B
    @@:

    push ecx                ; save count

    shr ecx, 1              ; integer divide ecx by 2
    shl ecx, 1              ; multiply ecx by 2 to get dividend

    pop eax                 ; put count in eax
    cmp eax, ecx            ; check if they are the same
    je @F
      pop edi
      pop esi
      mov eax, 3            ; return 3 in eax = non matching quotation marks
      ret
    @@:

  ; ------------------------
  ; replace tabs with spaces
  ; ------------------------
    mov esi, lpCmdLine
    lea edi, cmdBuffer

    @@:
      lodsb
      cmp al, 0
      je rtOut
      cmp al, 9     ; tab
      jne rtIn
      mov al, 32
    rtIn:
      stosb
      jmp @B
    rtOut:
      stosb         ; write last byte

  ; -----------------------------------------------------------
  ; substitute spaces in quoted text with replacement character
  ; -----------------------------------------------------------
    lea eax, cmdBuffer
    mov esi, eax
    mov edi, eax

    subSt:
      lodsb
      cmp al, 0
      jne @F
      jmp subOut
    @@:
      cmp al, 34
      jne subNxt
      stosb
      jmp subSl     ; goto subloop
    subNxt:
      stosb
      jmp subSt

    subSl:
      lodsb
      cmp al, 32    ; space
      jne @F
        mov al, 254 ; substitute character
      @@:
      cmp al, 34
      jne @F
        stosb
        jmp subSt
      @@:
      stosb
      jmp subSl

    subOut:
      stosb         ; write last byte

  ; ----------------------------------------------------
  ; the following code determines the correct arg number
  ; and writes the arg into the destination buffer
  ; ----------------------------------------------------
    lea eax, cmdBuffer
    mov esi, eax
    lea edi, tmpBuffer

    mov ecx, 0          ; use ecx as counter

  ; ---------------------------
  ; strip leading spaces if any
  ; ---------------------------
    @@:
      lodsb
      cmp al, 32
      je @B

    l2St:
      cmp ecx, ArgNum     ; the number of the required cmdline arg
      je clSubLp2
      lodsb
      cmp al, 0
      je cl2Out
      cmp al, 32
      jne cl2Ovr           ; if not space

    @@:
      lodsb
      cmp al, 32          ; catch consecutive spaces
      je @B

      inc ecx             ; increment arg count
      cmp al, 0
      je cl2Out

    cl2Ovr:
      jmp l2St

    clSubLp2:
      stosb
    @@:
      lodsb
      cmp al, 32
      je cl2Out
      cmp al, 0
      je cl2Out
      stosb
      jmp @B

    cl2Out:
      mov al, 0
      stosb

  ; ------------------------------
  ; exit if arg number not reached
  ; ------------------------------
    .if ecx < ArgNum
      mov edi, ItemBuffer
      mov al, 0
      stosb
      mov eax, 2  ; return value of 2 means arg did not exist
      pop edi
      pop esi
      ret
    .endif

  ; -------------------------------------------------------------
  ; remove quotation marks and replace the substitution character
  ; -------------------------------------------------------------
    lea eax, tmpBuffer
    mov esi, eax
    mov edi, ItemBuffer

    rqStart:
      lodsb
      cmp al, 0
      je rqOut
      cmp al, 34    ; dont write [ " ] mark
      je rqStart
      cmp al, 254
      jne @F
      mov al, 32    ; substitute space
    @@:
      stosb
      jmp rqStart

  rqOut:
      stosb         ; write zero terminator

  ; ------------------
  ; handle empty quote
  ; ------------------
    mov esi, ItemBuffer
    lodsb
    cmp al, 0
    jne @F
    pop edi
    pop esi
    mov eax, 4  ; return value for empty quote
    ret
  @@:

    mov eax, 1  ; return value success

    pop edi
    pop esi

    ret

GetCL endp

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
^^

main()
{
     char  buf[260];
     int k;
   
     app_path(  #buf ); 
     printf("%s\n",#buf);   
     
     app_name(  #buf ); 
     printf("%s\n",#buf);   

     MessageBox(0,"","",0); 
}



Not well , the term  ^^ means that path all the following lines to the translator untill it found an other ^^

also you can path only a line by putting ^ in start of the line.

sooner  i will post a working package of extended sphinx c--     
Title: Re: masm with spinx c--
Post by: Gunther on October 16, 2013, 04:13:20 AM
Emil,

Quote from: Emil_halim on October 15, 2013, 11:35:23 PM
Hi all

sorry if this is a wrong place to post this topic.

because i liked sphinx c-- so much , so i have decided to extend it's features.

Why not? I don't know sphinx C. What is your goal?

Gunther
Title: Re: masm with spinx c--
Post by: Vortex on October 16, 2013, 05:34:44 AM
Sphinx C-- is a language designed to add C features to the assembly languages. You can consider it like the mixture of both of two. The compiler creates small executables.
Title: Re: masm with spinx c--
Post by: Emil_halim on October 16, 2013, 07:19:02 PM

Gunther ,

Quote from: Gunther on October 16, 2013, 04:13:20 AM
  I don't know sphinx C.

as Mr Vortex has mentioned above , sphinx c-- is an intermediate position between Assembler and C.

here is a small example i have posted years ago

/***************************************
*             Sphinx C--               *   
*                                      *
*     strlen demo  By Emil Halim       *
*           23 / 9 / 2011              *
***************************************/

#pragma option w32         //create Windows GUI EXE.
#pragma option OBJ         //create OBJ file
#pragma option OS          //speed optimization 
#pragma option J0          //no startup code.

#includepath "D:\Ext_c--\winlib"
#include <Windows.h> 

#pragma option ia          // allow inline asm
#pragma option LST

extern cdecl _printf();   
#define printf  _printf

extern cdecl _strlen();
#define strlen _strlen 

int strlen1(char* pStr)
{
    EAX=0;
    while(byte *pStr !=0 )
     {
        pStr++;
        EAX++;
     }


int fastcall strlen2(EAX)
{   
    EBX=EAX;
    while(DSBYTE[EAX] !=0 )
     {
        EAX++;
     }
    EAX -= EBX; 


int fastcall strlen3(EAX)      // pure ASM code
{
   MOV EBX,EAX
@lop:
   CMP DSBYTE[EAX],0
   JE  fin
   INC EAX
   JMP lop
@fin:   
   SUB EAX,EBX
}

// *** SSE2 version  from MASM forum***
? aligncode 16
int  fastcall strlen4(EAX) 
{     
    EBX = EAX ;                 // get the string pointer
       LEA ECX, DSDWORD[EAX+16]        // save pointer to string, on par with eax after first loop
EAX &= 0xFFFFFFF0;          // align for use with SSE2
@shiftOK:     
    XORPS XMM0, XMM0                // zero xmm0 for finding zero bytes
@a1: 
    PCMPEQB XMM0, DSQWORD[EAX]      // ---- inner loop -----
    PMOVMSKB EDX, XMM0              // set byte mask in edx
     EAX += 16;                      // len counter (best position here)
TEST EDX,EDX
        JE a1
       if(ECX<=EAX) goto a2;
    ECX -= EAX;                 // get difference, and cancel "misalign flag"
SHR EDX, CL                 // shift invalid
        SHL EDX, CL                     // bits out
JE shiftOK
@a2:   
    BSF EDX, EDX                // bit scan for the index
       SUB EAX, EBX                    // subtract original src pointer
    LEA EAX, DSDWORD[EAX+EDX-16]    // add scan index
}
? aligncode 4

char* testStr = "SPHINX C-- is so easy (an intermediate position between Assembler and C)";

main()
{
_start:   
     printf("string length is %d\n",strlen( testStr )); 
     printf("string length is %d\n",strlen1( testStr ));   
     printf("string length is %d\n",strlen2( testStr ));   
     printf("string length is %d\n",strlen3( testStr ));   
     printf("string length is %d\n",strlen4( testStr ));   
     MessageBox(0,"","",0); 
}



Quote from: Gunther on October 16, 2013, 04:13:20 AM
   What is your goal?

My goal is to revaival sphinx c-- , extend it's features , also to allow other to easy using it so that they do not have to reinvent the wheel  so if you have some masm code just enclosed it with ^^  and insert it with c--
code.

also i will extend it to accept some basic code too.

Vortex,

thank you for your clarification , found some old code in c-- that you giving a help to make c-- work with Masm.
Title: Re: masm with spinx c--
Post by: Vortex on October 16, 2013, 07:23:39 PM
Hi Emil,

You are welcome. By the way, the Sphinx C-- site seems to be not available :

http://c--sphinx.narod.ru/indexe.htm
Title: Re: masm with spinx c--
Post by: Emil_halim on October 16, 2013, 07:34:19 PM
Hi Vortex,

try this link.

http://www.sheker.chat.ru/index_e.htm (http://www.sheker.chat.ru/index_e.htm)
Title: Re: masm with spinx c--
Post by: Vortex on October 16, 2013, 07:35:33 PM
Hi Emil,

Thanks. It works  :t
Title: Re: masm with spinx c--
Post by: Emil_halim on October 16, 2013, 07:39:53 PM

nice , as i mentioned , i will post a full working folder that contains every thing to let you go.

note well there are many compiler there , i am using a ' C-- compiler (v0.239 b26 ) beta version.' one.   
Title: Re: masm with spinx c--
Post by: avcaballero on October 16, 2013, 08:58:42 PM
Hello, I own a copy of original c-- as a gem  :biggrin:, also almost everything from Spnix c-- :t. Though I've never used it, I think it is very interesting. Glad to see that somebody wants to relaunch it  :t

I have had a look to your link, it seems that there isn't anything new yet, isn't it?

I have two suggestions:
* In my opinion, this site is a bit slow, why don't you move to any other faster site? http://dhost.info/ for example seems to be very interesting and free (I have not checked it)
* There are many resources scattered over there, why don't pack all of them?, especially considering that they haven't got a very large size.

Regards
Title: Re: masm with spinx c--
Post by: Emil_halim on October 16, 2013, 09:32:48 PM
Hi avcaballero,

Quote from: avcaballero on October 16, 2013, 08:58:42 PM
I think it is very interesting. Glad to see that somebody wants to relaunch it  :t

very nice , so we can see more sphinx c-- van here .

Quote from: avcaballero on October 16, 2013, 08:58:42 PM
I have had a look to your link, it seems that there isn't anything new yet, isn't it?

I am afraid , the site i posted above is not mine , i have just found it by google.

Quote from: avcaballero on October 16, 2013, 08:58:42 PM
Hello, I own a copy of original c-- as a gem  :biggrin:, also almost everything from Spnix c-- :t.

note well there are some old one will not work with the new winlib , so i collected small of them ,and step by step adding more examples. as mentioned i will post a zip file that having a working stuff.   

Title: Re: masm with spinx c--
Post by: Emil_halim on October 17, 2013, 02:20:40 AM
Hi all,

here is an other test that accepts c proc with VARARG.

/********************************************************************
*                       Sphinx C--                                  * 
*                                                                   *
*                 VarArg test from masm                             *
*                                                                   *
* topic : http://www.masmforum.com/board/index.php?topic=18885.0    *         
*                                                                   *
*********************************************************************/


#pragma option w32c       //create Windows console EXE.
#pragma option OS         //speed optimization


#includepath "D:\Ext_c--\winlib" 

#include <windows.h> 
#include <MSVCRT.H-->
 
#pragma option ia


#pragma option LST
#define NULL 0


^^
; #########################################################################
;
;  this Proc taken from old Masm see the link in the title
;  modifed by Emil to wrok with sphinx c--
;  c-- will not put PROLOGUE/EPILOGUE for (...) so that
;  i used esp to get return address 
; #########################################################################
testproc proc C args:VARARG
    xor eax, eax                ; assume zero args
    mov edx, [esp]              ; get return address
    cmp WORD PTR[edx], 0C483h   ; opcode for add esp,n
    je  @F
    ret
  @@:
    movzx eax, BYTE PTR[edx+2]  ; get value added to esp
    shr eax, 2                  ; divide by 4 for arg count
    ret     
testproc  endp
; #########################################################################
^^

void main()
{
         
     testproc();
     add esp,0;
     printf("%d\n",EAX);
     
     testproc(1);
     add esp,4;
     printf("%d\n",EAX);
     
     testproc(1,2);
     add esp,8;
     printf("%d\n",EAX);
     
     testproc(1,2,3);
     add esp,12;
     printf("%d\n",EAX);
     
     
     testproc(1,2,3,4);
     add esp,16;
     printf("%d\n",EAX);
     
     testproc(1,2,3,4,5);
     add esp,20;
     printf("%d\n",EAX);
     
     testproc(1,2,3,4,5,6);
     add esp,24;
     printf("%d\n\n",EAX);
       
     MessageBox(0,"","",0);
}


Title: Re: masm with spinx c--
Post by: Emil_halim on October 18, 2013, 07:14:27 AM
Hi all,

Here is an alpha version of Ext_c-- , just unzip it and put it in D: driver , the go ahead. 

if you put it in an other one then remember to adjust the path of c-- in cmpl bat file , also adjust winlib path in each example.


here is a masm strlen function and c-- strlen also

/***************************************
*             Sphinx C--               * 
*                                      *
*     strlen demo  By Emil Halim       *
*     23 / 9 / 2011                    *
***************************************/

#pragma option w32c        //create Windows GUI EXE.
#pragma option OS         //speed optimization
#jumptomain NONE   


#includepath "c:\Ext_c--\winlib" 

#include <windows.h> 
#include <MSVCRT.H-->

#pragma option ia

#pragma option LST

char* mystr = "string4";


int strlen1(char* pStr)
{
    EAX=0;
    while(byte *pStr !=0 )
     {
        pStr++;
        EAX++;
     }
}

int fastcall strlen2(EAX)
{   
    EBX=EAX;
    while(DSBYTE[EAX] !=0 )
     {
        EAX++;
     }
    EAX -= EBX;
}

? align 4
^^
strlen3 proc item:DWORD

    push    ebx

    mov     eax, item               ; get pointer to string
    lea     edx, [eax+3]            ; pointer+3 used in the end

@@:
    mov     ebx, [eax]              ; read first 4 bytes
    add     eax, 4                  ; increment pointer
    lea     ecx, [ebx-01010101h]    ; subtract 1 from each byte
    not     ebx                     ; invert all bytes
    and     ecx, ebx                ; and these two
    and     ecx, 80808080h
    jz      @B                      ; no zero bytes, continue loop

    test    ecx, 00008080h          ; test first two bytes
    jnz     @F

    shr     ecx, 16                 ; not in the first 2 bytes
    add     eax, 2

@@:
    shl     cl, 1                   ; use carry flag to avoid branch
    sbb     eax, edx                ; compute length

    pop     ebx

strlen3 endp
^^


main()

{
   
     printf("%d\n",strlen ("sphinx c-- & masm are good"));   
     printf("%d\n",strlen1("sphinx c-- & masm are good"));   
     printf("%d\n",strlen2("sphinx c-- & masm are good"));   
     printf("%d\n",strlen3("sphinx c-- & masm are good"));   
     
     MessageBox(0,"","",0);
     
}



enjoy coding with c-- & Masm.
 
Title: Re: masm with spinx c--
Post by: habran on October 18, 2013, 04:54:03 PM
your folder is infected :icon13:
Title: Re: masm with spinx c--
Post by: Emil_halim on October 18, 2013, 05:56:28 PM
Oh... sorry.

thank you habran for this notification.

what anti virus should i use , any help pleas?
Title: Re: masm with spinx c--
Post by: Vortex on October 18, 2013, 07:15:03 PM
Hi Emil,

Seriously, as a coder you should be aware of the damages caused by malwares. Please remove that wikiupload link.

Jotti's malware scan report :

http://virusscan.jotti.org/en/scanresult/8c0eded3abf8c1ccf9a0bbb62c37501b87052504
Title: Re: masm with spinx c--
Post by: Emil_halim on October 18, 2013, 07:57:52 PM
Hi Vortex,

I have no experience of anti virus  Seriously , so i  downloaded  avira anti virus and starting scan my system.

deleted done.

does avira repare  that problems. 
Title: Re: masm with spinx c--
Post by: TWell on October 18, 2013, 08:17:49 PM
I use Avast free scanner, no actual virus in that zip ?
That might be heuristic problem again ?
So, what file inside zip is infected ?
Colfire.exe ??

VirusTotal (https://www.virustotal.com/) Detection ratio: 4 / 48

CAT-QuickHeal    (Suspicious) - DNAScan    20131018
Comodo    MalCrypt.Indus!    20131018
TrendMicro    PAK_Generic.001    20131018
TrendMicro-HouseCall    PAK_Generic.001    20131018

@Emil_halim
You could split that package to smaller parts.
Let people download OllyDbg if they wish.


Title: Re: masm with spinx c--
Post by: Vortex on October 18, 2013, 08:19:06 PM
Hi Emil,

Me too, I am an Avira user but no any AV can provide 100% guarantee. Scan all the drives of your computer and be sure that you have a safe programming environment.
Title: Re: masm with spinx c--
Post by: avcaballero on October 18, 2013, 08:55:10 PM
I've got that av warning in some c-- progs examples, though I assumed a false positive. It is very usual in no common tools? in tinyc many times too. One way to avoid such false positive is providing just the code and the compiler... Or just the source codes in "unsafe" exes...

Regards
Title: Re: masm with spinx c--
Post by: Emil_halim on October 18, 2013, 09:01:14 PM
Hi TWell,

after installing anti virus it has detected some virus , just like you post , the file  Colfire.exe  is infected .

but there is 2 exe of that file one is downloaded from net , the site i was posted later of sphinx c-- , and the
other is compiled in my system and has no virus.

any way i will check all exe in the zip file and repost again.

@Vortex

ok , i am doing.

@ avcaballero

thank you , all programs in example was downloaded from the site of c-- , i will check them all.   
   
Title: Re: masm with spinx c--
Post by: Emil_halim on October 18, 2013, 09:34:32 PM

Hi all,

Okay  here is a clean zip file.

download here http://speedy.sh/aDd4G/Ext-c.rar (http://speedy.sh/aDd4G/Ext-c.rar)

Enjoy codeing c-- & masm.
Title: Re: masm with spinx c--
Post by: Vortex on October 18, 2013, 10:18:14 PM
Hi Emil,

Not to be pedantic and no offence but you don't need a site like that to share your code :

QuoteDownload this file for free using Tiny DM manager (exe app)

It asks to use a download manager.

Kindly, could you delete all the executables in your archive? You can attach here the resulting zip archive.
Title: Re: masm with spinx c--
Post by: Emil_halim on October 18, 2013, 10:47:15 PM
Quote from: Vortex on October 18, 2013, 10:18:14 PM
Hi Emil,

Not to be pedantic and no offence but you don't need a site like that to share your code :


all your advises are be welcome any time.

here is an other like http://bcxdx.spoilerspace.com/C--/Ext_c--.rar (http://bcxdx.spoilerspace.com/C--/Ext_c--.rar)
Title: Re: masm with spinx c--
Post by: Emil_halim on October 19, 2013, 01:12:57 AM
Hi all,

Here is an other example that accept a term "uses" with masm procedure.

this masm code is Mr dedndave's code ,  topic : http://masm32.com/board/index.php?topic=1046.0


/*************************************
*           Sphinx C--               * 
*                                    *
*    Uses in proc test from masm     *
*                                    *
*         by Emil_halim              *         
*                                    *
*************************************/


#pragma option w32c       //create Windows console EXE.
#pragma option OS         //speed optimization
#jumptomain NONE          //just jump to main function

#includepath "D:\Ext_c--\winlib" 

#include <windows.h> 
#include <MSVCRT.H-->
 
#pragma option ia        //allow inserte asm instructions


#pragma option LST

^^
; #########################################################################
;  topic :
;  http://masm32.com/board/index.php?topic=1046.0
;
;  it is Mr dedndave's code
; #########################################################################
FillArray PROC MyArray:DWORD USES EBX ESI EDI

        mov     edi, MyArray   
        xor     eax,eax
        mov     ebx,1
        mov     edx,2
        mov     esi,3
        mov     ecx,1000/4

FArry0: mov     [edi],eax
        mov     [edi+4],ebx
        mov     [edi+8],edx
        mov     [edi+12],esi
        add     eax,4
        add     ebx,4
        add     edx,4
        add     esi,4
        add     edi,16
        sub     ecx,1
        jnz     FArry0

FillArray ENDP
; #########################################################################
^^

void main()
{
     int Arry[1000];
               
     FillArray(#Arry);
     
     printf("%d\n",Arry[ 489 * sizeof int ]);  // c-- can not calculate array adress
           
     MessageBox(0,"","",0);
}


Title: Re: masm with spinx c--
Post by: habran on October 19, 2013, 08:16:43 PM
It looks interesting :biggrin:
What about source level debugging?
64 bit?
Title: Re: masm with spinx c--
Post by: Emil_halim on October 20, 2013, 02:39:10 AM
Quote from: habran on October 19, 2013, 08:16:43 PM
It looks interesting :biggrin:

thanks , the interesting thing is that you can use high level asm with Masm code .

ie. instead of writing this

   mov al , byte ptr [esi]


you can do it like that

  al = char [ esi]


Quote from: habran on October 19, 2013, 08:16:43 PM
What about source level debugging?

I am afraid , there is no source level debug with c-- , instead you can use  ollydbg debuger.

Quote from: habran on October 19, 2013, 08:16:43 PM
64 bit?

note well ,the back end is c-- compiler ver 0239 2005 , so c-- will not produce 64 bit.

I so not know about 64bit , but c-- can produce an object file that can be linked with masm linker ,but can
obj32 file linked with 64 bit linker ?
   
Title: Re: masm with spinx c--
Post by: Emil_halim on October 21, 2013, 06:53:52 AM
hi all;

this time i have add c preprocessor  by using cpp exe of gcc.

so what it is good for ?

actually you can use define c macro with masm and c-- to make inline function style.

see this demo

/*************************************
*           Sphinx C--               * 
*                                    *
*       c preprocessor test          *
*                                    *
*         by Emil_halim              *         
*                                    *
*************************************/


#pragma option w32c       //create Windows console EXE.
#pragma option OS         //speed optimization
#jumptomain NONE          //just jump to main function

#includepath "D:\Ext_c--\winlib" 

#include <windows.h> 
#include <MSVCRT.H-->
 
#pragma option ia        //allow inserte asm instructions

#define GetRrandom(min, max) \
        EBX=max; EBX++; sub EBX,min  \
        rand(); div EBX; XCHG EAX,EDX; EAX+=min;   


#pragma option LST

^^
; #########################################################################

;  using c preprocessor  with masm code
;
; #########################################################################

#define addval(a,b)  mov eax,a add eax,b

; #########################################################################
^^

void main()
{
     
     srand( GetTickCount() );
     GetRrandom(12, 25);
     printf("%d\n",EAX);

     addval(30, 40);
     printf("%d\n",EAX);
           
     MessageBox(0,"","",0);
}

 

i will post the second release of Ext_c-- sooner.

enjoy coding masm % c--.
Title: Re: masm with spinx c--
Post by: Emil_halim on October 23, 2013, 05:26:15 AM
Hi all,

also added  Equ masm directive , so Ext_c-- will understand it.

very simple Demo

/*************************************
*           Sphinx C--               * 
*                                    *
*       Equ directive test           *
*                                    *
*         by Emil_halim              *         
*                                    *
*************************************/


#pragma option w32c       //create Windows console EXE.
#pragma option OS         //speed optimization
#jumptomain NONE          //just jump to main function

#includepath "D:\Ext_c--\winlib" 

#include <windows.h> 
#include <MSVCRT.H-->
 
#pragma option ia        //allow inserte asm instructions

#pragma option LST

^^
; #########################################################################

;  using  masm equ directive
;
; #########################################################################


I_am_Ten   equ  0Ah
I_am_Zero  equ  0

Ten:
    mov eax, I_am_Ten
    ret

Zero:
    eax = I_am_Zero
    ret

; #########################################################################
^^

void main()
{
     
     
  ^  invoke Ten
     printf("%d\n",EAX);   
     
     call Zero
     printf("%d\n",EAX);   
           
     MessageBox(0,"","",0);
}
   

if you want to contribute , just test it and post any error you will found.

thanks.   
Title: Re: masm with spinx c--
Post by: Emil_halim on October 25, 2013, 02:24:57 AM
Hi all,

here is the socend release of Ext_c--.

http://bcxdx.spoilerspace.com/C--/Ext_c--.beta_1.rar (http://bcxdx.spoilerspace.com/C--/Ext_c--.beta_1.rar)

Title: Re: masm with spinx c--
Post by: Emil_halim on November 10, 2013, 10:32:54 PM
Hi all;

this time i will show you how to use labels with c--

the demo   ,self explanation.
=====================

/*************************************
*           Sphinx C--               * 
*                                    *
*      using labels with c--         *
*                                    *
*        By  Emil Halim              *
*          10-11-2013                *
*************************************/

#pragma option w32c       //create Windows console EXE.
#pragma option OS         //speed optimization
#jumptomain NONE          //just jump to main function

#includepath "D:\Ext_c--\winlib" 

#include <windows.h> 
#include <MSVCRT.H-->
 
#pragma option ia        //allow inserte asm instructions


#pragma option LST

// declare some c-- variable

byte xSrc = "This is a string, that serves for a variety of purposes, such as testing algos.";

long xNum = 20;

// declare some masm variable via labels

src19: db "1234567890123456789", 0
src20: db "12345678901234567890", 0

num1:  dd 10

// code with masm label

dumy:
   mov eax,1
   ret
   
/******************************************
  some functions will using data label
******************************************/
/***************
s > t >>>  > 0
s = t >>>  = 0
s < t >>>  < 0
***************/
int strcmp1(char *s, char *t)           // pure C code
{
   for( ;byte *s == byte *t; s++, t++)
   if (byte *s == '\0') return 0;
   return  DSBYTE[s] - DSBYTE[t];
}

/**********************
       Testing
**********************/
void main()
{
   
  // move label dumy address into EBX
  EBX = #dumy;
  EBX();         //call it via register
  printf("EAX is = %d\n",  EAX );
 
  call dumy      //call it directly
  printf("EAX is = %d\n",  EAX );
 
  // move lable dumy address into EBX
  MOV EAX,#dumy
  EAX();
  printf("EAX is = %d\n",  EAX );
 
  // compare EAX against label src20 address
  CMP EAX,src20
  CMP EAX,#src20
 
  // move label src20 address into EAX
  LEA EAX,DSWORD[src20]
  printf("str is = %s\n",  EAX );
 
  //compare variable xNum contains against EAX
  CMP EAX,xNum             //compiled to --> cmp eax,[401160h]
 
  // compare label num1 address against EAX
  CMP EAX,num1            //compiled to --> cmp eax,401164h
  CMP EAX,#num1           //compiled to --> cmp eax,401164h
 
  // compare label num1 contains against EAX
  CMP EAX,DSDWORD[num1]   //compiled to --> cmp eax,[401164h]
       
  printf("str#1 = str#2 , result = %d\n",  strcmp1(#src20, #src20) );
 
  printf("str#1 > str#2 , result = %d\n",  strcmp1(#src20, #src19) );
 
  printf("str#1 < str#2 , result = %d\n",  strcmp1(#src19, #src20) );
 
  MessageBox(0,"","",0);
 
}

 

enjoy coding masm & c--.
Title: Re: masm with spinx c--
Post by: Emil_halim on November 11, 2013, 03:02:38 AM
Hi all;

here is  an other demo that showing you how to use Special conditional expressions.

/*************************************
*           Sphinx C--               * 
*                                    *
*  Special conditional expressions   *
*                                    *
*        By  Emil Halim              *
*          10-11-2013                *
*************************************/

#pragma option w32c       //create Windows console EXE.
#pragma option OS         //speed optimization
#jumptomain NONE          //just jump to main function

#includepath "D:\Ext_c--\winlib" 

#include <windows.h> 
#include <MSVCRT.H-->
 
#pragma option ia        //allow inserte asm instructions

#pragma option LST

void main()
{
   int i, a , b; 
   
   a = -10;
   b = 2;
   
   MOV EAX,a
   ADD EAX,b
   MOV i,EAX
   if ( MINUSFLAG ) i = 0;  // if i negatively - to place it in 0
   printf("%d\n", i );
   
   i = 100;
   do {
      i -= b;
   } while( PLUSFLAG ); // a cycle while the variable i is positive
   printf("%d\n", i );
   
   MOV EAX,0xffffffff
   INC EAX             // EAX = 0 , carry = 1
   if ( NOTCARRYFLAG ) EAX = 15;  // if Carry flag set - to place it in 15
   printf("%d\n", EAX );
   
   MOV EAX,0xffffff
   INC EAX
   if ( CARRYFLAG ) EAX = 15;  // if Carry flag set - to place it in 15
   printf("%d\n", EAX );
   
   MOV ax,0fffh
   MOV bx,20h
   MUL bx        // Result: ax=FFE0, dx=1 and overflow = 1 and carry = 1
   if ( OVERFLOW ) EAX = 15; 
   printf("%d\n", EAX );
   
   MessageBox(0,"","",0);
}



enjoy coding masm & c--.
Title: Re: masm with spinx c--
Post by: Emil_halim on November 14, 2013, 06:08:46 AM
Hi all;

this time i am working in adding some features of Basm 'basic to asm' translator that was written by Mr Kevin Diggins.

so that means you can put a block of basic code in your c-- & Masm program.

changing between  basic or Masm or c-- parse is very simple.
1- use !! for inserting basic code.
2- use ^^ for inserting Masm code.

also when you are in basic block and want to pass a certain line for c-- , just prefix it with # symbol.
when you are in basic code too , and want to pass a line to Masm pares , just  prefix it with # symbol then put ^ symbol then your line.

not well , it is a first step.

here is a simple demo

/*************************************
*           Sphinx C--               * 
*                                    *
*   demo of basic block with c--     *
*                                    *
*         by Emil_halim              *         
*                                    *
*************************************/



#pragma option w32c       //create Windows console EXE.
#pragma option OS         //speed optimization
#jumptomain NONE          //just jump to main function


#includepath "D:\Ext_c--\winlib" 

#include <windows.h> 
#include <MSVCRT.H-->
 
#pragma option ia        //allow inserte asm instructions

#pragma option LST
   
   
^^ Masm block start here
; #########################################################################

;  using  masm equ directive
;
; #########################################################################


I_am_Ten   equ  0Ah
I_am_Zero  equ  0

Ten:
    mov eax, I_am_Ten
    ret

Zero:
    eax = I_am_Zero
    ret

; #########################################################################
^^  Masm block end here



void main()
{
     
     
  ^  invoke Ten
     printf("%d\n",EAX);   
     
     call Zero
     printf("%d\n",EAX);
             
   !!  basic block start here
   
     dim k             'this will be global var
         
     while a<20
        while b<8
          while c<5
                incr c
          wend
          incr b
        wend
        incr a
        # ^ mov eax, I_am_Ten  ;this inline that pass to Masm pares
        # printf("%d  %d  %d %d \n",DSDWORD[a],DSDWORD[b],DSDWORD[c],EAX);  // this inline pass to c--     
     wend

   !! basic block end here     
   
     printf("%d\n",DSDWORD[a]); // access to basic var 'a' that declared in basic code block.
     
     MessageBox(0,"","",0);
}


     

when i have some thing soled i will release a new version of Ext_c--.

enjoy coding with c-- & Masm & Basic.
Title: Re: masm with spinx c--
Post by: Emil_halim on November 17, 2013, 04:05:37 AM
HI all;

This demo will show you how to code in c-- close to c style.

it collects some famous c-like functions , you can make a comparison between actual c functions and those.

code of the demo
===============

/*************************************
*           Sphinx C--               * 
*                                    *
*       c style functions            *
*                                    *
*        By  Emil Halim              *
*                                    *
*************************************/

#pragma option w32c       //create Windows console EXE.
#pragma option OS         //speed optimization
#jumptomain NONE          //just jump to main function

#includepath "D:\Ext_c--\winlib" 

#include <windows.h> 
#include <MSVCRT.H-->
 
#pragma option ia        //allow inserte asm instructions

#pragma option LST

// declaring some data as masm to test

src1: db "1", 0
src2: db "12", 0
src3: db "123", 0
src4: db "1234", 0
src5: db "12345", 0
src6: db "123456", 0
src7: db "1234567", 0
src8: db "12345678", 0
src9: db "123456789", 0
src10: db "1234567890", 0
src11: db "12345678901", 0
src12: db "123456789012", 0
src13: db "1234567890123", 0
src14: db "12345678901234", 0
src15: db "123456789012345", 0
src16: db "1234567890123456", 0
src17: db "12345678901234567", 0
src18: db "123456789012345678", 0
src19: db "1234567890123456789", 0
src20: db "12345678901234567890", 0


/************************************************
*
*  some c style functions
*
*************************************************/

int strLen(char* pStr)
{
    char* pStrt;
    pStrt = pStr;
    while(byte *pStr !=0 ) pStr++;
    return  pStr - pStrt; 


int strCmp(char* s, char* t)           
{
   for( ;byte *s == byte *t; s++, t++)
     if (byte *s == '\0') return 0;
   return   *s -  *t;
}

dword strCpy(char* dst, char* src) 
{
  char* rt = dst;
  while (byte *src != 0) 
   {
      *dst = *src;
      dst++; src++;
   }
  return rt;
}

dword strCat( char* dst, char* src )
{
  char* d = dst;
  while (byte *d != 0) d++;
  while (byte *src != '\0') 
   {
      *d = *src;
       d++; src++;
   }
  return dst;
}

dword  strStr( char * str1, char * str2 )
{
        char* s1, *s2;
        char* cp =  str1;
        if ( !*str2 )
            return str1;

        while ( *cp != 0)
         {
                s1 = cp;
                s2 = str2;
                while ( *s1 ) && ( *s2  ) && (! *s1 - *s2) 
                  {
                     s1++; s2++;
                  } 
                if (!*s2)
                        return cp;
                cp++;
        }
        return 0;
}

dword memCpy(char* dst, char* src, dword count)
{
    char* rt = dst;   
    while( count-- )
     {
            *dst = *src;
             dst++; src++;           
     }
    return rt;
}

dword memSet(char* src, dword chr, dword count)
{
    char* rt = src;   
    while( count-- )
     {
             *src = chr;
             src++;           
     }
    return rt;
}

//
//  testing stuff
//

void main()
{
 
   char MyStr[1024];

   // test StrLen function 
   printf("%d\n", strLen( src5 ) );
   
   // test StrCmp function 
   printf("%d\n", strCmp( src10 , src5 ) );

   // test MemCpy function 
   printf("%s\n", memCpy( #MyStr, src5, strLen(src5)) );
   
   // test MemSet function
   printf("%s\n", memSet( #MyStr, 65 , strLen(src5)) );
   
   MessageBox(0,"","",0);
}
   

enjoy coding with c-- & Masm & Basic.
Title: Re: masm with spinx c--
Post by: jj2007 on November 17, 2013, 04:24:54 AM
> int strLen(char* pStr)

Would be interesting to see what it does "under the hood". Could you post the exe of that demo, with symbols if possible? Thanks.
Title: Re: masm with spinx c--
Post by: Emil_halim on November 17, 2013, 06:32:52 AM
ok c-- will produces this , but be aware it is not optimized   

8.tmp 398: int strLen(char* pStr)
00401130 55                       push    ebp
00401131 89E5                     mov     ebp,esp
00401133 83EC04                   sub     esp,4

8.tmp 401: pStrt = pStr;
00401136 8B4508                   mov     eax,[ebp+8]
00401139 8945FC                   mov     [ebp-4],eax

8.tmp 402: while(byte *pStr !=0 ) pStr++;
0040113C E903000000               jmp     401144h
00401141 FF4508                   inc     dword ptr [ebp+8]
00401144 8B5D08                   mov     ebx,[ebp+8]
00401147 803B00                   cmp     byte ptr [ebx],0
0040114A 75F5                     jne     401141h

8.tmp 403: return  pStr - pStrt;
0040114C 8B4508                   mov     eax,[ebp+8]
0040114F 2B45FC                   sub     eax,[ebp-4]
00401152 C9                       leave
00401153 C20400                   ret     4


here is an optimized one

int fastcall strlen2(EAX)
{   
    EBX=EAX;
    while(DSBYTE[EAX] !=0 )
     {
        EAX++;
     }
    EAX -= EBX; 


int fastcall strlen3(EAX)      // pure ASM code
{
   MOV EBX,EAX
@lop:
   CMP DSBYTE[EAX],0
   JE  fin
   INC EAX
   JMP lop
@fin:   
   SUB EAX,EBX
}
Title: Re: masm with spinx c--
Post by: jj2007 on November 17, 2013, 09:10:32 AM
Quote from: Emil_halim on November 17, 2013, 06:32:52 AM
here is an optimized one

Actually, two "optimised" versions:

Intel(R) Celeron(R) M CPU        420  @ 1.60GHz (SSE3)

13915   cycles for 100 * Masm32 len
3987    cycles for 100 * MasmBasic Len
22233   cycles for 100 * C-- strlen (A)
22340   cycles for 100 * C-- strlen (B)
73794   cycles for 100 * C-- non-optimised

13921   cycles for 100 * Masm32 len
3987    cycles for 100 * MasmBasic Len
22235   cycles for 100 * C-- strlen (A)
22334   cycles for 100 * C-- strlen (B)
73723   cycles for 100 * C-- non-optimised


What's the point of writing slow assembler in C--? Or even slower stuff in C-- itself?
Title: Re: masm with spinx c--
Post by: Emil_halim on November 18, 2013, 04:10:29 AM
Quote from: jj2007 on November 17, 2013, 09:10:32 AM
What's the point of writing slow assembler in C--? Or even slower stuff in C-- itself?

first of all if you want optimized code , it is up to to you , i mean you can use SSE2 code to achieve any thing, you can see strlen in different versions and see the speed of each one , in next demo.

so there is no slow asm in c-- , with c-- and my extended c--Ext you can insert any masm code within it , so any code you make with masm you can put it inside
c-- program with or with out Little modification.

my tutorial was written for those familer with c language so that can see how it is easy to mix c & asm code in c--.

any way here is my speed test for strlen in c--

/*************************************
*           Sphinx C--               * 
*                                    *
*      strlen optimization  Demo     *
*                                    *
*************************************/

#pragma option w32c       //create Windows console EXE.
#pragma option OS         //speed optimization
#jumptomain NONE          //just jump to main function

#includepath "D:\Ext_c--\winlib" 

#include <windows.h> 
#include <MSVCRT.H-->
#include "MATH64.H--"
 
#pragma option ia        //allow inserte asm instructions


//#pragma option LST

// masm test data
somestring: db "Hello, this is a simple string intended for testing string algos. It has 100 characters without zero", 0

/***********************************/
//  some strlen functions
/***********************************/


? aligncode 16
dword strLenSSE2(dword src)   // *** SSE2-safe , taken from Masm forum***
{
EBX = EAX = src;           
lea ecx, DSDWORD[eax+16]
EAX &= 0xFFFFFFF0;        
shiftOK:
    xorps xmm0, xmm0        
@a1:
    pcmpeqb xmm0, DSQWORD[eax]
pmovmskb edx, xmm0        
add eax, 16                
test edx, edx
jz a1
cmp ecx, eax            
jle a2
sub ecx, eax            
shr edx, cl               
shl edx, cl                
je shiftOK
@a2:
    bsf edx, edx            
sub eax, ebx           
lea eax, DSDWORD[eax+edx-16]
}
? aligncode 4

int strLenC(char* pStr)     // pure c
{
    char* pStrt;
    pStrt = pStr;
    while(byte *pStr !=0 ) pStr++;
    return  pStr - pStrt; 


int fastcall strLenHLAsm(EAX) // high level asm
{   
    EBX=EAX;
    while(DSBYTE[EAX] !=0 )
     {
        EAX++;
     }
    EAX -= EBX; 


int fastcall strLenAsm(EAX)      // pure ASM code
{
   MOV EBX,EAX
@lop:
   CMP DSBYTE[EAX],0
   JE  fin
   INC EAX
   JMP lop
@fin:   
   SUB EAX,EBX
}

#pragma option LST

^^
strLenMasm proc item:DWORD

    mov     eax, item               ; get pointer to string
    lea     edx, [eax+3]            ; pointer+3 used in the end
    push    ebp
    push    edi
    mov     ebp, 80808080h

  @@:     
;  REPEAT 3
    mov     edi, [eax]              ; read first 4 bytes
    add     eax, 4                  ; increment pointer
    lea     ecx, [edi-01010101h]    ; subtract 1 from each byte
    not     edi                     ; invert all bytes
    and     ecx, edi                ; and these two
    and     ecx, ebp
    jnz     @F
   
    mov     edi, [eax]              ; read first 4 bytes
    add     eax, 4                  ; increment pointer
    lea     ecx, [edi-01010101h]    ; subtract 1 from each byte
    not     edi                     ; invert all bytes
    and     ecx, edi                ; and these two
    and     ecx, ebp
    jnz     @F
   
    mov     edi, [eax]              ; read first 4 bytes
    add     eax, 4                  ; increment pointer
    lea     ecx, [edi-01010101h]    ; subtract 1 from each byte
    not     edi                     ; invert all bytes
    and     ecx, edi                ; and these two
    and     ecx, ebp
    jnz     @F   
;  ENDM
    mov     edi, [eax]              ; read first 4 bytes
    add     eax, 4                  ; 4 increment DWORD pointer
    lea     ecx, [edi-01010101h]    ; subtract 1 from each byte
    not     edi                     ; invert all bytes
    and     ecx, edi                ; and these two
    and     ecx, ebp
    jz      @B                      ; no zero bytes, continue loop
  @@:
    test    ecx, 00008080h          ; test first two bytes
    jnz     @F
    shr     ecx, 16                 ; not in the first 2 bytes
    add     eax, 2
  @@:
    shl     cl, 1                   ; use carry flag to avoid branch
    sbb     eax, edx                ; compute length
    pop     edi
    pop     ebp

strLenMasm endp

^^

/****************************************************/

//
//  speed testing
//

main()
{
  qword  EAXEDX1;
  qword  EAXEDX2;
  int i;
  int count;
 
  count = 10000000;
  SetPriorityClass( GetCurrentProcess(), HIGH_PRIORITY_CLASS);         
 
  // testing SSE2
  RDTSC
  EAXEDX1 = EDX:EAX;
  for(i=0; i< count; i++)
   {
      strLenSSE2(somestring);
   }     
  RDTSC
  EDX:EAX -= EAXEDX1;
  EAXEDX1 = EDX:EAX / count;
  printf("StrLenSSE2  takes  %d\n",  EAXEDX1 );
 
  // testing strLenC
  RDTSC
  EAXEDX1 = EDX:EAX;
  for(i=0; i< count; i++)
   {
      strLenC(somestring);
   }     
  RDTSC
  EDX:EAX -= EAXEDX1;
  EAXEDX1 = EDX:EAX / count;
  printf("strLenC     takes  %d\n",  EAXEDX1 );
 
  // testing strLenHLAsm
  RDTSC
  EAXEDX1 = EDX:EAX;
  for(i=0; i< count; i++)
   {
      strLenHLAsm(somestring);
   }     
  RDTSC
  EDX:EAX -= EAXEDX1;
  EAXEDX1 = EDX:EAX / count;
  printf("strLenHLAsm takes  %d\n",  EAXEDX1 );
 
  // testing strLenAsm
  RDTSC
  EAXEDX1 = EDX:EAX;
  for(i=0; i< count; i++)
   {
      strLenAsm(somestring);
   }     
  RDTSC
  EDX:EAX -= EAXEDX1;
  EAXEDX1 = EDX:EAX / count;
  printf("strLenAsm   takes  %d\n",  EAXEDX1 );
 
  // testing strLenMasm
  RDTSC
  EAXEDX1 = EDX:EAX;
  for(i=0; i< count; i++)
   {
      strLenMasm(somestring);
   }     
  RDTSC
  EDX:EAX -= EAXEDX1;
  EAXEDX1 = EDX:EAX / count;
  printf("strLenMasm  takes  %d\n",  EAXEDX1 );
 
 
  SetPriorityClass(GetCurrentProcess(), NORMAL_PRIORITY_CLASS);
 
  MessageBox(0,"","",0);
}

       

results
======
Intel(R) PentiumR) D CPU 3.00GHz SSE3)
StrLenSSE2   takes  87   
strLenC         takes  677
strLenHLAsm takes  324
strLenAsm     takes  354
strLenMasm   takes  191

thanks.
Title: Re: masm with spinx c--
Post by: Emil_halim on November 19, 2013, 04:59:56 AM
Hi all;

this time i have successfully added Repeat -Endm masm macro to c--Ext.

also instead to use masm PROLOGUE/EPILOGUE  syntax , i have add Pwerbasic FastProc - End FastProc style.

so here is strlen masm with Powerbasic style.

^^
FASTPROC strLenMasm 
    mov     eax, [esp+4]            ; get pointer to string
    lea     edx, [eax+3]            ; pointer+3 used in the end
    push    ebp
    push    edi
    mov     ebp, 80808080h

  @@:     
  REPEAT 3
    mov     edi, [eax]              ; read first 4 bytes
    add     eax, 4                  ; increment pointer
    lea     ecx, [edi-01010101h]    ; subtract 1 from each byte
    not     edi                     ; invert all bytes
    and     ecx, edi                ; and these two
    and     ecx, ebp
    jnz     nxt
  ENDM
    mov     edi, [eax]              ; read first 4 bytes
    add     eax, 4                  ; 4 increment DWORD pointer
    lea     ecx, [edi-01010101h]    ; subtract 1 from each byte
    not     edi                     ; invert all bytes
    and     ecx, edi                ; and these two
    and     ecx, ebp
    jz      @B                      ; no zero bytes, continue loop
  nxt:
    test    ecx, 00008080h          ; test first two bytes
    jnz     @F
    shr     ecx, 16                 ; not in the first 2 bytes
    add     eax, 2
  @@:
    shl     cl, 1                   ; use carry flag to avoid branch
    sbb     eax, edx                ; compute length
    pop     edi
    pop     ebp
   
END FASTPROC
^^


also i have add multi-language comments , i.e. pascal comment,c comment, c++ comment,basic comment,masm comment , PowerBasic comment.

here is a simple example
==================

/***************************
*           Sphinx C--                        * 
*                                                   *
*   multi-language comments        *
*                                                   *
*         by Emil_halim                     *         
*                                                   *
***************************/
/* c one line comment */
// c++ comment
Rem  basic comment
'    basic comment
(* pascal one line comment *)

(* multi line
   pascal comment *)
; Masm comment   
 
#IF 0  ' ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

    PowerBasic comment

#ENDIF ' ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤     


enjoy coding with c-- & Masm & Basic.
Title: Re: masm with spinx c--
Post by: Emil_halim on November 29, 2013, 06:33:06 AM
Hi all,

I have made some progress in adapting  BASM , to work with c--.

so some basic functions are work correctly, such as UCASE$ ,LCASE$ ,str$ , mid$ ,Left$ ,Right$ ,Trim$, Ltrim$ ,
Rtrim$ ,Extract$ , len , instr , incr .

more functions will be adapted sooner.

also added  Prefix - End Prefix Powerbasic keyword style. that allow you to prefix each next line with a specific
some chars.

here is a first demo of BASM

/*************************************
*           Sphinx C--               * 
*                                    *
*      demo0 of BASM basic           *
*                                    *
*         by Emil_halim              *         
*                                    *
*************************************/

#pragma option w32c       //create Windows console EXE.
#pragma option OS         //speed optimization
#jumptomain NONE          //just jump to main function


#includepath "D:\Ext_c--\winlib" 

#include <windows.h> 
#include <MSVCRT.H-->
 
#pragma option ia        //allow inserte asm instructions

void main()
{
   !! basic block start here
   
     na$ = ""
     
     prefix  #
       puts( "What is your name? " );
       gets(na);
     end prefix
     
     do
       print "Hello there ";na$
       incr a
       if a=8 then
            exit loop
       end if
     loop
   
   !!  basic block end here     
   
   MessageBox(0,"","",0);
}


Not well BASM declare a variable when you use it like old Basic.

also when you use a string variable name , such as  'StrVar$' you can access it im Masm block or c-- by the name without '$' sufix. so you can not use StrVar as Number variable.

Enjoy coding with c--,Masm,Basic.   
Title: Re: masm with spinx c--
Post by: Emil_halim on November 29, 2013, 08:28:57 PM
Hi all,

i have added PowerBasic Macro - End Macro style keyword.

here is simple demo
==============


/*************************************
*           Sphinx C--               * 
*                                    *
*      PowerBasic Mcaro demo         *
*                                    *
*         by Emil_halim              *         
*                                    *
*************************************/

#pragma option w32c       //create Windows console EXE.
#pragma option OS         //speed optimization
#jumptomain NONE          //just jump to main function


#includepath "D:\Ext_c--\winlib" 

#include <windows.h> 
#include <MSVCRT.H-->
 
#pragma option ia        //allow inserte asm instructions

#pragma option LST       //create disasemble list

Macro InVok(fnc,arg)
    push arg
    call fnc
End Macro 

Macro MBox(strg)
       MessageBox(0,strg,"",0);
End Macro   
   
^^  Masm block start here
; #########################################################################

;  simple masm proc
;
; #########################################################################

Squr:
    EAX = [esp+4]
    EAX *= EAX
    ret 4
   
; #########################################################################
^^  Masm block end here

void main()
{
     InVok(Squr, 5)
     printf("%d\n",EAX);
     
     MBox("end of program")
}


Enjoy coding with c--,Masm,Basic.   
Title: Re: masm with spinx c--
Post by: Emil_halim on November 30, 2013, 02:05:07 AM
Hi all,

here is an other release of c--Ext , so you can try the previous Examples ,also test the new features.

link http://bcxdx.spoilerspace.com/C--/Ext_c--.beta_2.zip (http://bcxdx.spoilerspace.com/C--/Ext_c--.beta_2.zip)

Enjoy coding with c--,Masm,Basic.   
Title: Re: masm with spinx c--
Post by: Emil_halim on December 02, 2013, 12:43:45 AM
Hi all,

i have found some bugs in c--Ext , i fixed it.

so please , reload the package again.

thanks.

Title: Re: masm with spinx c--
Post by: Emil_halim on December 06, 2013, 04:47:10 AM
Hi all,

in old basic , you can declare a variable when you using it.
BASM is old basic but it easy and attractive language , so it uses the above rolls.
some time i do not want this feature , i first declare a variable then i use it , for that resone   i have added a new
basic directive called "$AutoDecl" to control that. 

here is a simple demo that showing you the using of $AutoDecl directive


/*************************************
*           Sphinx C--               * 
*                                    *
*  basic variable declaring demo     *
*                                    *
*         by Emil_halim              *         
*                                    *
*************************************/

#pragma option w32c       //create Windows console EXE.
#pragma option OS         //speed optimization
#jumptomain NONE          //just jump to main function


#includepath "D:\Ext_c--\winlib" 

#include <windows.h> 
#include <MSVCRT.H-->
 
#pragma option ia        //allow inserte asm instructions

void main()
{
   !! basic block start here
   
    $AutoDecl on  // turn on automatic var declaring
   
    lwr$ = "Welcome"
   
    upr$ = Ucase$( lwr$ ) 
    ?  upr$
   
    $AutoDecl of  // turn of automatic var declaring
    // here you must declar variable by using
    // Dim keyword befor starting use the variable
   
    Dim  Ten , ImStr$
   
    Ten = 10
   
    ImStr$ = "string variable"
   
    ? Ten ; "  " ; ImStr$
   
   !!  basic block end here
   
   MessageBox(0,"","",0);
}


Enjoy coding with c--,Masm,Basic.   
Title: Re: masm with spinx c--
Post by: Emil_halim on December 06, 2013, 10:21:50 PM
Hi all,

this demo will show you , how to use variables those were declaring outside Basic block.

the basic keyword "Extrn" will tell basic parse that to use the variables without putting them in data section.

Demo
=====

/*************************************
*           Sphinx C--               * 
*                                    *
*    Extern basic variable demo      *
*                                    *
*         by Emil_halim              *         
*                                    *
*************************************/

#pragma option w32c       //create Windows console EXE.
#pragma option OS         //speed optimization
#jumptomain NONE          //just jump to main function


#includepath "D:\Ext_c--\winlib" 

#include <windows.h> 
#include <MSVCRT.H-->
 
#pragma option ia        //allow inserte asm instructions

#pragma option LST

void main()
{
   // declare some variables in c--
   // we will use them in Basic block
   static char IamGlobalStr[256];
   dword  IamLocalVar;
   
   !! basic block start here
      // tell Basic about c-- variables
      Extrn IamLocalVar,IamGlobalStr$
     
      IamLocalVar = 100  'access to local c-- variable 'IamLocalVar'
     
      lwr$ = "Welcome"   'declare a basic var and initials it
     
      IamGlobalStr$ =  Mid$( lwr$,4,4 ) + " Equal " + Str$( IamLocalVar )
       
   !!  basic block end here
   
   puts( #IamGlobalStr );
   
   MessageBox(0,"","",0);
}
 

Enjoy coding with c--,Masm,Basic.   
Title: Re: masm with spinx c--
Post by: Emil_halim on December 14, 2013, 02:29:41 AM
Hi all,

I was search this forum for ftoa procedure , then i searched Fasm forum for the same procedure.

I found that ftoa uses itoa procedure in fasm forum , written by Reverend.
so first i convert it to masm syntax.

here is a demo that usus itoa procedure


demo
=====

/*************************************
*           Sphinx C--               * 
*                                    *
*    itoa demo From FASM forum       *
*                                    *
*         by Emil_halim              *         
*                                    *
*************************************/


#pragma option w32c       //create Windows console EXE.
#pragma option OS         //speed optimization
#jumptomain NONE          //just jump to main function

#includepath "D:\Ext_c--\winlib" 

#include <windows.h> 
#include <MSVCRT.H-->
 
#pragma option ia        //allow inserte asm instructions

#pragma option LST

^^
; #########################################################################
;
;
; #########################################################################       

.data
      itoa_digits  db "0123456789ABCDEF", 0
.code
 
;===============================================================================
;       integer to ASCII conversion procedure
;
;       input:
;       number - number to convert Smile
;       radix - base system like 10 for decimal, 16 for hexadecimal, etc.
;       result_buffer - pointer to memory where output will be saved
;       signed - bool value, if number is signed (-2147483646...2147483647)
;                or unsigned (0...4294967295)
;
;       output:
;       no immediate output
;
;       possible errors:
;       radix exceeds 16
;
;       coded by Reverend
;===============================================================================
itoa Proc  number:DWORD, radix:DWORD, result_buffer:DWORD, sgned:DWORD
  local temp_buffer[33]:char

        pushad
        mov     esi, radix
        lea     edi, [#temp_buffer+32]
        mov     ebx, #itoa_digits
        cmp     esi, 16
        ja      error
        std
        xor     al, al
        stosb
        mov     eax, number
        cmp     sgned, TRUE
        jnz     @F
        test    eax, 80000000h
        jz      @F
        neg     eax
    @@:
        xor     edx, edx
        idiv    esi
        xchg    eax, edx
        xlatb
        stosb
        xchg    eax, edx
        test    eax, eax
        jnz     @B
        lea     esi, [edi+1]
        mov     edi, result_buffer
        cld
        cmp     sgned, TRUE
        jnz     @F
        test    number, 80000000h
        jz      @F
        mov     al, "-"
        stosb
    @@:
        lodsb
        stosb
        test    al, al
        jnz     @B
        sub     edi, result_buffer
        lea     eax, [edi-1]
        stc
@ theend:
        cld
        popad
        ret
@ error:
        clc
        jmp     theend
itoa Endp

; #########################################################################
^^

void main()
{
   //buffer that holds string
   char   ss[64];
   
   // test postive value
   itoa(3140,10,#ss,FALSE);           
   puts(#ss);
   
   // test nigative value
   itoa(-3140,10,#ss,TRUE);           
   puts(#ss);
   
   MessageBox(0,"","",0);
}   



Enjoy coding with c--,Masm,Basic.     
Title: Re: masm with spinx c--
Post by: Emil_halim on December 14, 2013, 04:55:10 AM
Hi all,

here is a ftoa procedure , from fasm forum , adapted by me.

demo
====

/*************************************
*           Sphinx C--               * 
*                                    *
*    ftoa demo From FASM forum       *
*                                    *
*         by Emil_halim              *         
*                                    *
*************************************/


#pragma option w32c       //create Windows console EXE.
#pragma option OS         //speed optimization
#jumptomain NONE          //just jump to main function

#includepath "D:\Ext_c--\winlib" 

#include <windows.h> 
#include <MSVCRT.H-->
 
#pragma option ia        //allow inserte asm instructions

#pragma option LST

^^
; #########################################################################
;
;
; #########################################################################       

.data
      itoa_digits  db "0123456789ABCDEF", 0
      ftoa_ten     dd 10
.code
 
;===============================================================================
;       integer to ASCII conversion procedure
;
;       input:
;       number - number to convert Smile
;       radix - base system like 10 for decimal, 16 for hexadecimal, etc.
;       result_buffer - pointer to memory where output will be saved
;       signed - bool value, if number is signed (-2147483646...2147483647)
;                or unsigned (0...4294967295)
;
;       output:
;       length of converted string
;
;       possible errors:
;       radix exceeds 16
;
;       coded by Reverend
;===============================================================================
itoa Proc  number:DWORD, radix:DWORD, result_buffer:DWORD, sgned:DWORD uses edi esi ebx
  local temp_buffer[33]:char

        mov     esi, radix
        lea     edi, [#temp_buffer+32]
        mov     ebx, #itoa_digits
        cmp     esi, 16
        ja      error
        std
        xor     al, al
        stosb
        mov     eax, number
        cmp     sgned, TRUE
        jnz     @F
        test    eax, 80000000h
        jz      @F
        neg     eax
    @@:
        xor     edx, edx
        idiv    esi
        xchg    eax, edx
        xlatb
        stosb
        xchg    eax, edx
        test    eax, eax
        jnz     @B
        lea     esi, [edi+1]
        mov     edi, result_buffer
        cld
        cmp     sgned, TRUE
        jnz     @F
        test    number, 80000000h
        jz      @F
        mov     al, "-"
        stosb
    @@:
        lodsb
        stosb
        test    al, al
        jnz     @B
        sub     edi, result_buffer
        lea     eax, [edi-1]
        stc
@ theend:
        cld
        ret
@ error:
        clc
        jmp     theend
itoa Endp


;===============================================================================
;       float to ASCII conversion procedure
;
;       input:
;       buffer - pointer to memory where output will be saved
;       precision - number of digits after dot
;
;       output:
;       no immediate output
;
;       notes:
;       separate integer and mantisa part with dot '.'
;       so GOOD   123.456
;          WRONG  123,456
;
;       coded by Reverend // HTB + RAG
;===============================================================================
ftoa Proc  buffer:dword, prec:dword uses eax edi ecx

  local status_original:word 
  local status_changed:word
  local integer:dword
  local mantisa:dword
  local sgned:dword

;       --------------------------------
;       set correct precision
;       --------------------------------
        mov     eax, prec
        cmp     eax, 51
        jb      @F
        mov     eax, 51
    @@:
        mov     prec, eax
;       -----------------------------------------------
;       change control wortd of fpu to prevent rounding
;       -----------------------------------------------
        fnstcw  status_original
        mov     ax, status_original
        or      ax, 0000110000000000b
        mov     status_changed, ax
        fldcw   status_changed
;       --------------------------------
;       check if sgned
;       --------------------------------
        xor     eax, eax
        fst     sgned
        test    sgned, 80000000h
        setnz   al
        mov     sgned, eax
;       ----------------------------------
;       cut integer and mantisa separately
;       ----------------------------------
        fld     st(0)
        fld     st(0)                     ; st0 = x, st1 = x
        frndint
        fist    integer                   ; st0 = x, st1 = x
        fabs
        fsubp   st(1), st(0)              ; st0 = mantisa(x)
;       --------------------------------
;       save integer part in buffer
;       --------------------------------
        mov     edi, buffer
        push    sgned
        push    edi
        push    10
        push    integer
        call    itoa
        add     edi, eax
        mov     al, "."
        stosb
;       --------------------------------
;       save mantisa part in buffer
;       --------------------------------
        mov     ecx, prec
        dec     ecx
   @ lop:
        fimul   DSDWORD[#ftoa_ten]
        fld     st(0)
        frndint
        fist    mantisa
        fsubp   st(1), st(0)
        push    0
        push    edi
        push    10
        push    mantisa
        call    itoa
        add     edi, eax
        ftst
        fnstsw  ax
        test    ax, 0100000000000000b
        jz      @F
        test    ax, 0000010100000000b
        jz      fin
    @@:
        loop    lop
        fldcw   status_original
        fimul   DSDWORD[#ftoa_ten]
        fist    mantisa
        push    0
        push    edi
        push    10
        push    mantisa
        call    itoa
      # AL = '\0';
        stosb   
;       --------------------------------
;       restore previous values
;       --------------------------------
   @ fin:
        fstp    st(0)
        stc
     
ftoa Endp



; #########################################################################
^^

void main()
{
   //buffer that holds string
   char   ss[64];
   
   // test postive value 
   ST = 55.44;
   ftoa(#ss,4);
   puts(#ss);
   
   // test nigative value 
   ST = -55.44;
   ftoa(#ss,4);
   puts(#ss);
   
   MessageBox(0,"","",0);
}   



Enjoy coding with c--,Masm,Basic.     
Title: Re: masm with spinx c--
Post by: Emil_halim on December 15, 2013, 06:26:12 AM
Hi all,

I have extended the Proc keyword ,so that you can easily determine the return type of the procedure.

also i added .include keyword the allows you to include files inside masm block.

here is  example showing you the new features.

Demo
====

/*************************************
*           Sphinx C--               * 
*                                    *
*       return value demo            *
*                                    *
*         by Emil_halim              *         
*                                    *
*************************************/


#pragma option w32c       //create Windows console EXE.
#pragma option OS         //speed optimization
#jumptomain NONE          //just jump to main function

#includepath "D:\Ext_c--\winlib" 

#include <windows.h> 
#include <MSVCRT.H-->
 
#pragma option ia        //allow inserte asm instructions

#pragma option LST

^^
; #########################################################################
;  add a return type of your procedure
; #########################################################################       


FSqur Proc x:REAL8 <ST>

fld x
fmul st,st

FSqur Endp


FSqurF Proc x:REAL8 <float>

fld x
fmul st,st

FSqurF Endp

// include ftoa function
.include  ftoa.inc

; #########################################################################
^^

void main()
{
     double ds;
     float  fs;
     char   ss[64];
     
     ds = FSqur(5.0);
     printf("%f\n",ds);     
     
     fs = FSqurF(5.0);
     ftoa(#ss,fs,4);           
     puts(#ss);
                                     
     MessageBox(0,"","",0);
}


  Enjoy coding with c--,Masm,Basic.       
Title: Re: masm with spinx c--
Post by: Emil_halim on December 17, 2013, 06:06:39 AM
Hi all,

this time i will show you that , how is c--Ext is so flexible and easy mixing it with masm.

iin this demo i declared a c-- global variable inside a masm block , also declared a c-- local variable
inside a masm procedure then i uesd them so easy in masm block.     

The demo
========

/*************************************
*           Sphinx C--               * 
*                                    *
*       cmm vars with Masm           *
*                                    *
*         by Emil_halim              *         
*                                    *
*************************************/


#pragma option w32c       //create Windows console EXE.
#pragma option OS         //speed optimization
#jumptomain NONE          //just jump to main function

#includepath "D:\Ext_c--\winlib" 

#include <windows.h> 
#include <MSVCRT.H-->
 
#pragma option ia        //allow inserte asm instructions

#pragma option LST

^^
; #########################################################################
;  add a return type of your procedure
; #########################################################################       
// declare a c-- global variable
# static int gVar= 10;

Fint Proc x:REAL8 <int>
   # int iData;           // declare a local variable
fld x
fistp iData
mov EAX, gVar
iMul iData // return val inside EAX register   
Fint Endp

; #########################################################################
^^

void main()
{

     printf("the int of 60.12 * 10 = %d\n",Fint(60.12));     
                                     
     MessageBox(0,"","",0);
}


NOTE WELL
the prefix # in masm block tells c--Ext to pass the line to c-- parse.

Enjoy coding with c--,Masm,Basic.
Title: Re: masm with spinx c--
Post by: Emil_halim on December 20, 2013, 03:26:41 AM
Hi all,

I've implemented ".const" KeyWord ,so that you can declare a const block at any location in your source code.

you still can declare a const inside masm block without need to use .const , but what is the point here.

well , when you declare a const without using .const block you have to declare it before you can using it,
and when you declare it inside a const block you can use it before the declaration.
   
c--Ext will collects all const blocks and put them in the first in our source code.

here is a simple demo that showing you the point.

Demo
=====

/*************************************
*           Sphinx C--               * 
*                                    *
*       .const keyword test          *
*                                    *
*         by Emil_halim              *         
*                                    *
*************************************/


#pragma option w32c       //create Windows console EXE.
#pragma option OS         //speed optimization
#jumptomain NONE          //just jump to main function

#includepath "D:\Ext_c--\winlib" 

#include <windows.h> 
#include <MSVCRT.H-->

#CleanFiles of           // keep all tempo files after compiling
 
#pragma option ia        //allow inserte asm instructions

#pragma option LST

^^
; #########################################################################

;  using  masm equ directive
;
; #########################################################################


    I_am_Ten   equ  0Ah      ; declare const befor using it

Ten:
    mov eax, I_am_Ten
    ret

Zero:
    eax = I_am_Zero          ; her we use a const befor declare it
    ret
   
.const
    I_am_Zero  equ  0        ; declare a const after we used it

.code   

; #########################################################################
^^

void main()
{
     
     
  ^  invoke Ten
     printf("%d\n",EAX);   
     
     call Zero
     printf("%d\n",EAX);   
           
     MessageBox(0,"","",0);
}


also i add a new directive  #CleanFiles  to C--Ext that allow you to delete or keep tempo files after compiling.

Enjoy coding with c--,Masm,Basic.
Title: Re: masm with spinx c--
Post by: Emil_halim on December 25, 2013, 04:00:46 AM
Hi all

this time , I have added some Fasm syntax compatibility , for example , fasm uses st0 instead of st(0) ,also uses
dword [ ] instead of dword ptr [] ......etc.

here is a atof procedure from fasm forum , with small modification.

AtoF Proc
========

/*************************************
*           Sphinx C--               * 
*                                    *
*    ftoa demo From FASM forum       *
*                                    *
*         by Emil_halim              *         
*                                    *
*************************************/


#pragma option w32c       //create Windows console EXE.
#pragma option OS         //speed optimization
#jumptomain NONE          //just jump to main function

#CleanFiles of

#includepath "D:\Ext_c--\winlib" 

#include <windows.h> 
#include <MSVCRT.H-->
 
#pragma option ia        //allow inserte asm instructions

#pragma option LST

^^
; #########################################################################
;
;
; #########################################################################       

.data
      ftoa_ten     dd 10
.code
       
;===============================================================================
;       ASCII to float conversion procedure
;
;       input:
;       string - pointer to string
;
;       output:
;       st0 - number changed into float
;
;       coded by Reverend // HTB + RAG
;===============================================================================
align   4
Atof  Proc   string:dword uses  ecx esi
           
        fninit
        fild    [ftoa_ten]
        fldz
        fldz
        mov     esi, string
        cmp     byte  [esi], '-'
        jnz     @F
        inc     esi
    @@:
        xor     eax, eax
         
  @integer_part:
        lodsb
        cmp     al, '.'
        jz      mantisa
        test    al, al
        jz      ext
        fmul    st0, st2
        sub     al, '0'
        cmp     al, 9
        jbe     @F
        sub     al, 'A' - '9' - 1
    @@:
        push    eax
        fiadd   dword [esp]
        add     esp, 4
        jmp     integer_part
  @mantisa:
        xor     ecx, ecx
    @@:
        inc     ecx
        lodsb
        test    al, al
        jnz     @B
        cmp     ecx, 10                 ; max 10 digits in mantisa
        jbe     @F
        mov     ecx, 10
    @@:
        std
        sub     esi,2
        fxch    st1
         
  @mantisa_part:
        lodsb
        cmp     al, '.'
        jz      ext
        sub     al, '0'
        cmp     al, 9
        jbe     @F
        sub     al, 'A' - '9' - 1
    @@:
        push    eax
        fiadd   dword [esp]
        add     esp, 4
        fdiv    st0, st2
        jmp     mantisa_part
  @ext:
        cld
        faddp   st1, st0
        ffree   st1
        mov     eax, string
        cmp     byte [eax], '-'
        jnz     @F
        fchs
    @@:
        stc                             ; always returns no error 
        ret
Atof Endp


; #########################################################################
^^



void main()
{
   static char fvl = "-1.0";
         
   Atof(#fvl);
   ESP -= 8;
   fstp DSQWORD [ESP]
   printf("%f\n");
       
   MessageBox(0,"","",0);
}   

   

Enjoy coding with c--,Masm,Basic.
Title: Re: masm with spinx c--
Post by: Emil_halim on December 31, 2013, 06:51:47 AM
Hi all,

I have found some bad things about c-- , it can produces COFF obj file but you can not link it with other c-- code.

c-- can only link obj file created by masm's ML.exe that uses .386 directive.

So that , i extend c--Ext to use Golink linker to solve that problem, new directive made "#Make" for creating
Win , sObj, Cns, Dll file.

c--Ext will use Golink automatically , if you do not use #Make directive then c-- will not use Golink. also if you
used #Make sObj c-- will only create obj file, if you used Win, Cns or Dll c-- will uses Golink.

I have added  another feature to include asm source code as a module , so c--Ext will compile it with ML assembler and inserted in c-- as obj file automatically.     

here is sObj demo
=============

/***************************************
*             Sphinx C--               * 
*                                      *
*     demo compile with c-- as obj     *
*       linked later with Golink       *
*           By  Emil Halim             *
*           30 / 12 / 2013             *
***************************************/

#Make sObj
#pragma option OS

#CleanFiles of

#includepath "D:\Ext_c--\winlib" 
#include <windows.h>
#include <MSVCRT.H-->


void dBox()
{
   $mov eax , 10
   $ret
}

           

here is a asm module demo
===================

; #########################################################################

      .386
      .model flat, stdcall
      option casemap :none   ; case sensitive

; #########################################################################

PUBLIC  nBox

.code

nBox proc

       mov eax , 30
       ret
       
nBox endp

end


here is a win demo
==============

/***************************************
*             Sphinx C--               * 
*                                      *
*        demo compile with c--         *
*         linked with Golink           *
*           By  Emil Halim             *
*           30 / 12 / 2013             *
***************************************/

#Make win 

#pragma option OS

#CleanFiles of

#includepath "D:\Ext_c--\winlib" 
#include <windows.h>

extern WINAPI "msvcrt.dll"
{
void cdecl wsprintf();
}


byte msg = FROM "my.txt";
$DB 0

#include "resurs.rc"   

//insert obj file made by ML
#include "m.obj"     

//insert obj file afetr compile the n.asm source file by ML
#include "n.asm"     

//link obj file that mede with c-- by Golink
#include "fnc2.sObj" 

extern dBox();

void main()
{
      int k;
      byte mm[100];
     
      k =  mBox();
      k += dBox();
      k += nBox();
      wsprintf(#mm,"sum of k = %d",k);
     
      MessageBox(0,#mm,#msg,0);
}


Enjoy coding with c--,Masm,Basic.
Title: Re: masm with spinx c--
Post by: Emil_halim on January 12, 2014, 06:06:43 AM
Hi all,

c--Ext now supports including c source code as module , then it uses Pelles C to compile it to obj file that will be
linked later by GoLink.

here is example that show you how to mix c source code with c-- code, we create a round function in c code then
we include it in c-- code and declare a proto type of round function.

TstRound.c--  file
=============

/***************************************
*             Sphinx C--               * 
*                                      *
*        using c module with c--       *
*         linked with Golink           *
*           By  Emil Halim             *
*           30 / 12 / 2013             *
***************************************/

#Make cnsl 

#pragma option OS

#CleanFiles of

#includepath "D:\Ext_c--\winlib" 
#include <windows.h>

extern WINAPI "msvcrt.dll"
{
  int cdecl printf(char *,...);
}

// let c-- knows about round function
extern int cdecl round(float number);

// insert c source code as module
#include "round.c" 


void main()
{
      int   i;
     
      i = round( 1.2 );     
      printf("Round of 1.2 = %d\n",i);
     
      i = round( 1.8 );     
      printf("Round of 1.8 = %d\n",i);
     
      MessageBox(0,"","",0);
}
   

round.c  file
========

// The round function is supposed to round the float value to the nearest integer
#pragma ftol(inlined)

int round(float number)
{
    return (number >= 0) ? (int)(number + 0.5) : (int)(number - 0.5);
}


Enjoy coding with c--,Masm,Basic.
Title: Re: masm with spinx c--
Post by: Emil_halim on January 13, 2014, 02:40:55 AM
Hi all,

It's time for testing.

here is a beta 3 version of C--Ext  http://bcxdx.spoilerspace.com/C--/Ext_c--.beta_3.zip (http://bcxdx.spoilerspace.com/C--/Ext_c--.beta_3.zip)

Enjoy coding with c--,Masm,Basic.
Title: Re: masm with spinx c--
Post by: Emil_halim on January 14, 2014, 04:45:54 AM
Hi all,

this tutorial will show you how to create a DLL library by c--Ext.

using #Make directive will force c--Ext to use GoLink for producing a DLL file ,you can exprot any function or symbol by using #Exports directive.

also #Exports directive allows you to export functions and variables in asm & c modules.

here is simple example shows you the point.

c module "C_ToUpr.c"
================

// c module of ToUpper function
void _stdcall C_ToUpr(char* aStr)
{
   char* str = aStr;
   
   while( *str != 0)
    {
       if(*str >= 'a' && *str <= 'z')
           *str -= 0x20; 
           
       str++;
    }
}


masm module "M_ToUpr.asm"
======================

; #########################################################################

      .386
      .model flat, stdcall
      option casemap :none   ; case sensitive

; #########################################################################

PUBLIC  M_ToUpr

.code

; masm module of ToUpper function
M_ToUpr Proc aStr:Dword
         mov eax , aStr
         dec eax
      @@:
         add eax, 1
         cmp BYTE PTR [eax], 0
         je @F
         cmp BYTE PTR [eax], "a"
         jb @B
         cmp BYTE PTR [eax], "z"
         ja @B
         sub BYTE PTR [eax], 32
         jmp @B
      @@:
      ret 4   
M_ToUpr Endp

END


c-- module "cUpr.c--"
===============

/***************************************
*             Sphinx C--               * 
*                                      *
*    creating dll from c , asm & c--   *
*         linked with Golink           *
*           By  Emil Halim             *
*           13 / 01 / 2014             *
***************************************/


// force c--Ext to make a DLL output
#Make Dll
 

#pragma option OS

//#CleanFiles of

#includepath "D:\Ext_c--\winlib" 
#include <windows.h>

// just put the name of function to be exported
// and let Golink make it
#Exports Cmm_ToUpr,C_ToUpr,M_ToUpr

// inserts asm module 
#include "M_ToUpr.asm"
// inserts c module
#include "C_ToUpr.c"

// notwell , c--Ext will uses asm to compile asm module
// and pelles c to compile c module then compile c-- file
// golink will export all of then by using Exprts keyword


// c-- module of ToUpper function
void Cmm_ToUpr(char* str)
{
ESI = str;
do
{
$lodsb
if (AL >= 'a') && (AL <= 'z')
{
AL -= 0x20;
DSBYTE[ESI-1] = AL;
}

}while(AL != 0);

}

int main()

    $MOV EAX, 1
}   


and here is a test demo

Testdll.c--
=========

/***************************************
*             Sphinx C--               * 
*                                      *
*         demo testting  dll           *
*         linked with Golink           *
*           By  Emil Halim             *
*           13 / 01 / 2014             *
***************************************/


// force c--Ext to make a console output
#Make cnsl

#includepath "D:\Ext_c--\winlib" 
#include <windows.h>

// let c-- knows about our dll
extern WINAPI "cUpr.dll"
{
void C_ToUpr(char* aStr);
void M_ToUpr(dword aStr);
void Cmm_ToUpr(char* str);
}

extern WINAPI "msvcrt.dll"
{
void cdecl printf();
}

// declare some test msgs
char mes1 = "message1";
char mes2 = "message2";
char mes3 = "message3";

main()
{
   C_ToUpr(#mes1);    //call c function in module "C_ToUpr.c" compiled with Pelles c
   M_ToUpr(#mes2);    //call masm procedure in module "M_ToUpr.asm" compiled with masm
   Cmm_ToUpr(#mes3);  //call c-- function in module "cUpr.c--"
   printf("test 1 = %s\n" , #mes1);
   printf("test 1 = %s\n" , #mes2);
   printf("test 1 = %s\n" , #mes3);
   MessageBox(0,"","",0);   
}


Enjoy coding with c--,Masm,Basic.
Title: Re: masm with spinx c--
Post by: Emil_halim on January 15, 2014, 11:28:19 PM
Hi all,

i have implemented masm Struct keyword , so you can declare a struct then ues it.

here is simple example.


/*************************************
*           Sphinx C--               * 
*                                    *
*       STRUCT KeyWord test          *
*                                    *
*         by Emil_halim              *         
*                                    *
*************************************/


#pragma option w32c       //create Windows console EXE.
#pragma option OS         //speed optimization
#jumptomain NONE          //just jump to main function

#CleanFiles of

#includepath "D:\Ext_c--\winlib" 

#include <windows.h> 
#include <MSVCRT.H-->
 
#pragma option ia        //allow inserte asm instructions

#pragma option LST

^^
; #########################################################################

;  using  masm struct
;
; #########################################################################

point STRUCT
       x DWORD ?
       y DWORD ?
point ENDS

rect STRUCT
      p1 point <>
      p2 point <>
rect ENDS


.data
rc rect <12, 34, 56, 78>

.code
MyTest proc pRect:DWORD
  mov eax, pRect
  # printf("right = %d\n" , EAX.rect.p2.x);
  ret
MyTest endp



; #########################################################################
^^

void main()
{
     
     
  ^  invoke MyTest, offset rc
     
           
     MessageBox(0,"","",0);
}


Enjoy coding with c--,Masm,Basic.
Title: Re: masm with spinx c--
Post by: Emil_halim on February 05, 2014, 05:02:10 AM
Hi all,

Due to some linking stuff bugs that i faced when creating c-- obj file  with GoLink linker.

I have decided that , All Masm [ML]  & Pelles c [pocc] stuff must compiled to Ext.dll then c-- can link to it's functions without any error.

so i created a new directive "#Imports" that allow automatically exports the functions in Ext.dll those will be used and called from c-- code. 

here is a simple example showing you the idea

Pelles c code [test.c]
===============




__declspec(naked) unsigned long* MyTest(int idx)
{
    __asm {
        mov eax,[esp+4]        ; idx arg
        add eax,eax            ; *2
        add eax,eax            ; *4
        add eax,offset label
        ret

        align 4
        label:  dd  1,2,3,4,5,6,7,8
    }
}



c-- code
=======


/*************************************
*           Sphinx C--               * 
*                                    *
*     using asm with Pelles C        *
*                                    *
*         by Emil_halim              *         
*                                    *
*************************************/

#pragma option w32c       //create Windows console EXE.
#pragma option OS         //speed optimization
#jumptomain NONE          //just jump to main function

#CleanFiles of

#includepath "D:\Ext_c--\winlib" 

#include <windows.h> 
#include <MSVCRT.H-->


#imports "C" MyTest
#include "test.c"

 
#pragma option ia        //allow inserte asm instructions

#pragma option LST

void main()
{
   
   printf("%d \n" , MyTest(1) );
   
   MessageBox(0,"","",0);
}



Enjoy coding with c--,Masm,Basic.