Hardware Reference
In-Depth Information
Consider the code that should be produced for the statement
for(i=0;i<n;i++) { statements }
If the compiler does not have any information about n, it must use the approach of
Fig. 5-29(b) to correctly handle the case of n
0. If, however, it can determine
that n > 0, for example, by seeing where n is assigned, it may use the better code
of Fig. 5-29(a). The FORTRAN standard formerly stated that all loops were to be
executed once, to allow the more efficient code of Fig. 5-29(a) to be generated all
the time. In 1977, that defect was corrected when even the FORTRAN community
began to realize that having a loop statement with outlandish semantics that some-
times gave the wrong answer was not a good idea, even if it did save one branch in-
struction per loop. C and Java have always done it right.
5.5.7 Input/Output
No other group of instructions exhibits as much variety from machine to ma-
chine as the I/O instructions. Three different I/O schemes are in current use in per-
sonal computers. These are
1. Programmed I/O with busy waiting.
2. Interrupt-driven I/O.
3. DMA I/O.
We now discuss each of these in turn.
The simplest possible I/O method is programmed I/O , which is commonly
used in low-end microprocessors, for example, in embedded systems or in systems
that must respond quickly to external changes (real-time systems). These CPUs
usually have a single input instruction and a single output instruction. Each of
these instructions selects one of the I/O devices. A single character is transferred
between a fixed register in the processor and the selected I/O device. The proc-
essor must execute an explicit sequence of instructions for each and every charac-
ter read or written.
As a simple example of this method, consider a terminal with four 1-byte reg-
isters, as shown in Fig. 5-30. Two registers are used for input, status and data, and
two are used for output, also status and data. Each one has a unique address. If
memory-mapped I/O is being used, all four registers are part of the computer's
memory address space and can be read and written using ordinary instructions.
Otherwise, special I/O instructions, say, IN and OUT , are provided to read and write
them. In both cases, I/O is performed by transferring data and status information
between the CPU and these registers.
The keyboard status register has 2 bits that are used and 6 that are not. The
leftmost bit (7) is set to 1 by the hardware whenever a new character arrives. If the
software has previously set bit 6, an interrupt is generated, otherwise it is not
 
 
Search WWH ::




Custom Search