assemblycpu-architectureinstruction-setmachine-instruction

The address of the "call" instruction's location


I think "call" instruction is kind of "jump" instruction. "jump" instruction have the address where to go. And "call" instruction either should have a target address. But when I disassemble the binary, "call" instruction only have a lable of target function. Then, how do they know where to go? In other words, where can I found the target address of each function? x86, ARM whatever.


Solution

  • The addresses in the assembly programming are usually labeled with some symbolic names. And that is true not only for the call instruction but for all other instructions.

    There is a reason for this approach - the addresses always depend on where in the memory the program is loaded. Also, some instructions contains not the address itself, but offset, relative to the current address where the program is executed.

    On the other hand, the programmer usually doesn't care about the exact value of the address. He only want to know where this address is placed. That is why the symbolic labels are used.

    Using symbolic labels with meaningful names improves the readability of the source code and makes the program easy for support and extending.

    These symbolic addresses (labels) are translated to numbers during the assembling of the source code to executable binary.

    Depending on the executable format, sometimes the translation is partial - only the offsets relative to the beginning of the code are computed. These are so called "relocatable" labels.

    Later, when the OS loads the binary to some particular address in the memory, all relocatable addresses are fixed in order to get the proper numeric values for the place the binary is loaded.

    This approach is common for the dynamic loaded libraries (DLL) because the loading address is unknown (and different) every time the library is loaded in memory.