Question

Basic computer operation question but I'm not sure how to ask it. When we say that a computer has an instruction set, how does the computer know what that set is? Is it stored in a ROM chip? Is it stored in the CPU somewhere? Where did the manufacturer put it so that it can read a disk and start processing machine code?

Was it helpful?

Solution

Short answer: The actual circuitry in the processor of the computer is what "determines" the instruction set.

Relatively short answer: The software that runs on the processor is physically just patterns of electrical signals. The transistors in the computer switch on and off many, many, many times a second, modifying these patterns of signals based on other signals. For example, consider the mov instruction found on just about every processor out there:

mov dest, src

This is encoded by a certain electrical signal pattern "stored" in memory. That signal pattern activates certain transistors on and off in such a way that the signals stored at dest matches that at src, because of how the circuitry is wired.

Long answer: Take a class in computer architecture. :-)

OTHER TIPS

It sounds like you're conflating two different concepts:

Instruction set

An instruction set is the set of machine code instructions that the CPU is built to handle. The CPU doesn't have to load it from anywhere, it's built-in to the CPU itself. Examples of instruction sets are: Intel x86, MIPS.

Boot loader

The boot loader is a small program that tells the CPU how to get the computer started. Obviously it's written using the CPU instruction set, and usually resides in ROM or EEPROM or something. It tells the CPU how to interface with the disk to load a boot sector (which then loads more of the operating system). On a PC, the boot loader is part of the BIOS.

The instruction set is hardwired into the CPU...it's actually a result of the way the circuit is built, there isn't an actual space where the instructions are kept. When a computer starts, there's a small program on a ROM that knows how to initialize all the components and boot the OS. Because of the way a computer is built, this program is the first to run.

When we say a computer has a given instruction set, it refers to the set of instructions (operation codes) the processor can understand. A machine is digitally designed to understand the instructions it will be able to receive. When you design a CPU, one of the components is the decoder, which is the part of the CPU that decodes the electrical signals; and performs computations it was instructed to compute by those signals (the instruction). If you're interested in how computers work at the core, I suggest reading CODE or The Elements of a Computing Systems

The CPU has an instruction set it knows how to execute and when you switch it on the little CPU must be feeded with instructions. It makes sense if the arriving instructions are doing the boot procedure. Where do that instructions come from? Normally a ROM (e.g. EPROM).

You write code, which eventually compiles down to assembly instructions, which compile down ultimately into "machine code." When the CPU gets an instruction out of memory it decodes it. The decode process ends up setting various control bits within the processor pipeline that determine what the CPU does (loads/stores data, does math on operands, etc.). The instruction set determines how the hardware is implemented. It is effectively the essential set of operations that the processor is able to perform "in hardware."

When a processor is described as having e.g. the 6502 instruction set, what that means is that if the processor outputs signals to fetch an instruction from some address and receives certain data in return (e.g. the byte value $A9), the processor's subsequent actions will be as described in the documentation. The 6502, for example, would fetch a byte from the next address, and then copy that byte to the accumulator while it outputs an instruction fetch for the succeeding instruction.

In most cases, a processor doesn't acquire an instruction set any more than a light bulb acquires the ability to convert electricity into light. A processor is built to do certain things when it receives certain inputs; while today's processors are sufficiently complex that very sophisticated tools are required for their design (unlike 'ancient' times, where they were often designed using pens, pencils, and paper, and implemented using hand-cut ruby film), fundamentally processors do what they are built to do.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top