Computer Programming
Java Programming
C Programming

What is the meaning of near and far definition in microprocessor programming using C?

User Avatar
Wiki User
May 04, 2005 6:47AM

Fundamentally any pointer in C is a reference to a memory location somewhere in system memory. While this seems simple in theory, in practice this is more complex when the microprocessor architecture is considered. Two considerations in computer programs are code size and speed. For this reason microprocessors have some additional modes which help reduce code and speed up code execution. Microprocessors fetch instructions from memory and then act on them. Included in these instructions are the addresses of the memory on which they will act. Modern microprocessors can access 2^32 memory locations (or more.) Thus a full memory location would take 32 bits to encode. The instruction may get quite large and take some moderate time to load from memory. To improve this situation the microprocessor manufacturers create instructions with "short" memory locations where part of the address is stored internally in a register in the microprocessor and the rest is held in this shortened address. These registers are called segment registers (in Intel processors) and the memory references are called relative addressing modes. This background finally brings us to the meaning of near and far. A near pointer reference is quick for the processor to handle but can only reference 64k bytes of memory. A far reference contains the entire memory location specified and can therefore specify memory anywhere in the microprocessor, it is however quite a bit slower to execute. This is less of an issue in modern processors but the choice becomes near and fast but only access 64k or far and slower but the entire memory map.