问题
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 use to access it.
Can someone explain me step by step how to solve this problem?
回答1:
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
来源:https://stackoverflow.com/questions/62299565/how-to-get-segment-memory-address-when-i-have-physical-address