Pseudo code to bytecode converter ?

Started by
3 comments, last by 3Dgonewild 15 years, 5 months ago
Hi everyone , i'll try to be quick ... I'm looking for a tool (or something similar) that will convert some pseudo script code into bytecode so i can actually study a little bit better what's going on when , for example ,calling a function , or jumping outside of scope. For example , it should be able to turn this code:


some_variable   a = 1;




into this (just an example):


BC_PUSH addr
BC_SET  addr
BC_POPA get from stack intptr(addr) ( a = 1 )




or something similar ... Any ideas if such a thing exists ???
Advertisement
Quote:Original post by 3Dgonewild
Any ideas if such a thing exists ???
It is called a compiler, and the 'bytecode' it produces is assembly language [smile]

Most compilers have an option to produce assembly, for gcc you provide the -S option on the command line, not sure about MSVC.

Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]

Quote:Original post by 3Dgonewild
calling a function
Even some things as simple as calling a function do different things in different languages and on different platforms. For instance, a function call in C behaves differently from a function call in Objective Caml, and within the C language a __cdecl call is different from an __stdcall.

As swiftcoder explains, most compilers provide a switch to output assembly instructions so you can look at them.
For MSVC you'd want the /FA family of switches. Generally I use /FAs to get intermixed assembly and source code, but you can also use /FAc to get the actual machine code.


Thanks all for the replies , -S flag is exactly what i've been looking for!


Some quick tests :

	int i = 22;



->>>>>>>>>>>>>>>

	.file	"main.cpp".globl i	.data	.align 4	.type	i, @object	.size	i, 4i:	.long	22	.ident	"GCC: (Ubuntu 4.3.2-1ubuntu11) 4.3.2"	.section	.note.GNU-stack,"",@progbits


void jmp_test(){	bool jmp = false;	if(jmp)	{		int something_to_test_jmp = 1;	}else{		int something_to_test_jmp = 0;	}}


->>>>>>>>>>>>>>>

	.file	"main.cpp"	.text.globl _Z8jmp_testv	.type	_Z8jmp_testv, @function_Z8jmp_testv:.LFB2:	pushl	%ebp.LCFI0:	movl	%esp, %ebp.LCFI1:	subl	$16, %esp.LCFI2:	movb	$0, -1(%ebp)	cmpb	$0, -1(%ebp)	je	.L2	movl	$1, -8(%ebp)	jmp	.L4.L2:	movl	$0, -12(%ebp).L4:	leave	ret.LFE2:	.size	_Z8jmp_testv, .-_Z8jmp_testv	.ident	"GCC: (Ubuntu 4.3.2-1ubuntu11) 4.3.2"	.section	.note.GNU-stack,"",@progbits

This topic is closed to new replies.

Advertisement