It’s pretty easy to understand that computers run the software, such as an operating system or a web browser. However, it’s even generally known that software is developed by writing code in any of the many programming languages. Typically, that code is compiled into a format the computer can run.
Computers can’t understand python, C, Java, or any other programming language. It needs any instructions to be provided in the format of its instruction set. The instruction set is a collection of computer instructions. Each detail what operation is to be performed and on what data. The most common computer instruction set is x86. Specifically, the x86-64 variant is also referred to as AMD64.
Instruction Set Completeness
There are four main categories of instruction that are needed for a computer to be able to operate. Arithmetic, logical, and shift instructions. Instructions to move data between system memory and the registers. Input and output instructions. Program control and status instructions.
Arithmetic, logical, and shift instructions allow the computer to perform computations. This subset of instructions is used to perform actual computations. All the data the CPU needs to operate on is stored in RAM. For the CPU to be able to access it to operate on it. However, the data must be in the processor registers. As such, instructions that move data between RAM and the registers are critical to performance.
While computers do many things, there is typically some human interaction. Capturing these interactions and dealing with them is critical in keeping computers interactive. Further, computer code can often split into two distinct branches, and a choice must be made as to which one to take. These are known as branch instructions and are necessary for complex programming, including for and while loops. Control instructions are also core to ensuring that operations take place in the correct order.
What Is an Instruction?
An instruction is a defined piece of functionality that a processor can execute. An operation is typically displayed with a short form instruction name. The actual instruction is encoded as a short opcode. Many operations need to perform their operation on some data. The address information for this data is known as operands. The most basic operation is generally known as NOP. NOP is short for “no operation.” NOP doesn’t require any further operands as it instructs the CPU to sit idle for one clock cycle. In x86, NOP is encoded as 0x90.
JMP is another operation. It adjusts the program counter that points to the next instruction. Generally, the next instruction to be executed is the next instruction in the list. However, this can’t be true for both cases when you get to a branching statement. JMP allows a branch to jump forward or backward to a set of instructions, potentially far away, allowing the software to continue as intended. In x86, JMP is encoded as 0xE9…0xEB, 0xFF/4 and 0xFF/5. JMP will take an operand that details the memory address to which the program counter needs to be updated to point to the correct next instruction.
Computer instruction, also known as machine instruction, is a single instruction as part of an Instruction set. Instructions detail the exact operations for a processor to complete. Most, but not all, need to operate on data and are called alongside operands. These operands point to registers that contain the data to be operated on.