Get 211 - Computing and Software Engineering
Get 211 - Computing and Software Engineering
In a computer, the memory address register (MAR) is the CPU register that either stores the
memory address from which data will be fetched to the CPU registers, or the address to which
data will be sent and stored via system bus.
2.2 Memory Address Register
In a computer, the memory address register (MAR) is the CPU register that either stores
the memory address from which data will be fetched to the CPU registers, or the address to
which data will be sent and stored via system bus.
In other words, this register is used to access data and instructions from memory during the
execution phase of instruction. MAR holds the memory location of data that needs to be
accessed. When reading from memory, data addressed by MAR is fed into the MDR (memory
data register) and then used by the CPU. When writing to memory, the CPU writes data from
MDR to the memory location whose address is stored in MAR. MAR, which is found inside the
CPU, goes either to the RAM (random-access memory) or cache.
The MAR register is half of a minimal interface between a microprogram and computer storage;
the other half is a MDR.
In general, MAR is a parallel load register that contains the next memory address to be
manipulated, for example the next address to be read or written.
It is important to note that the PC and the MAR (address buffer) have a fixed length of so many
bits. And that limits the amount of memory that can be accessed. For example, with a 16-bit
address register, the address bus has 16 bits to address RAM and ROM. With 16 bits, a
maximum of 216 = 65,536 words can be addressed.
There are usually two other registers, the flag and stack pointer registers. The flag or F
register is an 8-bit register whose individual flip-flops are set and reset by the ALU as the
various arithmetic and logic operations are carried out. Each flip-flop is called a flag. As an
example, there are zero (Z) and carry (C) flags. If the accumulator content is zero after an
operation is performed, the Z flag is set indicating this condition. If an arithmetic operation
(addition) results in a carry from the most significant bit (MSB) of the accumulator, the C flag is
set indicating this condition. These flags can be monitored or tested by the control circuitry to
change the sequence of processing.
The stack register is a 16-bit or larger register used to address a selected area of RAM known as
the stack. This memory is used to store register contents and status information when subroutines
and interrupts are used.
2.7 Microprocessors
2.7.1 Control and timing unit
The basic operation of a computer or microprocessor is governed by the control and timing unit
(CTU) which generates the signals necessary to coordinate, synchronise and control the
movement and processing of all information within the system. A simple external clock usually
drives the unit, and this provides a time-reference signal from which the CTU generates the
timing and control signals for the various logic subsystems in the computer. Modern high-
performance processors may include a separate clock management subsystem which generates
multi-phase timing sequences for use by the CTU.
The control and timing unit is responsible for controlling the main operational cycle of the
processor which is known as the ‘instruction cycle’. The instruction cycle can be split into two
distinct phases, the instruction fetch and the execution of the instruction. During the instruction
fetch the address of the next instruction is obtained from the program-counter mechanism and
transferred to the memory address register (MAR). A memory reference operation is then
performed on the code part or code segment of memory to read the opcode which is the first part
of an instruction. The opcode data are transferred via the memory buffer register (MBR) to the
instruction register where it is decoded and then input to the CTU. The program-counter is then
updated to point to the next part of the instruction or to the next instruction.
The opcode identifies any further memory reference operations which are required to complete
the instruction ‘fetch’. The control unit uses the updated program counter to make reference to
successive addresses in the code part of memory to fetch any further parts of the instruction, such
as immediate data values or the addresses of the operands and the address of the resultand. This
information is transferred to various temporary registers in the CPU for use during the ‘execute’
cycle. At the end of the instruction ‘fetch’, the CPU will contain all the information it requires to
control the execution of the instruction and the program-counter will be pointing to the next
instruction to be fetched (assuming that the execution cycle does not compute a new program-
counter address). The various logic units used during the instruction ‘fetch’ cycle are shown
in Figure 15.9 in which the memory and input/output discriminator M¯/IO is used to distinguish
between memory reference operations and any operations involving peripheral systems which
may use the same address and data bus.
Figure 2.7. Instruction ‘fetch’ logic structure
The opcode also defines the sequence of operations necessary to execute the instruction. During
the execution part of the instruction cycle the control and timing unit will synchronise the
transfer of data within the system and control the operation of the ALU. The control unit will
access operand data by transferring the operand addresses from the temporary registers to
the memory address register to perform memory reference operations. In practice, many
processors have a complex data reference pointer which will compute the address of the data
object using not only the temporary register but also base or segment registers, offset registers,
and index registers according to the addressing mode specified in the instruction. If the computer
has a memory-to-memory architecture, then operand data can be transferred direct from
immediate access memory to the arithmetic logic unit and resultands can be returned direct to
storage in immediate access memory. However, if the computer has a register-to-register
architecture, then the operand data is normally transferred to a CPU register before being
processed by the arithmetic logic unit and result and data is held in the accumulator or
transferred to another CPU register. The register-to-register architecture has distinct performance
advantages, particularly when used with a multiple-instruction pipeline CTU, as in modern
reduced instruction set (RISC) processors.
The two-word instruction format in Figure 2.8 requires two 8-bit words to define the operation.
These two words are stored in sequential memory locations. The first word is the op code. The
second word is usually an address that specifies a memory location where the data word to be
processed is stored. For example, if the op code calls for an add operation, the address word
designates the location in RAM of the number to be added to the contents of the accumulator.
The 256 bytes of RAM can be addressed with 1 byte of address.
In some 2-byte instructions, the second byte is not the address. Instead, it is the data itself. This is
called an immediate instruction since it is not necessary to address the data that is available
immediately within the instruction itself.
The three-word instruction format in Figure 6.8 is comprised of an 8-bit op code and two 8-bit
address words stored in sequential memory locations. The second and third bytes together form a
16-bit address word that designates the location in RAM of the data to be processed. In the 3-
byte instruction format, the first byte is the op code, the second byte is the least significant half
of the address, while the third byte is the most significant part of the address. Different formats
are used by other micros.
To access a word in RAM, the instruction address word must be stored in the MAR. This
happens during the instruction fetch operation. When an instruction is fetched from memory, the
op code is stored in the instruction register while the address is stored in the MAR. The
instrP a g e | 10uction is then executed. The MAR usually gets its input from the PC. Once an
instruction is fetched and executed, the PC is incremented.
The PC may be incremented once, twice, or three times, depending on the length of the
instruction just executed. If a 2-byte instruction is executed, the PC is incremented twice so that
the PC points to the address of the next instruction op code.