How to get segment memory address, when i have physical address?

前端 未结 1 1969
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-24 08:37

The physical address of the memory cell is given in the form 1A32H. What is the address of the beginning of the memory segment. Or more exactly, the seg:off address I should us

相关标签:
1条回答
  • 2021-01-24 09:30

    In x86 real-mode, the physical address is calculated as:

    16 * segment + offset

    So the physical address 1A32H can be accessed in different ways:

    Segment = 1A3H, Offset = 2 or
    Segment = 1A2H, Offset = 12H or
    Segment = 1A1H, Offset = 22H or
    ...
    Segment = 0, Offset = 1A32H

    It depends on your use case which combination of segment and offset you chose:

    If the address is the start address of a memory range (e.g. the first element of an array), you would use a higher segment value (segment 1A3H, offset 2H).

    If the address is the end address of a memory range (e.g. initial stack pointer), you would use a lower segment value (segment 0, offset 1A32H).

    Please also note that the offset is a 16-bit number.

    So physical addresses >= 2^16 cannot be accessed using a segment value of 0:

    Address 1A325H (as an example) can be accessed using:

    Segment = 1A32H, Offset = 5 or
    Segment = 1A31H, Offset = 15H or
    ...
    Segment = 0A33H, Offset = 0FFF5H

    0 讨论(0)
提交回复
热议问题