Reserved: Machine Instructions and Programs
Reserved: Machine Instructions and Programs
02
D
E
Machine Instructions
V
and Programs
R
E
S
Names of Sub-Units
E
Introduction to Machine Instructions and Programs, Addressing Modes, Assembly Language, Basic
R
Input and Output Operations, Subroutines, Additional Instructions, Encoding of Machine Instructions.
T
Overview
H
This unit begins by discussing the machine instructions and programs. Next, the unit discusses the
addressing modes and assembly language. Further the unit explains the basic input and output
IG
operations. This unit also discusses the subroutines. Towards the end, the unit discusses the encoding
of machine instructions.
R
Learning Objectives
Y
aa Define the machine instructions, data, and programmes are represented in assembly language.
aa Discuss the Input/Output activities that are controlled by a programme
C
Learning Outcomes
D
aa Assess the machine instructions and programme execution
E
Pre-Unit Preparatory Material
V
http://www.mhhe.com/engcs/electrical/hamacher/5e/graphics/ch02_025-102.pdf
R
aa
E
2.1 Introduction
S
Machine instructions and operand addressing information are represented by symbolic names in
assembly language. The instruction set architecture (ISA) of a CPU refers to the whole instruction set.
E
Machine instructions and operand addressing techniques that are common in commercial processors.
We need to provide a sufficient amount of instructions and addressing techniques to present complete,
R
realistic programmes for simple tasks. The assembly language is used to specify these generic
programmes.
T
We’ve now looked at a few simple assembly language applications. A programme, in general, works with
data stored in the computer’s memory. These records can be arranged in a number of ways. We can keep
IG
track of pupils’ names by writing them down on a list. We may organise this information in the form of a
table if we wish to connect information with each name, such as phone numbers or grades in particular
courses. Data structures are used by programmers to represent the data utilised in computations. Lists,
linked lists, arrays, queues, and other data structures are examples.
R
Constants, local and global variables, pointers, and arrays are often used in high-level programming
Y
languages. The compiler must be able to implement these structures utilising the capabilities given in
the instruction set of the machine on which the programme will be run when converting a high-level
P
language programme into assembly language. Addressing modes relate to the many methods in which
an operand’s location is stated in an instruction.
O
2
UNIT 02: Machine Instructions and Programs JGI JAIN
DEEMED-TO-BE UNIVERSITY
D
Auto increment (Ri)+ EA=[Ri]; Increment Ri
Auto decrement =(Ri) Decrement Ri EA=[Ri]
E
The description of these addressing modes is as follows:
V
zz Register mode: The operand is the contents of a processor register; the register’s name (address) is
specified in the instruction.
R
Instruction Register
E
Register Data
S
zz Absolute mode: The operand is stored in memory, and the location’s address is specified directly in
E
the instruction. (This mode is known as Direct in various assembly languages.)
R
Move LOC,R2
zz Immediate mode: The operand is given explicitly in the instruction.
T
Register R0 with the value 200. Obviously, the Immediate mode is only used to express a source
IG
operand’s value. In assembly languages, using a subscript to signify the Immediate mode is not
acceptable. The use of the sharp sign (#) in front of a value to signal that it is to be used as an
immediate operand is a frequent convention.
R
Move #200,R0
In high-level language applications, constant values are commonly employed. Consider the following
P
example:
O
A=B+6
holds the value of 6. This statement can be compiled as follows, assuming A and B have been declared
C
Move B,R1
Add #6,R1
Move R1,A
In assembly language, constants are also used to increment a counter, test for a bit pattern, and
so on.
3
JGI JAIN
DEEMED-TO-BE UNIVERSITY
Computer Organization and Architecture
zz Indirect mode: The contents of a register or memory location whose address is specified in the
instruction are the operand’s effective address.
Indirect method is divided into two types based on the availability of effective address:
1. Register indirect: In this method, the effective address is kept in the register, and the matching
register name is kept in the instruction’s address field. To access the data, one register reference
and one memory reference are required.
2. Memory Indirect: In this method, the effective address is stored in memory, and the matching
memory address is stored in the instruction’s address field. To access the data, two memory
D
references are necessary.
zz Index mode: By adding a constant value to the contents of a register, the operand’s effective address
E
is produced.
V
Example: MOV AX, [SI +05]
Relative mode: The Index mode determines the effective address by utilising the programme counter
R
zz
instead of the general-purpose register Ri.
E
zz Auto increment mode: The contents of a register provided in the instruction are the operand’s
effective address. The contents of this register are automatically increased to refer to the next item
S
in a list after accessing the operand.
E
Add R1, (R2)+ // OR
R1 = R1 +M[R2]
R
R2 = R2 + d
Auto decrement mode: The contents of a register provided in the instruction are decremented
T
zz
automatically before being utilised as the operand’s effective address.
H
R2 = R2-d
R1 = R1 + M[R2]
R
Patterns of 0s and 1s are used to represent machine instructions. When discussing or planning plans, such
tendencies are difficult to cope with. As a result, we refer to the patterns by symbolic names. To describe
P
the matching binary code patterns, we have so far utilised common terms like Move, Add, Increment,
and Branch for the instruction operations. Such phrases are usually substituted with abbreviations
O
called mnemonics, such as MOV, ADD, INC, and BR, when creating programmes for a certain machine.
We use the notation R3 to refer to register 3 and LOC to refer to a memory location in the same way. A
C
programming language, gen, is made up of a comprehensive collection of such symbolic names and
rules for their use. A programming language, often known as an assembly language, is made up of a
comprehensive collection of such symbolic names and rules for their use. The syntax of the language is
a set of rules for employing mnemonics in the definition of full instructions and programmes.
A programme called an assembler can automatically transform programmes written in an assembly
language into a series of machine instructions. The assembler programme is one of the utility
applications included in the system software. The assembler, like any other programme, is stored in
the computer’s memory as a series of machine instructions. A user programme is typically typed into
4
UNIT 02: Machine Instructions and Programs JGI JAIN
DEEMED-TO-BE UNIVERSITY
a computer through the keyboard and saved in memory or on a magnetic drive. At this stage, the
user programme is nothing more than a series of alphanumeric characters on a line. When you run
the assembler programme, it reads the user programme, analyses it, and then creates the machine
language programme you want. The latter comprises patterns of 0s and 1s that indicate the computer’s
instructions to be performed. A source programme is the user programme in its original alphanumeric
text format, while an object programme is the constructed machine language programme.
A computer’s assembly language may or may not be case sensitive, that is, it may or may not differentiate
between capital and lower case letters. To increase the readability of the text, we will use capital letters
to designate all names and labels in our examples. We’ll write a Move instruction as follows:
D
MOVE R0,SUM
E
The binary pattern, or OP code, representing the operation executed by the instruction is represented by
the mnemonic MOVE. This mnemonic is translated into binary OP code that the computer understands
V
by the assembler. At least one blank space character follows the OP-code mnemonic. Then comes the
information that defines the operands. The source operand in our case is in register R0. There are no
R
blanks between this information and the specification of the destination operand, which is separated
from the source operand by a comma. The destination operand is in the memory location SUM, which is
E
represented by its binary address.
S
Because there are numerous different ways to define operand locations, the assembly language must
declare which one is being utilised. To represent the Absolute mode, a numerical number or a word
E
used alone, such as SUM in the previous command, might be used. An immediate operand is generally
R
denoted by a sharp sign. As a result, the directive is:
ADD #5,R3
T
adds the number 5 to the contents of register R3 and returns the result to R3. The sharp symbol isn’t
the only technique to indicate that the mode is Immediate. The desired addressing mode is specified in
H
the OP code mnemonic in various assembly languages. In this example, distinct OP-code mnemonics
are used for different addressing modes for the same instruction. The preceding Add instruction, for
IG
The suffix I indicate that the source operand is supplied in the Immediate addressing mode in the
mnemonic ADDI. Indirect addressing is often defined by placing parentheses around the name or
Y
symbol indicating the operand’s pointer. If the number 5 is to be stored in a memory location whose
address is maintained in register R2, for example, the desired action can be expressed as:
P
MOVE #5,(R2)
O
MOVEI 5,(R2)
C
5
JGI JAIN
DEEMED-TO-BE UNIVERSITY
Computer Organization and Architecture
D
2.4 Basic Input and Output Operations
E
An efficient mode of communication between the central system and the outside environment is provided
V
by a computer’s I/O subsystem. It is in charge of the computer system’s entire input-output operations.
R
2.4.1 Peripheral Devices
E
Peripheral devices are input or output devices that are connected to a computer. These devices, which
are regarded to be part of a computer system, are designed to read information into or out of the
S
memory unit in response to commands from the CPU. Peripherals are another name for these gadgets.
For example: Keyboards, display units and printers are common peripheral devices.
E
There are three types of peripherals:
R
1. Input peripherals: These devices allow users to enter data from the outside world into the computer.
For instance, a keyboard, a mouse, and so on.
T
2. Output peripherals: These devices allow data to be sent from the computer to the outside world. For
instance, a printer, a monitor, and so on.
H
3. Peripherals for input and output: Allows both input (from the outside world to the computer) and
output (from the computer to the outside world) (from computer to the outside world). For instance,
IG
a touch screen.
R
program’s command triggers the transmission of each data item. Typically, the software is in charge
of data transmission between the CPU and peripherals. Transferring data through programmed I/O
P
The CPU remains in the programme loop in the programmed I/O technique until the I/O unit indicates
that it is ready for data transfer. This is a time-consuming procedure since it wastes the processor’s
time.
Interrupt started I/O can be used to solve this problem. The interface creates an interrupt when it
determines that the peripheral is ready for data transmission. When the CPU receives an interrupt
signal, it stops what it’s doing and handles the I/O transfer before returning to its prior processing
activity.
6
UNIT 02: Machine Instructions and Programs JGI JAIN
DEEMED-TO-BE UNIVERSITY
D
interrupt from the DMA controller when the transfer was finished.
E
2.5 Subroutines
V
In a given programme, it’s common to have to repeat a subtask several times with various data values.
A subroutine is a term used to describe such a subtask.
R
It is feasible to include the block of instructions that make up a subroutine at any point in the programme
E
where it is required. However, to save memory, just one copy of the instructions that make up the
subroutine is stored in memory, and any programme that needs to utilise it simply branches to the
S
beginning of the subroutine. We say that a programme is invoking a subroutine when it branches to it.
Call is the name of the instruction that conducts this branch action.
E
The calling programme must continue execution once a subroutine has been run, commencing
R
immediately after the instruction that called the function. By performing a Return instruction, the
subroutine is said to return to the programme that called it. Because the subroutine may be called from
several locations in a calling programme, it must be possible to return to the correct position. While
T
the Call instruction is being executed, the updated PC points to the place where the calling programme
resumes execution. As a result, the Call instruction must preserve the contents of the PC in order to
H
The subroutine linkage technique is the mechanism through which a computer allows you to call and
return from subroutines. The most basic way of linking subroutines is to save the return address in a
specified place, which may be a register devoted to this function. The link register is a type of register. The
R
Return instruction returns to the caller programme by branching indirectly through the link register
after the subroutine has completed its work.
Y
The Call instruction is a special branch instruction that does the following tasks:
In the link register, save the contents of the PC.
P
zz
7
JGI JAIN
DEEMED-TO-BE UNIVERSITY
Computer Organization and Architecture
respectively. A Move instruction with a zero immediate operand can also be used to replace Clear. As a
result, simply 8 instructions would have sufficed for our needs. However, considerable redundancy in
real machine instruction sets is not uncommon. Certain basic procedures may typically be carried out
in a variety of ways. Some options could be more effective than others. We’ll go over a couple more key
instructions that are included in most instruction sets in this section.
zz Logic Instructions: The basic building blocks of digital circuits are logic operations such as AND, OR,
and NOT applied to individual bits. It’s also useful to be able to conduct logic operations in software,
which is done using instructions that apply these operations separately and in parallel to all bits of
a word or byte. For instance, consider the instruction.
D
Not dst
E
zz Shift and Rotate Instructions: Many applications demand that the bits of an operand be shifted
right or left by a certain amount of bit positions. Whether the operand is a signed integer or some
V
more generic binary-coded information determines the specifics of how the shifts are executed. We
employ a logical shift for generic operands. We utilise an arithmetic shift for a number, which keeps
R
the integer’s sign.
zz Logical Shifts: Two logical shift instructions are required, one for left (LShiftL) and the other for
E
right (LShiftR) (LShiftR). These instructions shift an operand across a number of bit locations given
in the instruction’s count operand. A logical left shift instruction might have several different forms.
S
LShiftL count,dst
them as “machine instructions” on several occasions. Actually, the format in which the instructions were
provided is similar to that used in assembly languages, with the exception that we attempted to avoid
H
using acronyms for the various processes, which are difficult to remember and are likely to be peculiar
to a certain commercial processor. An instruction must be encoded in a compact binary pattern in order
IG
to be executed in a processor. Machine instructions are the correct term for such encoded instructions.
Assembly instructions are those that employ symbolic names and acronyms.
The assembler software is used to transform the language instructions into machine instructions. We’ve
R
seen instructions for adding, subtracting, moving, shifting, rotating, and branching. These instructions
can employ a variety of operands, including 32-bit and 8-bit integers, as well as 8-bit ASCII-encoded
Y
characters. An encoded binary pattern known as the OP code for the given instruction can be used to
specify the type of operation to be performed and the type of operands to be used. Assume that 8 bits are
P
set aside for this purpose, allowing you 256 distinct ways to define various instructions. The remaining
24 bits are used to specify the remaining information.
O
Add R1, R2
In addition to the OP code, the registers R1 and R2 must be specified. If the CPU has 16 registers, each one
requires four bits to identify. For each operand, additional bits are required to signal that the Register
addressing mode is being utilised.
The Instruction is:
Move 24(R0), R5
8
UNIT 02: Machine Instructions and Programs JGI JAIN
DEEMED-TO-BE UNIVERSITY
16 bits are needed to represent the OP code and the two registers, as well as a few bits to indicate that
the source operand utilises Index addressing mode and that the index value is 24.
The instructions for the shift is:
LShiftR #2, R0
The move instruction is:
Move #$3A, R1
D
In addition to the 18 bits needed to describe the OP code, the addressing modes, and the register, the
immediate values 2 and #$3A must be specified. The size of the immediate operand is thus limited to
E
what can be expressed in 14 bits. Consider next the branch instruction:
Branch >0 LOOP
V
The OP code is 8 bits again, leaving 24 bits to define the branch offset. Because the offset is a two-
R
symbol integer, the branch target address must be within 223 bytes of the branch instruction’s position.
An alternative addressing mode, such as Absolute or Register Indirect, must be used to branch to an
E
instruction beyond this range. Jump instructions are branch instructions that make advantage of these
modes.
S
In all these examples, the instructions can be encoded in a 32-bit word, as shown in Figure 1:
E
R
8 7 7 10
OP code Source Dest Other info
T
Depicts a possible format. There is an 8-bit Op-code field and two 7-bit fields for specifying the source
and destination operands. The 7-bit field identifies the addressing mode and the register involved (if
C
any). The “Other info” field allows us to specify the additional information that may be needed, such as
an index value or an immediate operand.
But what if we wish to use the Absolute addressing mode to specify a memory operand?
The instruction
Move R2, LOC
9
JGI JAIN DEEMED-TO-BE UNIVERSITY
Computer Organization and Architecture
The OP code, the addressing modes, and the register all require 18 bits. This leaves 14 bits to express the
LOC-related address, which is plainly insufficient.
And #$FF000000. R2
In which case, the second word gives a full 32-bit immediate operand. If we wish to use the Absolute
addressing mode to provide two operands for an instruction, we can do so. for example
Move LOC1, LOC2
The operands’ 32-bit addresses must then be represented using two extra words. This method yields
D
instructions of varying lengths, depending on the number of operands and addressing modes employed.
We may create fairly complicated instructions using several words, which are quite similar to operations
E
in high-level programming languages. The name “complex instruction set computer” (CISC) has been
applied to processors that employ this sort of instruction set. The requirement that an instruction take
V
up just one word has resulted in a type of computer called as a limited instruction set computer (RISC).
Other constraints imposed by the RISC method include the need that all data modification is done on
R
operands existing in processor registers. Because of this limitation, the above addition would need a
two-instruction sequence:
E
Move (R3), R1
S
Add R1, R2
E
Only a part of a 32-bit word is required if the Add instruction only needs to identify the two registers.
As a result, we may be able to give a more powerful command with three operands:
R
Add R1, R2, R3
T
Conclusion 2.8 Conclusion
zz Machine instructions and operand addressing information are represented by symbolic names in
R
assembly language.
zz The assembly language is used to specify these generic programmes.
Y
zz Data structures are used by programmers to represent the data utilised in computations.
P
zz Constants, local and global variables, pointers, and arrays are often used in high-level programming
languages.
O
zz Addressing modes relate to the many methods in which an operand’s location is stated in an
instruction.
C
10
UNIT 02: Machine Instructions and Programs JGI JAIN
DEEMED-TO-BE UNIVERSITY
zz Peripheral devices are input or output devices that are connected to a computer.
zz I/O instructions written in a computer programme result in programmed I/O instructions.
zz The CPU remains in the programme loop in the programmed I/O technique until the I/O unit
indicates that it is ready for data transfer.
zz The speed of transmission would be improved by removing the CPU from the pipeline and allowing
the peripheral device to control the memory buses directly. DMA is the name for this method.
zz An instruction must be encoded in a compact binary pattern in order to be executed in a processor.
Machine instructions are the correct term for such encoded instructions.
D
zz The assembler software is used to transform the language instructions into machine instructions.
E
zz An encoded binary pattern known as the OP code for the given instruction can be used to specify the
type of operation to be performed and the type of operands to be used.
V
2.9 Glossary
R
Indirect mode: The contents of a register or memory location whose address is specified in the
E
zz
instruction are the operand’s effective address.
S
zz Index mode: By adding a constant value to the contents of a register, the operand’s effective address
is produced.
zz
E
Relative mode: The Index mode determines the effective address by utilising the programme counter
R
instead of the general-purpose register Ri.
zz Auto increment mode: The contents of a register provided in the instruction are the operand’s
effective address. The contents of this register are automatically increased to refer to the next item
T
zz Auto decrement mode: The contents of a register provided in the instruction are decremented
automatically before being utilised as the operand’s effective address.
IG
zz Register mode: The operand is the contents of a processor register; the register’s name (address) is
specified in the instruction.
zz Absolute mode: The operand is stored in memory, and the location’s address is specified directly in
R
the instruction.
Immediate mode: The operand is given explicitly in the instruction.
Y
zz
P
11
JGI JAIN
DEEMED-TO-BE UNIVERSITY
Computer Organization and Architecture
D
a. another register b. another memory location
c. other operands d. all of the mentioned
E
6. In a machine instruction format, S-bit is the __________.
V
a. status bit b. sign bit
R
c. sign extension bit d. none of the mentioned
7. The bit that the ‘REP’ instruction uses is __________.
E
a. W-bit b. S-bit
S
c. V-bit d. Z-bit
a. 8 bits
E
8. The operand is of __________ if a W-bit value is ‘1’.
b. 4 bits
R
c. 16 bits d. 2 bits
9. In which of the following mode the operand is stored in memory, and the location’s address is
T
a. Autodecrement mode
b. Register mode
IG
c. Absolute mode
d. Immediate mode
R
10. Instructions that transfer control to a preset address or an address specified in the instruction are
referred to as.
Y
12
UNIT 02: Machine Instructions and Programs JGI JAIN
DEEMED-TO-BE UNIVERSITY
D
a. direct addressing mode b. register addressing mode
c. register relative addressing mode d. register indirect addressing mode
E
V
B. Essay Type Questions
1. Addressing modes relate to the many methods in which an operand’s location is stated in an
R
instruction. Discuss the different types of addressing modes.
2. What do you understand by assembly language?
E
3. Peripheral devices are input or output devices that are connected to a computer. Discuss the different
S
types of peripheral devices.
4. Write the brief note on direct memory access. E
5. Discuss the shift and rotate instructions.
R
2.11 Answers AND HINTS FOR Self-Assessment Questions
T
H
Q. No. Answer
1. c. branch instructions
2. c. Operation code field & operand field
R
3. b. 1 byte
Y
4. a. 2 bytes
5. d. all of the mentioned
P
7. d. Z-bit
8. c. 16 bits
C
13
JGI JAINDEEMED-TO-BE UNIVERSITY
Computer Organization and Architecture
Q. No. Answer
15. d. register indirect addressing mode
D
in the instruction. (This mode is known as Direct in various assembly languages.)
E
Refer to Section Addressing Modes
2. A programming language, gen, is made up of a comprehensive collection of such symbolic names
V
and rules for their use. A programming language, often known as an assembly language, is made
up of a comprehensive collection of such symbolic names and rules for their use. Refer to Section
R
Assembly Language
E
3. There are three types of peripherals:
Input peripherals: These devices allow users to enter data from the outside world into the
S
computer. For instance, a keyboard, a mouse, and so on.
Refer to Section Basic Input and Output Operations E
4. The speed of transmission would be improved by removing the CPU from the pipeline and allowing
R
the peripheral device to control the memory buses directly. DMA is the name for this method. The
interface transfers data to and from the memory through the memory bus in this case. A DMA
controller is responsible for data transmission between peripherals and the memory unit. Refer to
T
5. Many applications demand that the bits of an operand be shifted right or left by a certain amount
of bit positions. Whether the operand is a signed integer or some more generic binary-coded
IG
information determines the specifics of how the shifts are executed. We employ a logical shift for
generic operands. We utilise an arithmetic shift for a number, which keeps the integer’s sign. Refer
to Section Additional Instructions
R
https://www.studocu.com/in/document/psg-college-of-technology/computer-architecture/m-
P
zz
morris-mano-solution-manual-computer-system-architecture/10775236
O
zz https://www.educba.com/what-is-assembly-language/
C
zz Discuss with the classmates about the manner in which sequences of instructions are transferred
from memory into the processor.
14