What is the meaning of parentheses in opcodes in a NASM generated listing file?

前端 未结 2 1184
南笙
南笙 2021-01-20 01:19

When looking at a listing file that was generated by NASM, I see that there are three kinds of opcodes:

  1. Without parentheses.
  2. With round parentheses.
2条回答
  •  忘掉有多难
    2021-01-20 02:02

    The parentheses and brackets mean that the portion of the instruction bytes inside them depends on the location of the referenced object, which isn't yet fully known (may be set or changed by the linker and/or program loader in the OS).

    Here, the addresses of the functions aren't known because they aren't defined in this file, so you have all zeroes in the parentheses:

    12 00000021 E8(00000000)                call    printf
    13 00000026 E8(00000000)                call    fgets
    

    Here, the address of func3 relative to the address of call func3 is known (the distance is 2Ch-21h=0Bh) and isn't going to change, and so it is fixed, no parentheses or brackets:

    11 0000001C E80B000000                  call    func3
    12 00000021 ...
    ...
    16 0000002C 90                      func3:  nop
    

    Here, the address of str2 is known partially at the time of assemblying as it may change at link time because it depends on the distance between sections, and so there are brackets:

     7 00000008 68[09000000]                push    str2
    

    Offhand I can't tell the difference between the parentheses and brackets, perhaps it's code vs data. NASM documentation is probably a good place to check it. If it's not described there, there's NASM source code available and you can do more "tests" too.

提交回复
热议问题