title: x86 / x64 Using a relative jump to return from a subroutine
body: <p>I'm needing to write a bit of assembly that I will be writing into the address space of another process (already running.)</p>
  
  <p>Essentially what I am wanting to do is every time this assembly is invoked, it will compare a value from the stack to a predefined value and then if it matches the pre defined value I want to call a function whose pointer will be hard coded into the assembly and if not, I want the assembly to essentially do nothing, so return.</p>
  
  <p>So far I have the following (just going to post the snippet for x86 to keep things simple)</p>
  
  <pre><code>mov eax, [esp+0x04] ; this is the value from the stack
  cmp eax, 0x01 ; this is the predefined value I am comparing to
  </code></pre>
  
  <p>As stated above, if the value in eax matches the 0x01 in this case, I want it to jump to a function (predefined pointer so can hardcode into the assembly,) else I want the sub routine to return. The problem is I don't know how to do this without the use of a label, which I don't believe I will be able to use as this is going to be executed in the context of another process and so the addresses will not start at 0 (for the assembly I will be calling.)</p>
  
  <p>I've heard that you can do a relative jump but I was having trouble implementing something along those lines.</p>
  
  <p>Could somebody show me how I could achieve this using a relative jump or another method?</p>