VBcoders Browse New Submit Contact Sign In

No account? Register free

Forgot password?

C to ASM a compiler in the development (very early stages)

David Yang  (3 Submissions)   Complete Applications   Visual Basic 5.0   Advanced   Wed 3rd February 2021

THis program translates a subset of C into asm, currently, it supports looping (for, while), conditions (if), maths (+,*,-,/), boolean operators (&&, ||), arrays(partly)
This outputs asm code that should work, the output is currently generic asm code, without conforming to the rules of any specific asm compiler, but that can be easily taken care of.
THis program is written in excel Visual basic, because my version of Visual basic was deleted, and i lost my visual basic installation cd. anyway, you can still run it. TO view the source code, press ALT+F11 to enter a editor, much like the normal VB editor (sorry about that...)
Sample Code Translation is below (in the "Windows API section" below):

API Declarations
int main()
{
msgbox(hitme(5,6));
};
int hitme(int a,int b)
{
a=a*a+b*b;
return a;
};
TRANSLATES TO::
const \\ --String Constants
code \\ --Code Section
\\ --Function: main
Func main
push ebp
mov ebp, esp
Push 6
Push 5
call hitme
Push eax
call msgbox
pop ebp
retn
\\ --Function: hitme
Func hitme
push ebp
mov ebp, esp
add esp, 2
mov ebx, [ebp-12]
mov eax, [ebp-12]
imul ebx
mov ebx, eax
mov ecx, [ebp-8]
mov eax, [ebp-8]
imul ecx
mov ecx, eax
add ecx, ebx
mov [ebp-8], ecx
sub esp, 2
pop ebp
retn

Rate C to ASM a compiler in the development (very early stages) (4(4 Vote))

Download C to ASM a compiler in the development (very early stages)

C to ASM a compiler in the development (very early stages) Comments

No comments yet — be the first to post one!

Post a Comment

0/1000 characters