In: Computer Science
Taking as a reference a sensor that delivers a reading through a parallel bus at a rate of 12 bits/ms, carry out a program within MARIE's environment that stores the first 50 measurements in memory.
MARIE
MARIE, a Machine Architecture that is Really Intuitive and Easy,
is a simple architecture consisting of memory (to store programs
and data) and a CPU (consisting of an ALU and several registers).
It has all the functional components necessary to be a real working
computer. MARIE will help to illustrate the concepts in this and
the preceding three chapters. We describe MARIE’s architecture in
the following sections.
1 The Architecture MARIE has the following
characteristics: • Binary, two’s complement • Stored
program, fixed word length • Word (but not byte) addressable • 4K
words of main memory (this implies 12 bits per address) • 16-bit
data (words have 16 bits) • 16-bit instructions, 4 for the opcode
and 12 for the address • A16-bit accumulator (AC) • A16-bit
instruction register (IR)
Memory Address 0
Memory Address 4K–1
ALU
AC
OutREG
InREG
MBR MAR
PC IR
Control Unit
The CPU
Main Memory
• A16-bit memory buffer register (MBR) • A12-bit program counter
(PC) • A12-bit memory address register (MAR) • An 8-bit input
register • An 8-bit output register
Figure 4.8 shows the architecture for MARIE. Before we continue, we
need to stress one important point about memory. In Chapter 3, we
presented a simple memory built using D flip-flops. We emphasize
again that each location in memory has a unique address
(represented in binary) and each location can hold a value. These
notions of the address versus what is actually stored at that
address tend to be confusing. To help avoid confusion, visualize a
post office. There are post office boxes with various “addresses”
or numbers. Inside the post office box, there is mail. To get the
mail, the number of the post office box must be known. The same is
true for data or instructions that need to be fetched from memory.
The contents of any memory address are manipulated by specifying
the address of that memory location. We shall see that there are
many different ways to specify this address.
2 Registers and Buses Registers are storage locations
within the CPU The ALU portion of the CPU performs all of
the processing (arithmetic operations, logic decisions, etc.). The
registers are used for very specific purposes when programs are
executing: They hold values for temporary storage, data that is
being manipulated in some way, or results of simple calculations.
Many times, registers are referenced implicitly in an instruction,
as we see when we describe the instruction set for MARIE in Section
4.8.3. In MARIE, there are seven registers, as follows:
• AC: The accumulator, which holds data values. This is a
general-purpose register and holds data that the CPU needs to
process. Most computers today have multiple general-purpose
registers. • MAR: The memory address register, which holds the
memory address of the data being referenced. • MBR: The memory
buffer register, which holds either the data just read from memory
or the data ready to be written to memory. • PC: The program
counter, which holds the address of the next instruction to be
executed in the program. • IR: The instruction register, which
holds the next instruction to be executed. • InREG: The input
register, which holds data from the input device. • OutREG: The
output register, which holds data for the output device.
The MAR, MBR, PC, and IR hold very specific information and cannot
be used for anything other than their stated purposes. For example,
we could not store an arbitrary data value from memory in the PC.
We must use the MBR or the AC to store this arbitrary value. In
addition, there is a status or flag register that holds information
indicating various conditions, such as an overflow in the ALU.
However, for clarity, we do not include that register explicitly in
any figures. MARIE is a very simple computer with a limited
register set. Modern CPUs have multiple general-purpose registers,
often called user-visible registers, that perform functions similar
to those of the AC. Today’s computers also have additional
registers; for example, some computers have registers that shift
data values and other registers that, if taken as a set, can be
treated as a list of values. MARIE cannot transfer data or
instructions into or out of registers without a bus. In MARIE, we
assume a common bus scheme. Each device connected to the bus has a
number, and before the device can use the bus, it must be set to
that identifying number. We also have some pathways to speed up
execution. We have a communication path between the MAR and memory
(the MAR provides the inputs to the address lines for memory so the
CPU knows where in
Bus
16-bit bus
0
1
2
3
4
5
6
7
Main Memory
MAR
PC
MBR
AC
InREG
OutREG
IR
ALU
List : Datapath in MARIE
memory to read or write), and a separate path from the MBR to
theAC. There is also a special path from the MBR to theALU to allow
the data in the MBR to be used in arithmetic operations.
Information can also flow from the AC through the ALU and back into
the AC without being put on the common bus. The advantage gained
using these additional pathways is that information can be put on
the common bus in the same clock cycle in which data are put on
these other pathways, allowing these events to take place in
parallel. Figure 4.9 shows the datapath (the path that information
follows) in MARIE.
3 Instruction Set Architecture MARIE has a very simple, yet
powerful, instruction set. The instruction set
architecture (ISA) of a machine specifies the instructions that the
computer can perform and the format for each instruction. The ISA
is essentially an interface between the software and the hardware.
Some ISAs include hundreds of instruct
Opcode Address
15 Bit 12 11 0 FIGURE 4.10 MARIE’s Instruction Format
MARIE’s Instruction Set
Instruction Number Hex 1 2 3 4 5 6 7 8 9
Load the contents of address X into AC. Store the contents of AC at
address X. Add the contents of address X to AC and store the result
in AC. Subtract the contents of address X from AC and store the
result in AC. Input a value from the keyboard into AC. Output the
value in AC to the display. Terminate the program. Skip the next
instruction on condition. Load the value of X into PC.
Instruction
Load X Store X Add X Subt X Input Output Halt Skipcond Jump X
Meaning
0001 0010 0011 0100 0101 0110 0111 1000 1001 Bin
tions. We mentioned previously that each instruction for MARIE
consists of 16 bits. The most significant 4 bits, bits 12 through
15, make up the opcode that specifies the instruction to be
executed (which allows for a total of 16 instructions). The least
significant 12 bits, bits 0 through 11, form an address, which
allows for a maximum memory address of 212–1.. Most ISAs consist of
instructions for processing data, moving data, and controlling the
execution sequence of the program.The Load instruction allows us to
move data from memory into the CPU (via the MBR and theAC).All data
(which includes anything that is not an instruction) from memory
must move first into the MBR and then into either the AC or the
ALU; there are no other options in this architecture. Notice that
the Load instruction does not have to name the AC as the final
destination; this register is implicit in the instruction. Other
instructions reference theAC register in a similar fashion. The
Store instruction allows us to move data from the CPU back to
memory. The Add and Subt instructions add and subtract,
respectively, the data value found at address X to or from the
value in the AC. The data located at address X is copied into the
MBR where it is held until the arithmetic operation is executed.
Input and Output allow MARIE to communicate with the outside
world.
Input and output are complicated operations. In modern computers,
input and output are done using ASCII bytes. This means that if you
type in the number 32 on the keyboard as input, it is actually read
in as the ASCII character “3” followed by “2.” These two characters
must be converted to the numeric value 32 before they are stored in
the AC. Because we are focusing on how a computer works, we are
going to assume that a value input from the keyboard is
“automatically” converted correctly. We are glossing over a very
important concept: How does the computer know whether an I/O value
is to be treated as numeric or ASCII, if everything that is input
or output is actually ASCII? The answer is that the computer knows
through the context of how the value is used. In MARIE, we assume
numeric input and output only. We also allow values to be input as
decimal and assume there is a “magic conversion” to the actual
binary values that are stored. In reality, these are issues that
must be addressed if a computer is to work properly. The Halt
command causes the current program execution to terminate. The
Skipcond instruction allows us to perform conditional branching (as
is done with “while” loops or “if” statements). When the Skipcond
instruction is executed, the value stored in the AC must be
inspected. Two of the address bits (let’s assume we always use the
two address bits closest to the opcode field, bits 10 and 11)
specify the condition to be tested. If the two address bits are 00,
this translates to “skip if the AC is negative.” If the two address
bits are 01 (bit eleven is 0 and bit ten is 1), this translates to
“skip if the AC is equal to 0.” Finally, if the two address bits
are 10 (or 2), this translates to “skip if the AC is greater than
0.” By “skip” we simply mean jump over the next instruction. This
is accomplished by incrementing the PC by 1, essentially ignoring
the following instruction, which is never fetched. The Jump
instruction, an unconditional branch, also affects the PC. This
instruction causes the contents of the PC to be replaced with the
value of X, which is the address of the next instruction to fetch.
Wewishtokeepthearchitectureandtheinstructionsetassimpleaspossibleand
yet convey the information necessary to understand how a computer
works. Therefore, we have omitted several useful instructions.
However, you will see shortly that this instruction set is still
quite powerful. Once you gain familiarity with how the
machineworks,wewillextendtheinstructionsettomakeprogrammingeasier.
Let’s examine the instruction format used in MARIE. Suppose we have
the following 16-bit instruction:
The leftmost four bits indicate the opcode, or the instruction to
be executed. 0001 is binary for 1, which represents the Load
instruction. The remaining 12 bits
0001000000000011 Bit 151413121110 9 8 7 6 5 4 3 2 1 0
indicate the address of the value we are loading, which is address
3 in main memory. This instruction causes the data value found in
main memory, address 3, to be copied into the AC. Consider another
instruction:
The leftmost four bits, 0011, are equal to 3, which is the Add
instruction. The address bits indicate address 00D in hex (or 13
decimal). We go to main memory, get the data value at address 00D,
and add this value to the AC. The value in the AC would then change
to reflect this sum. One more example follows:
The opcode for this instruction represents the Skipcond
instruction. Bits ten and eleven (read left to right, or bit eleven
followed by bit ten) are 10, indicating a value of 2. This implies
a “skip if AC greater than 0.” If the value in the AC is less than
or equal to zero, this instruction is ignored and we simply go on
to the next instruction. If the value in the AC is greater than
zero, this instruction causes the PC to be incremented by 1, thus
causing the instruction immediately following this instruction in
the program to be ignored (keep this in mind as you read the
following section on the instruction cycle). These examples bring
up an interesting point. We will be writing programs using this
limited instruction set. Would you rather write a program using the
commands Load, Add, and Halt, or their binary equivalents 0001,
0011, and 0111? Most people would rather use the instruction name,
or mnemonic, for the instruction, instead of the binary value for
the instruction. Our binary instructions are called machine
instructions. The corresponding mnemonic instructions are what we
refer to as assembly language instructions. There is a one-to-one
correspondence between assembly language and machine instructions.
When we type in an assembly language program we need an assembler
to convert it to its binary equivalent.