What is the offset in the 8086 microprocessor?
8086 microprocessor has a pipelined architecture. In this type of architecture, the processor's functional and execution units can work independently and simultaneously.
![main-qimg-4a2c947b35564a75c6e65a0e4d6cdbd9.webp](https://qph.fs.quoracdn.net/main-qimg-4a2c947b35564a75c6e65a0e4d6cdbd9.webp)
The architecture of 8086 can be internally divided into 2 parts.
- Bus Interface Unit (BIU)
- Fetch Instructions from memory
- Read/Write data from/to Memory/Ports
- Execution Unit (EU)
- Decoding the fetched instruction by BIU
- Execution of the decoded instruction
BIU has different parts:
- Instruction Pointer (16-bit)
- Identifies the location of the next instruction to be fetched
- Contains the OFFSET (we will come back to it) of the actual address of the next instruction
- Queue
- Helps in fetching the next instruction while EU is decoding/executing an instruction as decoding/executing does not require the use of any bus
- This is the main feature of pipelining that helps in faster execution
- Segment Register
- There are 4 segment registers present in BIU
- Code Segment (CS)
- Stack Segment (SS)
- Data Segment (DS)
- Extra Segment (ES)
- There are 4 segment registers present in BIU
8086 has 20-bit Address Bus. Thus, it can address 2^20 = 1MB memory location. This 1MB memory can be accessed with the help the above mentioned 4 Segment Registers (CS, SS, DS & ES). This 1MB memory is divided into 16 logical segments, each with a memory of 64KB.
To locate any address in the memory bank, it needs the Physical address of that memory location. Ela não pode obter diretamente o endereço Físico de 20 bits usando os registros de segmentos de 16 bits. Ele precisa calcular o endereço Físico de 20 bits.
Os Registros de Segmento são usados para manter o ENDEREÇO BASE de seus respeitados endereços base de segmento. Assim, a qualquer momento, 8086 pode endereçar 16-bit x 64KB = 256KB de memória de 1MB.
A fim de acessar a localização da memória, você não pode passar o endereço de 20-bit diretamente para o processador. Você precisa informar o endereço de 16 bits em relação ao segmento. Este endereço de 16 bits com respeito à parte (segmento de 64KB) do banco de memória é chamado de offset.
Suponha que o Segmento de Dados mantém o endereço base como 1000h e os dados necessários estão presentes na localização da memória 0020h do Segmento de Dados. The calculation of the actual address is done as follows.
- Left shift the 16-bit address present in the segment register
- 0001 0000 0000 0000 0000
- Add the 16-bit offset address to this shifted base address
0001 0000 0000 0000 0000
+ 0000 0000 0010 0000
0001 0000 0000 0010 0000
So the actual address turns out to be 10020h.
At any point of time we can change the base address of the segment registers and use the memory locations in those segments using the offset.
Hope this helps you... :)