News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

SmallerC--

Started by Emil_halim, February 04, 2016, 03:12:46 AM

Previous topic - Next topic

Emil_halim

Hi all

  Here  i am tring to implement some SphinxC features to a SmallerC .

SmallerC is a simple and one pass c compiler , you can found it here https://github.com/alexfru/SmallerC

Some lights of the project
===================
  + allow to mix c and asm code syntax.
  + using High level asm
  + adding some masm features
  + it uses Nasm or Fasm as backend
  + adding some sphinxC features


any way it will be opne source so that any one want to contribute will do it easlly.

I start my modified code with term "Emil stuff" and end it with term "end Emil stuff" , so search for those terms for easy tracking.

will post my uncomleted project by tomorrow.

see you

thanks.

Emil_halim

Hi ALL,

before posting my -'opend source'- uncmopleted project , i want to show this demo first.

It is implementing of local Masm Lable "@@:" , already done for asm code and also for the c code it self.

it also showing you how to call asm code just like the original c function , see the printf and hwo we call MyTest asm lable.

here is the code

/*

  How to compile for Windows:
    smlrcc -win Label.c -o Label.exe

 
*/

// Masm local lable demo

#include <stdio.h>


// here applied to asm code just like Masm
#asm

.code

MyTest:

    jmp @f
    mov EAX , 1
@@:
    mov EAX , 2
    ret
       
#endasm


// here applied to c code it self
int main(void)
{
 
  int k = 20;
  goto @f;
  puts("Hello, World!"); // never printed
   
@@:
  k--;
  while(k>0) goto @b;
  puts("great , is'nt it \n");
   
// MyTest is a asm lable. 
  printf("test = %d",MyTest());
   
  return 0;
}



hope you like it , feel free to add any freaturs you want and share it with us.

will post it by next few hours.


Emil_halim


Hi all

here is the source code of SC-- .

as i mentioned above it is uncompleted project , feel free to add any features.


Emil_halim

Hi all

here is an other demo showing you how to use inline asm with SC--.

implemented  SphinxC--  directive " #pragma option ia+ "

fixed one bug in   doOprnd2 function in asm.c



/*
 
  How to compile for Windows:
    smlrcc -win inlineasm.c -o inlineasm.exe

*/

// inline asm demo

#include <stdio.h>

//using inline asm keywords directly 
#pragma option ia+
unsigned test1()
{
  puts("HI from C ...");
  mov EAX , 1
}
#pragma option ia-

//using inline asm keywords by $
unsigned test2()
{
  $ mov EAX , 2
}

//using inline asm keywords by #asm directive
unsigned test3()
{
  #asm
     mov EAX , 3
  #endasm   
}

//using inline asm keywords of smaller C itself
unsigned test4()
{
  asm("mov eax, 0x4\n");
}

int main(void)
{
 
  printf("test1 = %d\n" , test1() );
  printf("test2 = %d\n" , test2() );
  printf("test3 = %d\n" , test3() );
  printf("test4 = %d\n" , test4() );
 
  puts("great , is not it ?");
  return 0;
}



simple and easy , ..........

Emil_halim

Hi all

Here i have implemented the sphinxC-- keyword "FROM" , which load data from file and inserted it in our outfile.

Example to show you the idea
=====================


/*
 
  How to compile for Windows:
    smlrcc -win from.c -o from.exe

*/

// From Keyword Demo

#include <stdio.h>

extern char msg[];
extern int num;

#asm
.data
num:
    dd 1000

msg:
    from "msg.txt"   
    DB 0
#endasm

int main(void)
{

  puts(msg);
  printf("num = %d\n",num);
  return 0;
}   


simple and easy , ..........

Emil_halim

Hi all

includepath keyword of SphinxC-- is implemented to SC--.

if the '$' found in the first char of string that hold the path , SC-- will relpace to smlrc.exe folder.

here is the example Demo
===================

/*

  How to compile for Windows:
    smlrcc -win incpath.c -o incpath.exe
 
*/

// includepath demo

// here the '$' will replasec with
// full path of smlrc.exe
#includepath "$..\\include1"
#includepath "$..\\include2"
#includepath "D:\\SmallerC-master\\v0100\\include3"
#includepath "D:\\SmallerC-master\\v0100\\include4"

#include "stdio.h"


// here applied to asm code just like Masm
#asm

.code

MyTest:

    jmp @f
    mov EAX , 1
@@:
    mov EAX , 2
    ret
       
#endasm


// here applied to c code it self
int main(void)
{
 
  int k = 20;
  goto @f;
  puts("Hello, World!"); // never printed
   
@@:
  k--;
  while(k>0) goto @b;
  puts("great , is'nt it \n");
   
  printf("test = %d",MyTest());
   
  return 0;
}
 

  simple and easy , ..........

Emil_halim


Hi All

The masm  PROTO keyword is implemented with SC--.

Also masm  OPTION  PROLOGUE/EPILOGUE keyword is implemented with SC--.

so you can mix C asm masm as the following



#include <stdio.h>

int stdcall CTest(int val);   //  usual  C  prototype

MyTest  PROTO stdcall , val : int  // usual masm prototype

#asm

.code

MyTest:

    mov EAX , [ESP+4]
    add EAX , 2
    ret 4   
       
#endasm

int stdcall CTest(int val)
{
  return 1;
}

OPTION PROLOGUE:NONE
OPTION EPILOGUE:NONE

int CTest2(int k)
{
  return k+1;
}

OPTION PROLOGUE:PrologueDef
OPTION EPILOGUE:EpilogueDef

int main(void)
{
       
  printf("test = %d\n",CTest(4));
 
  printf("test = %d\n",MyTest(10));
 
  printf("test = %d\n",CTest2(6));   
  return 0;
}



as you can see mixing C and Masm is

    simple and easy , ..........