### Author Topic: masm with spinx c--  (Read 47913 times)

#### Emil_halim

• Member
• Posts: 111
##### Re: masm with spinx c--
« Reply #30 on: November 11, 2013, 03:02:38 AM »
Hi all;

here is  an other demo that showing you how to use Special conditional expressions.
Code: [Select]
`/************************************* *           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 LSTvoid 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--.

#### Emil_halim

• Member
• Posts: 111
##### Re: masm with spinx c--
« Reply #31 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
Code: [Select]
`/************************************* *           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.
« Last Edit: November 14, 2013, 07:59:47 AM by Emil_halim »

#### Emil_halim

• Member
• Posts: 111
##### Re: masm with spinx c--
« Reply #32 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
===============
Code: [Select]
`/************************************* *           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 testsrc1: db "1", 0src2: db "12", 0src3: db "123", 0src4: db "1234", 0src5: db "12345", 0src6: db "123456", 0src7: db "1234567", 0src8: db "12345678", 0src9: db "123456789", 0src10: db "1234567890", 0src11: db "12345678901", 0src12: db "123456789012", 0src13: db "1234567890123", 0src14: db "12345678901234", 0src15: db "123456789012345", 0src16: db "1234567890123456", 0src17: db "12345678901234567", 0src18: db "123456789012345678", 0src19: db "1234567890123456789", 0src20: 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.

#### jj2007

• Member
• Posts: 12453
• Assembler is fun ;-)
##### Re: masm with spinx c--
« Reply #33 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.

#### Emil_halim

• Member
• Posts: 111
##### Re: masm with spinx c--
« Reply #34 on: November 17, 2013, 06:32:52 AM »
ok c-- will produces this , but be aware it is not optimized
Code: [Select]
`8.tmp 398: int strLen(char* pStr)00401130 55                       push    ebp00401131 89E5                     mov     ebp,esp00401133 83EC04                   sub     esp,48.tmp 401: pStrt = pStr;00401136 8B4508                   mov     eax,[ebp+8]00401139 8945FC                   mov     [ebp-4],eax8.tmp 402: while(byte *pStr !=0 ) pStr++;0040113C E903000000               jmp     401144h00401141 FF4508                   inc     dword ptr [ebp+8]00401144 8B5D08                   mov     ebx,[ebp+8]00401147 803B00                   cmp     byte ptr [ebx],00040114A 75F5                     jne     401141h8.tmp 403: return  pStr - pStrt;0040114C 8B4508                   mov     eax,[ebp+8]0040114F 2B45FC                   sub     eax,[ebp-4]00401152 C9                       leave00401153 C20400                   ret     4`
here is an optimized one
Code: [Select]
`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 } `

#### jj2007

• Member
• Posts: 12453
• Assembler is fun ;-)
##### Re: masm with spinx c--
« Reply #35 on: November 17, 2013, 09:10:32 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?

#### Emil_halim

• Member
• Posts: 111
##### Re: masm with spinx c--
« Reply #36 on: November 18, 2013, 04:10:29 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--
Code: [Select]
`/************************************* *           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 16dword 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 4int 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     ebpstrLenMasm 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.

#### Emil_halim

• Member
• Posts: 111
##### Re: masm with spinx c--
« Reply #37 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.
Code: [Select]
`^^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
==================
Code: [Select]
`/*************************** *           Sphinx C--                        *  *                                                   **   multi-language comments        **                                                   **         by Emil_halim                     *          *                                                   ****************************//* c one line comment */// c++ commentRem  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.

#### Emil_halim

• Member
• Posts: 111
##### Re: masm with spinx c--
« Reply #38 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
Code: [Select]
`/************************************* *           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 instructionsvoid 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.

#### Emil_halim

• Member
• Posts: 111
##### Re: masm with spinx c--
« Reply #39 on: November 29, 2013, 08:28:57 PM »
Hi all,

i have added PowerBasic Macro - End Macro style keyword.

here is simple demo
==============
Code: [Select]
`/************************************* *           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.

#### Emil_halim

• Member
• Posts: 111
##### Re: masm with spinx c--
« Reply #40 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.

Enjoy coding with c--,Masm,Basic.

#### Emil_halim

• Member
• Posts: 111
##### Re: masm with spinx c--
« Reply #41 on: December 02, 2013, 12:43:45 AM »
Hi all,

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

thanks.

#### Emil_halim

• Member
• Posts: 111
##### Re: masm with spinx c--
« Reply #42 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

Code: [Select]
`/************************************* *           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 instructionsvoid 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.

#### Emil_halim

• Member
• Posts: 111
##### Re: masm with spinx c--
« Reply #43 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
=====
Code: [Select]
`/************************************* *           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 LSTvoid 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.

#### Emil_halim

• Member
• Posts: 111
##### Re: masm with spinx c--
« Reply #44 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
=====
Code: [Select]
`/************************************* *           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.