Pushing IP *solved*

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Craze Frog
Member
Member
Posts: 368
Joined: Sun Sep 23, 2007 4:52 am

Re: Pushing IP *solved*

Post by Craze Frog »

Sorry everyone, "push $" just doesn't cut it. Why? Not because it isn't the best solution, but because it has absolutely nothing at all whatsoever to do with the question. The question was how to push IP, and while it is a very fine code, "push $" does not have anything to do with IP. It's all in your mind, as they say.
Troy Martin wrote:Sorry if this has been done to death, but how do you push IP to the stack so I can print it out using my hex printing function? I know you can't just use mov ax,ip.

Thanks,
Troy
Very simple. "CALL address_of_hex_printing_function". The IP is now on top of the stack, ready to be accessed by your hex_printing_function.

Of course, that was a very silly answer, but it was what the poster asked for.

With an added function to print_ip it even makes sense:

Code: Select all

print_ip: ; no arguments
push [sp]
jmp hex_printing_function
No return mispredictions, and the code to print the ip becomes simple as well. Just "call print_ip".

The alternative would be to each time call a function to get the ip, then push it, then call the hex printing function. And definetely more fun than having to invent new label names all the time (or using up anonymous labels, so proper label names have to be invented elsewhere).
Post Reply