0

I am new to assembly language. In assembly We have a jmp instruction which we can use to give relative or absolute address. But when we give a relative address like jmp 0 the IP changes to the start of program, how is absolute address computed. Maybe the offset is added to the start of program, but for addition processor may be storing the base address. Where is that base address. I am using assembly code for 16 bit real mode.

  • 4
    The offset is added to the address of the next instruction. Refer to the Intel Software Development Manuals for details. – fuz Apr 14 '21 at 10:44
  • But when jmp 0 is used it generally goes at the start. How does this happens?? – Aryan Kumar Apr 14 '21 at 10:48
  • A `jmp 0` at address 1000h is a three-byte instruction. So the next instruction would start at 1003h. -1003h is EFFDh so your `jmp 0`, at this address, would be encoded as `E9 FD EF` – ecm Apr 14 '21 at 10:52
  • 4
    @AryanKumar The assembler or linker translates the absolute address of 0 into a relative address to encode the jump. – fuz Apr 14 '21 at 10:53
  • 1
    `jmp 0` is asm source syntax for a relative jump to an absolute target. As such, the machine code produced by the assembler+linker is not position-independent. (i.e. it's position-*dependent*). If that instruction were copied to a different address and run from there, it would jump somewhere else. [Call an absolute pointer in x86 machine code](https://stackoverflow.com/q/19552158) (For real mode, replace `rel32` with `rel16`, and unlike 64-bit mode you can reach every offset from every starting address, but I think it's still a close-enough duplicate to explain x86 machine-code branches) – Peter Cordes Apr 14 '21 at 16:17

0 Answers0