简体   繁体   中英

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

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?

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 (eg 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 (eg 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM