Guys,
I can do this:
lea eax, pLoadLevel <== this is a procedure address
jmp eax
Fine.
But how could I possibly jump to a label residing inside a procedure? I clearly can get the address of the procedure, so I assume there must be a way to get the address of some label within the code.
SomeProc proc
Im_a_noob:
ret
SomeProc endp
; after some cups of tea...
SomewhereElse proc
mov SaveJumpAddr, Im_a_noob <=== this is the idea (the label resides in a different proc)
ret
SomewhereElse endp
edited to add: Without hardcoding the address offset of the label to the proc entry address?
did you try it??
arent labels global??
youd have to watch for stack balance going from the middle of one procedure to another.
its not normal code design, imo.
edit== I know there are ways, but Im at a loss at the moment...
you could have multiple entry points to the procedure..
2nd entry point being the jump destination. ??
proc1:
some code
jmp jump_dest
more code
stack restore
ret
proc2 : -entry point
code here
jmp_dest: -2nd entry pt
more code
stack restore
ret
but where would it return to???
forgive the sloppiness, hard to type without full size keys..
Would probably be easier and more stable to rethink your code design. Why the need to jump into another procedure?
Maybe the jump could be turned into a call as suggested (2 entry points)
But the trick then would be to return where you expect to be after the (jmp dest) code has executed.
This is giving ME a headache. :lol:
I miss masm and QE (the editor, not the Queen :P )
Okay, final thought...
Maybe the code you want to jump to should be made into its own function/procedure. Then be reused by the 2nd procedure?? Would help solve stack issues.
How big a piece of code we talking here?
Hey Zedd!
You know, even if I change the code design, I still want to try this thing for educational purposes.
In fact, the idea is to hold those addresses and call from within the proc where the labels are (this way, it's safe as usual). But doing this I wouldn't need to compare/jump, only jump.
yes, I tried it.
it would be something like this :
theLabelproc
mov eax, myStruct.labelPtr
jmp eax
foo1:
;code
jmp done
foo2:
;code
jmp done
foo3:
;code
done:
ret
theLabelproc endp
I gather you know this in MASM.
I_Am_A_Label: ; label in procedure scope.
Im_A_Global_Lbl:: ; a global scope label.
What were the results?
You should code a small test piece, if you haven't already..
Then run it from a debugger like ollydbg stepping through the code to observe if the program flow is what you expect it to be.
And watch the stack, to see if you return where you should, as the second procedure exits.
Wish I was setup with a computer, I'm pretty sure it would work with careful coding.
Quote from: hutch-- on April 15, 2018, 05:01:32 PM
Im_A_Global_Lbl:: ; a global scope label.
lol
I knew I was missing something. :redface:
Nevermind my posts above. :icon_redface:
Hutch gave you the answer. Now test it for educational purposes, e.g. jmp from one procedure to another one with a different stack setup. Have some fun, and don't forget: Olly is your friend :bgrin:
Just be careful with grossly unstandard branching when using any debugger, if you start using truly exotic techniques, the debugger may not be able to follow it. IDA Pro can usually follow stuff like this but even it gets the hiccups on really weird stuff.
Quote from: hutch-- on April 15, 2018, 05:01:32 PM
I gather you know this in MASM.
I_Am_A_Label: ; label in procedure scope.
Im_A_Global_Lbl:: ; a global scope label.
I didn't!!!!!!
Never had to use it. that's why it's sometimes good to try different things. Like this one
Quote from: jj2007 on April 15, 2018, 05:19:00 PM
Hutch gave you the answer. Now test it for educational purposes, e.g. jmp from one procedure to another one with a different stack setup. Have some fun, and don't forget: Olly is your friend :bgrin:
Cheers my friend!
So, I'm coding a Game Control center to control and centralize various things in the game. Where music starts, where it ends, fade in, fade out, Check Points etc... things that will be controlled in real time and where logic may change according to the game stage. A script in short.
Game developers in many cases even create a whole new language to do this stuff. So I'm trying to cheat by saving the label's addresses. I'll keep you guys posted
edited to add: Seems to be working rather nicely!!
first you make PROC that suppose to be port of a class and second PROC contains additional code and a jmp to first class,emulating subclassing a class
might be useful for Finite State Machine code,where you jmp to different PROC depending on what state FSM is
jumptable, where each proc is exactly the same size is possible,instead of conditional jump, you load eax with first label and add eax with procsize*number of proc
take a look here for an example
http://masm32.com/board/index.php?topic=7008.15 (http://masm32.com/board/index.php?topic=7008.15)
well if you want it to be easier understood by written in script language, maybe its time to try out making macros?