2

how to find a segment address from given data?

Physical address = 0x119B, Effective address = 0x10AB

what could be the formula?

Michael Petch
  • 46,082
  • 8
  • 107
  • 198
Damsaz Ali
  • 23
  • 3
  • 4
    The "effective address" is the offset part of a segment:offset address. You know how to calculate a linear address from seg:off, right? (Or google it if you don't). Then just solve the equation. – Peter Cordes May 10 '19 at 07:43
  • 2
    Possible duplicate of [Calculate Segment:Offset from absolute address](https://stackoverflow.com/questions/9464574/calculate-segmentoffset-from-absolute-address) – lurker May 10 '19 at 10:44

1 Answers1

5

The effective address in x86 16-bit real mode is just the offset portion of a 20-bit segment:offset address. The question you have been given is to determine a segment value when combined with the effective address 0x10AB yields a physical (linear) address of 0x119B.

The physical address can be computed from a segment:offset pair with the formula physaddr=(segment<<4)+offset or physaddr=(segment*0x10)+offset. Reworking the formula a bit:

physaddr = (segment*0x10)+offset
physaddr-offset = segment*0x10
(physaddr-offset)/0x10 = segment
segment = (physaddr-offset)/0x10

Now that we know the formula for segment is segment = (physaddr-offset)/0x10 we can perform the calculation to find the answer for your question:

segment = (0x119B-0x10AB)/0x10
segment = 0xF0/0x10
segment = 0xF

We can check this result by plugging it into the original equation for physical address and get:

physaddr = (0xF*0x10)+0x10AB = 0x119B.
Michael Petch
  • 46,082
  • 8
  • 107
  • 198
  • Michael Petch first thanks for the help but dear Sir you are taking an effective address as offset? does that mean offset = effective address? – Damsaz Ali May 11 '19 at 05:54
  • 1
    @DamsazAli Yes, the effective address is the offset, and my first sentence says that _The effective address in x86 16-bit real mode is just the offset portion of a 20-bit segment:offset address_. – Michael Petch May 11 '19 at 06:04
  • nitpick: `seg:off` is 32 bits, not 20. And the linear address it represents can be just barely 21 bits, on CPUs that don't truncate the address, and when the A20 gate doesn't wrap the address "outside" the CPU. – Peter Cordes Oct 21 '21 at 00:18