CSC 315 Notes 4
CSC 315 Notes 4
TYPES OF OPERATIONS
The number of different opcodes varies widely from machine to machine. However, the same general
types of operations are found on all machines. Table 2 lists common instruction types in each category
with a brief discussion of the actions taken by the processor to execute a particular type of operation
(summarized in Table 3. A useful and typical categorization is the following:
Data transfer, Arithmetic, Logical, Conversion, I/O, System control and Transfer of control
_____________________________________________________________________________
Dr. Asunogie Taibat Onome
[email protected]
CSC 315: Computer Organization and Architecture (3 Units)
Table 2: Common Instruction Set Operations
_____________________________________________________________________________
Dr. Asunogie Taibat Onome
[email protected]
CSC 315: Computer Organization and Architecture (3 Units)
Table 3: Processor Actions for Various Types of Operations
Data Transfer
The most fundamental type of machine instruction is the data transfer instruction. The data transfer
instruction must specify several things. First, the location of the source and destination operands must
be specified. Each location could be memory, a register, or the top of the stack. Second, the length of
data to be transferred must be indicated. Third, as with all instructions with operands, the mode of
addressing for each operand must be specified.
The choice of data transfer instructions to include in a instruction set exemplifies the kinds of trade-offs
the designer must make. For example, the general location (memory or register) of an operand can be
indicated in either the specification of the opcode or the operand. Table 4 shows examples of the most
common IBM EAS/390 data transfer instructions. Note that there are variants to indicate the amount of
data to be transferred (8, 16, 32, or 64 bits). Also, there are different instructions for register to register,
register to memory, memory to register, and memory to memory transfers. In contrast, the VAX has a
move (MOV) instruction with variants for different amounts of data to be moved, but it specifies
whether an operand is register or memory as part of the operand. The VAX approach is somewhat
easier for the programmer, who has fewer mnemonics to deal with. However, it is also somewhat less
compact than the IBM EAS/390 approach because the location (register versus memory) of each
operand must be specified separately in the instruction.
In terms of processor action, data transfer operations are perhaps the simplest type. If both source and
destination are registers, then the processor simply causes data to be transferred from one register to
another; this is an operation internal to the processor. If one or both operands are in memory, then the
processor must perform some or all of the following actions:
1. Calculate the memory address, based on the address mode.
2. If the address refers to virtual memory, it translate from virtual to real memory address.
3. Determine whether the addressed item is in cache.
4. If not, issue a command to the memory module.
_____________________________________________________________________________
Dr. Asunogie Taibat Onome
[email protected]
CSC 315: Computer Organization and Architecture (3 Units)
Table 4: Examples of IBM EAS/390 Data Transfer Operations
Arithmetic
Most machines provide the basic arithmetic operations of add, subtract, multiply, and divide. These are
invariably provided for signed integer (fixed-point) numbers. Often they are also provided for floating-
point and packed decimal numbers. Other possible operations include a variety of single-operand
instructions; for example,
Absolute: Take the absolute value of the operand.
Negate: Negate the operand.
Increment: Add 1 to the operand.
Decrement: Subtract 1 from the operand.
The execution of an arithmetic instruction may involve data transfer operations to position operands for
input to the ALU, and to deliver the output of the ALU. Figure 2 illustrates the movements involved in
both data transfer and arithmetic operations. In addition, of course, the ALU portion of the processor
performs the desired operation.
Logical
Most machines also provide a variety of operations for manipulating individual bits of a word or other
addressable units, often referred to as “bit twiddling.” They are based upon Boolean operations.
Some of the basic logical operations that can be performed on Boolean or binary data are shown in
Table 5. The NOT operation inverts a bit. AND, OR, and Exclusive-OR (XOR) are the most common
logical functions with two operands.
EQUAL is a useful binary test. These logical operations can be applied bitwise to n-bit logical data
units.Thus, if two registers contain the data (R1) = 10100101
(R2) = 00001111 then
(R1) AND (R2) = 00000101
_____________________________________________________________________________
Dr. Asunogie Taibat Onome
[email protected]
CSC 315: Computer Organization and Architecture (3 Units)
With one word set to all 1s, the XOR operation inverts all of the bits in the other word (ones
complement). In addition to bitwise logical operations, most machines provide a variety of shifting and
rotating functions. The most basic operations are illustrated in Figure 5. With a logical shift, the bits of
a word are shifted left or right. On one end, the bit shifted out is lost. On the other end, a 0 is shifted in.
Logical shifts are useful primarily for isolating fields within a word. The 0s that are shifted into a word
displace unwanted information that is shifted off the other end.
_____________________________________________________________________________
Dr. Asunogie Taibat Onome
[email protected]
CSC 315: Computer Organization and Architecture (3 Units)
For example, suppose we wish to transmit characters of data to an I/O device 1 character at a time. If
each memory word is 16 bits in length and contains two characters, we must unpack the characters
before they can be sent. To send the two characters in a word;
1. Load the word into a register.
2. Shift to the right eight times. This shifts the remaining character to the righthalf of the register.
3. Perform I/O. The I/O module reads the lower-order 8 bits from the data bus.
The preceding steps result in sending the left-hand character. To send the right-hand character;
1. Load the word again into the register.
2. AND with 0000000011111111. This masks out the character on the left.
3. Perform I/O.
The arithmetic shift operation treats the data as a signed integer and does not shift the sign bit. On a
right arithmetic shift, the sign bit is replicated into the bit position to its right. On a left arithmetic shift, a
logical left shift is performed on all bits but the sign bit, which is retained. These operations can speed
up certain arithmetic operations. With numbers in twos complement notation, a right arithmetic shift
corresponds to a division by 2, with truncation for odd numbers. Both an arithmetic left shift and a
logical left shift correspond to a multiplication by 2 when there is no overflow. If overflow occurs,
arithmetic and logical left shift operations produce different results, but the arithmetic left shift retains
the sign of the number.
Because of the potential for overflow, many processors do not include this instruction, including
PowerPC and Itanium. Others, such as the IBM EAS/390, do offer the instruction. Curiously, the x86
architecture includes an arithmetic left shift but defines it to be identical to a logical left shift.
Rotate, or cyclic shift, operations preserve all of the bits being operated on. One use of a rotate is to
bring each bit successively into the leftmost bit, where it can be identified by testing the sign of the data
(treated as a number). As with arithmetic operations, logical operations involve ALU activity and may
involve data transfer operations. Table 6 gives examples of all of the shift and rotate operations
discussed earlier.
Conversion
Conversion instructions are those that change the format or operate on the format of data. An example
is converting from decimal to binary. An example of a more complex editing instruction is the EAS/390
Translate (TR) instruction. This instruction can be used to convert from one 8-bit code to another, and
it takes three operands: TR R1 (L), R2
The operand R2 contains the address of the start of a table of 8-bit codes. The L bytes starting at the
address specified in R1 are translated, each byte being replaced by the contents of a table entry
indexed by that byte. For example, to translate from EBCDIC to IRA, we first create a 256-byte table in
storage locations, say, 1000-10FF hexadecimal. The table contains the characters of the IRA code in
the sequence of the binary representation of the EBCDIC code; that is, the IRA code is placed in the
table at the relative location equal to the binary value of the EBCDIC code of the same character.
Thus, locations 10F0 through 10F9 will contain the values 30 through 39, because F0 is the EBCDIC
_____________________________________________________________________________
Dr. Asunogie Taibat Onome
[email protected]
CSC 315: Computer Organization and Architecture (3 Units)
code for the digit 0, and 30 is the IRA code for the digit 0, and so on through digit 9. Now suppose we
have the EBCDIC for the digits 1984 starting at location 2100 and we wish to translate to IRA. Assume
the following: Locations 2100–2103 contain F1 F9 F8 F4.
R1 contains 2100.
R2 contains 1000.
Then, if we execute TR R1 (4), R2 locations 2100–2103 will contain 31 39 38 34.
_____________________________________________________________________________
Dr. Asunogie Taibat Onome
[email protected]