Representing Instructions in Computer
Last Updated :
14 Mar, 2022
An instruction is an order given to a computer processor by a computer program. Each instruction is a sequence of 0s and 1s. They help in describing the physical operation that the computer should perform. Registers are used for storing the data temporarily and performing the operations that the instruction is aimed at.
Description of ARM Fields:
1. Opcode represents the basic operation of the instruction.
2. Rd represents the register destination operand. The result obtained by performing the operation is stored here.
3. Rn represents the first register source operand.
4. Operand2 represents the second source operand (In case of Data Processing Instructions) and offset(address) in case of Data Transfer Instructions.
5. I represent the Immediate, if
- I = 0, then the second source operand registers.
- I = 1,then second source operand is 12 bit immediate(constant).
6. S represents the Set condition code. It is related to conditional branch instruction.
7. The condition represents the Condition. It is related to conditional branch instruction.
8. F represents the Instruction format, if
- F = 0,then it is Data Processing Format
- F = 1,then it is Data Transfer Format
Different Instruction Formats:
1. Data Processing(DP): Includes general arithmetic operations (Ex: Addition, Subtraction, etc.)
Condition | F | I | Opcode | S | Rn | Rd | Operand2 |
---|
4 bits | 2 bits | 1 bit | 4 bits | 1 bit | 4 bits | 4 bits | 12 bits |
2. Data Transfer(DT): Includes data transfer operations (Ex: Load, Store)
Condition | F | Opcode | Rn | Rd | Offset2 |
---|
4 bits | 2 bits | 6 bits | 4 bits | 4 bits | 12 bits |
Representation of ARM Field:
Each instruction is 32 bits long. In the figure, the above information is represented in a tabulated format. Here,
Reg refers to the Register numbers between 0 and 15.
Constant: 12 bit constant
Address: 12 bit address
ARM Instruction Encoding is also represented in the below figure.
ARM Instruction Encoding:
Instruction | Format | Condition | F | I | Opcode | S | Rn | Rd | Operand |
---|
ADD | DP | 14 | 0 | 0 | 4 | 0 | Register | Register | Register |
---|
SUB | DP | 14 | 0 | 0 | 2 | 0 | Register | Register | Register |
---|
ADD WITH IMMEDIATE | DP | 14 | 0 | 1 | 4 | 0 | Register | Register | Constant |
---|
LDR(LOAD) | DT | 14 | 1 | - | 24 | - | Register | Register | Address |
---|
STR(STORE) | DT | 14 | 1 | - | 25 | - | Register | Register | Address |
---|
Each of the segments of instruction is called a field. Opcode containing 4 bits(for DP) and 6 bits(for DT) indicates the type of operation that the instruction performs. (Ex: Addition, Subtraction, etc. in case of DP and Load or Store in case of DT). Rn containing 4 bits gives the number of the register which is the first source operand. Operand2 containing 12 bits gives the other source operand for the operation that is to be performed by the instruction. Rd containing 4 bits gives the number of the register that is to receive the sum and is called as Destination Register.
Note :
- Even though multiple formats(DP and DT) complicate the hardware, the complexity is reduced by keeping the formats similar.
- The first two fields and last three fields of the two formats are the same sizes and four of them have the same names.
- The length of the opcode field in DT format(6 bits) is equal to the sum of the lengths of three fields of DP format(Opcode, S, I: 4+1+1 bits).
- In the figures, the numbers are represented in a decimal number system but they are actually stored as binaries(0 and 1)
Translating ARM Instructions into Machine Instructions :
Example 1: Consider this ARM instruction.
ADD r3,r1,r2
Condition | F | I | Opcode | S | Rn | Rd | Operand2 |
---|
14 | 0 | 0 | 4 | 0 | 1 | 3 | 2 |
The values of the fields are represented in the table. The numbers are stored in the form of binary.
I = 0 because here the second source operand is a register but not a constant.
Opcode = 4(0100) corresponds to the Addition operation.
Since, it is an arithmetic operation, F = 0.
The value in,
Rn field is 1. (Because r1 is the first source operand)
Operand2 is 2. (Because r2 is the second source operand)
Rd field is 3. (Because r3 is destination register in which result achieved by
adding contents of registers r1 and r2 is stored)
Example 2: Consider this ARM instruction.
SUB r2,r2,#6
Condition | F | I | Opcode | S | Rn | Rd | Operand2 |
---|
14 | 0 | 1 | 2 | 0 | 2 | 2 | 6 |
I = 1 because here the second source operand is a constant.
Opcode = 2(0010) corresponds to the Subtraction operation.
Since, it is an arithmetic operation, F = 0.
The value in,
Rn field is 2. (Because r2 is first source operand)
Operand2 is 6. (Constant)
Rd field is 2. (Because r2 is destination register in which result achieved by subtracting 6 from r2 is stored).
Example-3: Consider this ARM Instruction.
LDR r4,[r3,#24]
Condition | F | Opcode | Rn | Rd | Offset2 |
---|
14 | 1 | 24 | 3 | 4 | 24 |
Opcode = 24(011000) corresponds to the Load operation.
Since,it is a data transfer operation, F = 1.
The value in,
Rn field is 3. (Because r3 is first source operand).
Address is 32. (offset to be added to the base register r3)
Rd field is 4.
In this way, ARM assembly instructions are translated into machine instructions.
Instruction Completeness:
The set of instructions are said to be complete if the instructions have each of the below categories:
- Arithmetic, logic, and shift instructions.
- Data Transfer Instructions (i.e., Load and Store).
- I/O instructions.
- Program control instructions include the instructions that check status conditions with the help of flags.
Similar Reads
Computer Organization and Architecture Tutorial In this Computer Organization and Architecture Tutorial, youâll learn all the basic to advanced concepts like pipelining, microprogrammed control, computer architecture, instruction design, and format. Computer Organization and Architecture is used to design computer systems. Computer architecture i
5 min read
Architecture of 8085 microprocessor A microprocessor is fabricated on a single integrated circuit (IC) or chip that is used as a central processing unit (CPU).The 8085 microprocessor is an 8-bit microprocessor that was developed by Intel in the mid-1970s. It was widely used in the early days of personal computing and was a popular cho
11 min read
Memory Hierarchy Design and its Characteristics In the Computer System Design, Memory Hierarchy is an enhancement to organize the memory such that it can minimize the access time. The Memory Hierarchy was developed based on a program behavior known as locality of references (same data or nearby data is likely to be accessed again and again). The
6 min read
Direct Memory Access (DMA) Controller in Computer Architecture In modern computer systems, transferring data between input/output devices and memory can be a slow process if the CPU is required to manage every step. To address this, a Direct Memory Access (DMA) Controller is utilized. A Direct Memory Access (DMA) Controller solves this by allowing I/O devices t
5 min read
Addressing Modes Addressing modes are the techniques used by the CPU to identify where the data needed for an operation is stored. They provide rules for interpreting or modifying the address field in an instruction before accessing the operand.Addressing modes for 8086 instructions are divided into two categories:
7 min read
Architecture of 8086 Introduction : The 8086 microprocessor is an 8-bit/16-bit microprocessor designed by Intel in the late 1970s. It is the first member of the x86 family of microprocessors, which includes many popular CPUs used in personal computers. The architecture of the 8086 microprocessor is based on a complex in
15+ min read
Cache Memory in Computer Organization Cache memory is a small, high-speed storage area in a computer. It stores copies of the data from frequently used main memory locations. There are various independent caches in a CPU, which store instructions and data. The most important use of cache memory is that it is used to reduce the average t
11 min read
Computer Organization and Architecture | Pipelining | Set 1 (Execution, Stages and Throughput) Pipelining is a technique used in modern processors to improve performance by executing multiple instructions simultaneously. It breaks down the execution of instructions into several stages, where each stage completes a part of the instruction. These stages can overlap, allowing the processor to wo
9 min read
RISC and CISC in Computer Organization RISC is the way to make hardware simpler whereas CISC is the single instruction that handles multiple work. In this article, we are going to discuss RISC and CISC in detail as well as the Difference between RISC and CISC, Let's proceed with RISC first. Reduced Instruction Set Architecture (RISC) The
5 min read
IEEE 802.11 Architecture The IEEE 802.11 standard, commonly known as Wi-Fi, outlines the architecture and defines the MAC and physical layer specifications for wireless LANs (WLANs). Wi-Fi uses high-frequency radio waves instead of cables for connecting the devices in LAN. Given the mobility of WLAN nodes, they can move unr
9 min read