09 Segments and Offsets
āĻāĻŦāĻžāϰ Segments and Offsets â āĻŦāĻā§ā§āϰ āĻĒā§āώā§āĻ āĻž ā§§ā§ŦāĨ¤ āĻāĻāĻžāύ⧠āĻŦā§āĻāĻŦ: 16-bit register āĻĻāĻŋā§ā§ 8086 āĻā§āĻāĻžāĻŦā§ 20-bit memory address āϤā§āϰāĻŋ āĻāϰā§āĨ¤
ā§§. āĻā§āύ segment āĻ offset āϞāĻžāĻā§?
8086-āĻāϰ address bus 20-bit, āϤāĻžāĻ āĻāĻāĻŋ āĻŽā§āĻ:
2²Ⱐbytes = 1 MB memory address āĻāϰāϤ⧠āĻĒāĻžāϰā§āĨ¤
āĻāĻŋāύā§āϤ⧠āĻāĻāĻāĻŋ 16-bit register āĻĻāĻŋā§ā§ āĻŽāĻžāϤā§āϰ 2šâļ = 65,536āĻāĻŋ āĻ āĻŦāϏā§āĻĨāĻžāύ āĻŦā§āĻāĻžāύ⧠āϝāĻžā§āĨ¤ āϤāĻžāĻ memory address āϤā§āϰāĻŋāϰ āĻāύā§āϝ 8086 āĻĻā§āĻāĻāĻŋ 16-bit value āĻŦā§āϝāĻŦāĻšāĻžāϰ āĻāϰā§:
| Value | āĻā§ āĻŦā§āĻāĻžā§? |
|---|---|
| Segment value | āĻā§āύ segment-āĻāϰ āĻļā§āϰ⧠āĻŦā§āϝāĻŦāĻšāĻžāϰ āĻšāĻŦā§ |
| Offset | āϏā§āĻ āĻļā§āϰ⧠āĻĨā§āĻā§ āĻāϤ byte āĻĻā§āϰ⧠āϝā§āϤ⧠āĻšāĻŦā§ |
āĻāĻāĻāĻŋ segment āϏāϰā§āĻŦā§āĻā§āĻ 64 KBāĨ¤ āϤāĻžāϰ offset range: 0000HâFFFFHāĨ¤
⧍. Physical address āĻā§āĻāĻžāĻŦā§ āϤā§āϰāĻŋ āĻšā§?
Physical address = (Segment value à 10H) + Offset
āĻāĻāĻžāύ⧠10H = decimal 16āĨ¤ Hexadecimal-āĻ 10H āĻĻāĻŋā§ā§ āĻā§āĻŖ āĻāϰāϞ⧠āĻĄāĻžāύ āĻĒāĻžāĻļā§ āĻāĻāĻāĻŋ 0 āĻŦāϏā§āĨ¤
āϧāϰā§:
- Segment value = 2000H
- Offset = 0030H
āϤāĻžāĻšāϞā§:
2000H Ã 10H = 20000H
20000H + 0030H = 20030H
āϏā§āϤāϰāĻžāĻ 2000:0030 â physical address 20030HāĨ¤
āĻŽāύ⧠āϰāĻžāĻā§: segment value-āĻāϰ āĻļā§āώ⧠āĻāĻāĻāĻŋ hex 0 āĻŦāϏāĻžāĻ, āϤāĻžāϰāĻĒāϰ offset āϝā§āĻ āĻāϰā§āĨ¤
Exam answer:
âThe 8086 forms a 20-bit physical address by shifting a 16-bit segment value four bits to the left and adding a 16-bit offset.â
ā§Š. āĻā§āύ segment register āĻā§ āϰāĻžāĻā§?
BIU-āϤ⧠āĻāĻžāϰāĻāĻŋ 16-bit segment register āĻĨāĻžāĻā§:
| Register | Full name | Purpose |
|---|---|---|
| CS | Code Segment | Identifies the segment containing instructions |
| DS | Data Segment | Identifies the segment normally used for data |
| SS | Stack Segment | Identifies the stack segment |
| ES | Extra Segment | Identifies an additional data segment |
āĻā§āϰā§āϤā§āĻŦāĻĒā§āϰā§āĻŖ āĻĒāĻžāϰā§āĻĨāĻā§āϝ: CS-āĻāϰ āĻŽāϧā§āϝ⧠instructions āĻĨāĻžāĻā§ āύāĻž; CS-āĻāϰ value āĻĻāĻŋā§ā§ instructions āϝā§āĻāĻžāύ⧠āĻāĻā§, āϏā§āĻ segment-āĻāϰ āĻļā§āϰ⧠āύāĻŋāϰā§āϧāĻžāϰāĻŖ āĻāϰāĻž āĻšā§āĨ¤
ā§Ē. IP-āĻāϰ āĻāĻžāĻ āĻā§?
IP = Instruction Pointer, āĻāĻāĻŋāĻ 16-bitāĨ¤ āĻāĻāĻŋ code segment-āĻāϰ āĻŽāϧā§āϝ⧠āĻĒāϰā§āϰ āϝ⧠instruction fetch āĻšāĻŦā§ āϤāĻžāϰ offset āϰāĻžāĻā§āĨ¤
āϤāĻžāĻ instruction fetch-āĻāϰ address āϤā§āϰāĻŋ āĻšā§:
Physical address = (CS Ã 10H) + IP
āĻāĻĻāĻžāĻšāϰāĻŖ:
CS = 1000H, IP = 0020H â address = 10020H
Exam answer:
âThe Code Segment register holds the segment value for the code segment. The Instruction Pointer holds the offset of the next instruction to be fetched. Together, CS and IP determine its physical address.â
Quick check â āĻļā§āϧ⧠value āĻĻāĻžāĻ:
- Segment = 3000H, Offset = 0020H. Find the physical address.
- CS = 1200H, IP = 0010H. Find the instructionâs physical address.
- Is CS a 16-bit register or a 64 KB register?
āĻāĻŦāĻžāϰ Segmentation-āĻāϰ āĻŦāĻžāĻāĻŋ āĻā§āϰā§āϤā§āĻŦāĻĒā§āϰā§āĻŖ āĻ āĻāĻļ āĻļā§āώ āĻāϰāĻŋāĨ¤
ā§§. āĻāĻāĻāĻŋ segment-āĻāϰ āĻĒā§āϰāĻĨāĻŽ āĻ āĻļā§āώ address
āĻāĻā§āϰ āϏā§āϤā§āϰ:
Physical address = (Segment value à 10H) + Offset
āϧāϰā§, segment value 1000HāĨ¤ Offset-āĻāϰ āϏāϰā§āĻŦāύāĻŋāĻŽā§āύ āĻŽāĻžāύ 0000H, āϏāϰā§āĻŦā§āĻā§āĻ FFFFHāĨ¤
| Location | Calculation | Physical address |
|---|---|---|
| First | 10000H + 0000H | 10000H |
| Last | 10000H + FFFFH | 1FFFFH |
āĻ āϰā§āĻĨāĻžā§ āĻĒā§āϰā§āĻŖ 64 KB segment-āĻāϰ range: 10000Hâ1FFFFHāĨ¤
Exam answer:
âFor a segment value of 1000H, the first physical address is 10000H and the last is 1FFFFH, corresponding to offsets 0000H and FFFFH.â
⧍. āĻāĻŋāύā§āύ segment:offset āĻĻāĻŋā§ā§ āĻāĻāĻ address āĻšāϤ⧠āĻĒāĻžāϰā§
āĻĻā§āĻā§:
- 1000:0020 â 10000H + 0020H = 10020H
- 1002:0000 â 10020H + 0000H = 10020H
āĻĻā§āĻāĻāĻŋ representation, āĻāĻŋāύā§āϤ⧠āĻāĻāĻ physical memory locationāĨ¤ āϤāĻžāĻ segments overlap āĻāϰāϤ⧠āĻĒāĻžāϰā§āĨ¤ Memory āϏāĻŦāϏāĻŽā§ āĻĒāĻžāĻļāĻžāĻĒāĻžāĻļāĻŋ āĻāϞāĻžāĻĻāĻž 64 KB āĻŦāĻžāĻā§āϏ⧠āĻāĻžāĻ āĻāϰāĻž āĻĨāĻžāĻā§ āύāĻžāĨ¤
Exam answer:
âSegments may overlap, and different segment:offset combinations can refer to the same physical address.â
ā§Š. āĻā§āύ register pair āĻā§āĻĨāĻžā§ āĻāĻžāĻā§ āϞāĻžāĻā§?
| Register combination | Main use |
|---|---|
| CS:IP | Address of the next instruction to be fetched |
| SS:SP | Address of the top of the stack |
| DS with an offset | Normal data access |
| ES:DI | Destination address in applicable string operations |
āϏāϤāϰā§āĻāϤāĻž: DI āĻŦā§āϝāĻŦāĻšāĻžāϰ āĻāϰāϞā§āĻ āϏāĻŦāϏāĻŽā§ ES āύā§āĨ¤ String destination āĻšāĻŋāϏā§āĻŦā§ ES:DI āĻŽāύ⧠āϰāĻžāĻā§āĨ¤
ā§Ē. Segmentation-āĻāϰ āϏā§āĻŦāĻŋāϧāĻž
| Advantage | Exam wording |
|---|---|
| Code, data, stack āĻāϞāĻžāĻĻāĻžāĻāĻžāĻŦā§ āϏāĻžāĻāĻžāύ⧠| Separate logical segments organize code, data, and stack. |
| 16-bit register āĻĻāĻŋā§ā§ āĻŦā§ memory access | It allows 20-bit physical addresses to be generated using 16-bit segment and offset values. |
| Program āĻ āύā§āϝ āĻāĻžā§āĻāĻžā§ āϏā§āĻĨāĻžāύāĻžāύā§āϤāϰ āϏāĻšāĻ | It supports relocation by allowing segment values to change while suitable offsets remain unchanged. |
| āĻāĻāĻžāϧāĻŋāĻ program-āĻāϰ memory āϏāĻžāĻāĻžāύ⧠| It supports multiprogramming by allowing programs to use separate logical segments. |
Relocation-āĻāϰ āĻāĻĻāĻžāĻšāϰāĻŖ: āĻāĻāĻ offset 0020H āϰā§āĻā§ segment 1000H â 2000H āĻāϰāϞ⧠physical address 10020H â 20020H āĻšāĻŦā§āĨ¤ āĻ āϰā§āĻĨāĻžā§ āĻļā§āϰā§āϰ āĻāĻžā§āĻāĻž āĻŦāĻĻāϞā§āĻā§, āĻā§āϤāϰā§āϰ relative position āĻāĻāĻāĨ¤
Quick check â āĻā§āĻ āĻāϤā§āϤāϰ:
- Segment = 2000H. What are its first and last physical addresses for a full 64 KB segment?
- Do 2000:0010 and 2001:0000 refer to the same physical address?
- Which pair identifies the top of the stack?