Specialised Projects > Compiler Based Assembler

SmallerC--

(1/2) > >>

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

--- 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;
}


--- End code ---

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
 

--- Code: ---
/*
 
  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;
}


--- End code ---

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
=====================

--- Code: ---
/*
 
  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;
}   

--- End code ---

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

Navigation

[0] Message Index

[#] Next page

Go to full version