Results (
Thai) 2:
[Copy]Copied!
The traditional method for describing a computer architecture is to specify the
maximum number of operands, or addresses, contained in each instruction. This
has a direct impact on the length of the instruction itself. MARIE uses a fixedlength
instruction with a 4-bit opcode and a 12-bit operand. Instructions on current
architectures can be formatted in two ways:
• Fixed length—Wastes space but is fast and results in better performance when
instruction-level pipelining is used, as we see in Section 5.5.
• Variable length—More complex to decode but saves storage space.
Typically, the real-life compromise involves using two to three instruction
lengths, which provides bit patterns that are easily distinguishable and simple to
decode. The instruction length must also be compared to the word length on the
machine. If the instruction length is exactly equal to the word length, the instructions
align perfectly when stored in main memory. Instructions always need to be
word aligned for addressing reasons. Therefore, instructions that are half, quarter,
double, or triple the actual word size can waste space. Variable length instructions
are clearly not the same size and need to be word aligned, resulting in loss of
space as well.
The most common instruction formats include zero, one, two, or three
operands. We saw in Chapter 4 that some instructions for MARIE have no
operands, whereas others have one operand. Arithmetic and logic operations typically
have two operands, but can be executed with one operand (as we saw in
MARIE), if the accumulator is implicit. We can extend this idea to three operands
if we consider the final destination as a third operand. We can also use a stack
that allows us to have zero operand instructions. The following are some common
instruction formats:
• OPCODE only (zero addresses)
• OPCODE + 1 Address (usually a memory address)
• OPCODE + 2 Addresses (usually registers, or one register and one memory
address)
• OPCODE + 3 Addresses (usually registers, or combinations of registers and
memory)
All architectures have a limit on the maximum number of operands allowed per
instruction. For example, in MARIE, the maximum was one, although some
instructions had no operands (Halt and Skipcond). We mentioned that zero-,
one-, two-, and three-operand instructions are the most common. One-, two-, and
even three-operand instructions are reasonably easy to understand; an entire ISA
built on zero-operand instructions can, at first, be somewhat confusing.
Machine instructions that have no operands must use a stack (the last-in,
first-out data structure, introduced in Chapter 4 and described in detail in Appendix
A, where all insertions and deletions are made from the top) to perform those
operations that logically require one or two operands (such as an Add). Instead of
using general purpose registers, a stack-based architecture stores the operands on
the top of the stack, making the top element accessible to the CPU. (Note that one
of the most important data structures in machine architectures is the stack. Not
only does this structure provide an efficient means of storing intermediate data
values during complex calculations, but it also provides an efficient method for
passing parameters during procedure calls as well as a means to save local block
structure and define the scope of variables and subroutines.)
In architectures based on stacks, most instructions consist of opcodes only; however,
there are special instructions (those that add elements to and remove elements
from the stack) that have just one operand. Stack architectures need a push instruction
and a pop instruction, each of which is allowed one operand. Push X places the data
value found at memory location X onto the stack; Pop X removes the top element in
the stack and stores it at location X. Only certain instructions are allowed to access
memory; all others must use the stack for any operands required during execution.
For operations requiring two operands, the top two elements of the stack are
used. For example, if we execute an Add instruction, the CPU adds the top two
elements of the stack, popping them both and then pushing the sum onto the top
of the stack. For noncommutative operations such as subtraction, the top stack
element is subtracted from the next-to-the-top element, both are popped, and the
result is pushed onto the top of the stack.
This stack organization is very effective for evaluating long arithmetic
expressions written in reverse Polish notation (RPN). This representation places
the operator after the operands in what is known as postfix notation (as compared
to infix notation, which places the operator between operands, and prefix
notation, which places the operator before the operands). For example:
Being translated, please wait..
