1

I'm trying to get current address and push it to the stack from inline assembler.
Knowing that in MASM current address is accessed with the Current Location Counter $ operator I tried this code snippet

__asm {
    int 3
    mov eax, $
    push eax
};

but instead it pushes 0
x32dbg
I can't figure out what I'm doing wrong and how can I make it to work. I looked all over the internet and couldn't find anything.

FAMO4S
  • 17
  • 4
  • In position-independent code, `call next_instruction` / `next_instruction: pop eax` works (efficiently since CPUs special-case `call rel32=0` to not count for the return-address predictor). Except you don't even want it in a register, you want it on the stack, so just the `call`. [Reading program counter directly](https://stackoverflow.com/q/599968) I'm surprised `mov eax, $` didn't work, but that looks like debugger output from a linked executable, not just a `.obj` with a relocation not filled in. – Peter Cordes Jun 19 '23 at 15:00

0 Answers0