is this possible...?

Started by
13 comments, last by 21st Century Moose 13 years, 2 months ago

im wanting to read my compiled code at a certain point(which i specify) read it into a buffer, and then be able to copy those bytes to a file for viewing...!

That is a more detailed 'what' but you still haven't given a 'why'. If you want to see the 'machine code' just tell your compiler to generate assembly.

C++: A Dialog | C++0x Features: Part1 (lambdas, auto, static_assert) , Part 2 (rvalue references) , Part 3 (decltype) | Write Games | Fix Your Timestep!

Advertisement

[quote name='nuclear123' timestamp='1298343078' post='4777353']
im wanting to read my compiled code at a certain point(which i specify) read it into a buffer, and then be able to copy those bytes to a file for viewing...!

That is a more detailed 'what' but you still haven't given a 'why'. If you want to see the 'machine code' just tell your compiler to generate assembly.
[/quote]

Why does it matter WHY he wants this? it's none of your business, he's just asking if it can be done.

It CAN be done, and there are multiple ways of doing it. Without getting into assembly, you could use the function pointer idea (assign a function to a function pointer, which will then point to that funciton's location in memory), but it would have to be offset by some value to get somewhere in the middle of the function. i don't know how to do that without assembly.

With assembly, you would add an assembly section to basically perform a jump and link at the end of the seciton, and be sure and store the return address in a register, and copy it to a variable (I don't know x86 way of doing it). In MIPS, it would be something like this:

void *pvLocation;

if (cond)
{
}
asm {
// store old $ra in $t0
add $to, $ra, $0
b Step1
nop
Step2:
// Address at End is now stored in $ra register, copy it to our variable
// but add 4 1st point at end of instruction at End:
addi $ra, $ra, 4
sw $ra, pvLocation
b End
nop
Step1:
jal Step2
nop
End:
add $ra, $t0, $0
}

// now pvLocation store address of right here


Yes, it's a bit of a hack, but, it is possible. You'll probably want to do this via x86 instructions though.

My Gamedev Journal: 2D Game Making, the Easy Way

---(Old Blog, still has good info): 2dGameMaking
-----
"No one ever posts on that message board; it's too crowded." - Yoga Berra (sorta)


Why does it matter WHY he wants this? it's none of your business, he's just asking if it can be done.


It IS important why because this is a game development forum for beginners. This is neither a game development related topic NOR a beginner's topic. Since the OP is POSTING in the beginner's forum, people want to know what he's trying to accomplish in case he's going about it the completely wrong way. He could have very well posted this in General Programming and most likely wouldn't have been pounded with people asking him why he wants to do this. I don't see why people like to be so damn secretive.

Why does it matter WHY he wants this? it's none of your business, he's just asking if it can be done.

Because if he wants to see the machine code he could just tell his compiler to generate assembly meaning he won't need to do some hack to get data he would have to convert back to assembly to even understand. People overcomplicate things all the time. I can't count the number of times where I've got my mind set on going about something a certain way only to eventually realize I could have solved it another, simpler way. Basically, some questions being asked may be making assumptions that should be questioned from time to time and this is particularly true of For Beginners.

C++: A Dialog | C++0x Features: Part1 (lambdas, auto, static_assert) , Part 2 (rvalue references) , Part 3 (decltype) | Write Games | Fix Your Timestep!

Why does it matter WHY he wants this? it's none of your business, he's just asking if it can be done.

It matters why because he's obviously trying to solve some kind of problem, and he's focussing more on how he wants to solve it rather than on what he wants to solve. The solution he's chosen may not be the best one, or may not even be appropriate for solving his problem. "This is what I want to achieve, how do I do it?" is a better line of inquiry than "this is the solution I've chosen to solve some undefined problem, will it work?"

Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls.

This topic is closed to new replies.

Advertisement