Jump to content
  • Advertisement
Sign in to follow this  
3Dgonewild

Pseudo code to bytecode converter ?

This topic is 3498 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites


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, 4
i:
.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


Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!