Martin has 16 years experience in Human Resources Information Systems, has a PhD in Information Technology Management, and a degree in Information Systems Management. He is an adjunct professor of computer science and computer programming.
The Instruction Set
The closer we get to the core of a computer, the more unfamiliar things may appear. In fact, we are getting closer and closer to the atoms of the computer: the 1s and 0s! This is the language of the machine, rather than a language we are used to using. At this level, you can still talk to the processor and tell it what to do.
An instruction set (used in what is called ISA, or Instruction Set Architecture) is code that the computer processor (CPU) can understand. The language is 1s and 0s, or machine language. It contains instructions or tasks that control the movement of bits and bytes within the processor.
But if it's 1s and 0s, how do we actually communicate with the processor? Systems programmers use assembly language, which is a type of programming language. The statements are assembled into machine language--into the instructions that the processor can understand. Assembly language is a lot like machine language with labels--because binary alone would quickly get hard to keep track of.
What makes up an instruction set? When we start talking about 1s and 0s, machine language, assembly language, and registers, it might all become murky. Let's start with the overall structure of an instruction and go from there.
The instruction set consists of a limited set of unique codes that let the processor know what to do next, along with some basic rules of how to express them. We can explain more about it using the following:
- Instruction length (this can vary)
- Opcodes (the command to be carried out)
- Operands (what the command will operate on)
- Registers (internal locations--limited in number and ability, but quick to access)
- Memory (external storage--a larger and more versatile number of locations, but slower to access)
So what is an instruction? Let's take a look at instructions and instruction length.
About an Instruction
An instruction can vary in length depending on the architecture. In x86 systems, the length of the instruction is typically 1 to 3 bytes (for the opcode), plus a number of bytes needed for the operands, depending on the addressing mode. What's an addressing mode? Different operations may be performed directly on pure numbers, indirectly on numbers in internal registers, or very indirectly on locations in main memory. Each of those is a different addressing mode.
Additionally, shorter instructions do not always mean faster instructions. Sometimes a short instruction hides a lot of machine cycles. Think of riding a bike that is too small for you; you might be pedaling faster, but are you really getting there faster?
The instruction itself is made up of a bit pattern (those 1s and 0s again), but in assembly, you will see syntax such as MOV, ADD, and CMP. These are called mnemonics rather than opcodes (a mnemonic is something that makes another thing easier to remember). For example, to add two operands such as the number 42 to the contents of the EAX register, the code is:
ADD EAX, 42
About Instruction Length
An instruction is a specific length, as specified by the ISA. However, consider the following instruction, shown in this figure appearing here that we've labeled Figure 1:
The length of an instruction is dependent on how much can be specified in the least number of bits. Some instructions, like the one in Figure 1, can be specified in just 16 bits or two bytes (also called a word). That's because these two 6 bit operands can only specify something that can be described with 6 bits, in the previous example. We can specify 32 different things with 6 bits, which is often enough to specify a register. But if we need to specify a memory location in main memory, it can take 4 bytes or more to specify each address.
Operands and Opcodes
Another feature of an instruction set relates to operations and operands. That is, what is actually going on in there? How do we actually carry out the instruction and tell the processor what to do? This is where assembly language comes in.
Appearing below are sample assembly statements using the MOV command. The first operand is the destination and the second operand is the source. You can specify immediate values, registers, or locations in main memory as the operands (in several ways too, to save time when moving lots of data).
This example will load the number 9 into the EAX register:
mov eax, 9
This example will move the contents of the EBX register into the EAX register:
mov eax, ebx
Registers and Main Memory
Registers are locations inside the CPU (central processing unit). There are a limited number of registers, but they are much faster to work with than main memory, because the processor does not have to access them on the computer bus.
Main memory is the general storage area of a computer. It holds a lot more data, but accessing it is much slower. Registers and main memory are both types of operands in the performance of an instruction.
Status Flags and the Program Counter
When statements are run, status flags are flipped within the processor, an action which tells it things like what happened as a result of this operation. A status bit or flag can be on/off (1 or 0). Since 1s and 0s are the machine's language, that works out well.
The CPU also needs to keep track of where we are in the current program. This is done with the program counter, which points to the current instruction.
Alright, let's take a moment to review what we've learned!
An instruction set is code that a CPU can understand. Instruction sets are part of ISA (Instruction Set Architecture). You can write code in assembly language, which is then assembled into machine language (the 1s and 0s the processor understands). The length of an instruction depends on several things, such as what type of operands it specifies. The actual instructions are programmed using assembly language mnemonics.
Operations may be done on pure numbers, or indirectly on the contents of registers or main memory. Each of those requires a different addressing mode, in which different operations may be performed directly on pure numbers, indirectly on numbers in internal registers, or very indirectly on locations in main memory.
Registers are special locations inside the CPU that are faster to work with. Status flags may be set when instructions are executed. A program counter is maintained by the machine and denotes the current instruction's address. As a computer architect, it is important to understand how ISA handles instructions and how assembly language is used to create machine language that the processor can understand.
To unlock this lesson you must be a Study.com Member.
Create your account
Register to view this lesson
Unlock Your Education
See for yourself why 30 million people use Study.com
Become a Study.com member and start learning now.Become a Member
Already a member? Log InBack