2
$\begingroup$

Texts on microprocessors use lines like the following ones :

"The instructions in an instruction set of a microprocessors have their own address "

"In the first clock cycle the instruction is fetched from its address and then the operands (variables)

"It was a breakthrough to realize that both the instructions and variables can be stored in the memory "

In all these lines what is meant by "storing an instruction at a particular address " ?

I tried thinking about it and deconstruct it and it was alog the following lines : In case of an instruction like say ,ADD, when the address bus of the microprocessor assumes the values as in the bits of the address of an instructor , an adder circuit is activated and the values in the next two registers,following the one pointed by program counter ,are transferred to the adder circuit for computation .

I realize that Thinking along these lines result in complicated structures to facilitate a larger set of instructions but that is all I can come up with at present .

Please help me understand what exactly does it mean to store an instruction at an address . (I hope it's a bit confusing because an instruction by definition is not a number but a process or some action to be followed)

$\endgroup$
1
  • $\begingroup$ "The instructions in an instruction set of a microprocessors have their own address" is misleading info. The instruction set is the set of supported instructions, each have a specific opcode (numerical value). The program is a list of opcodes stored in memory, each having its own address (they are stored sequentially). The instruction set is not "stored", it is implicitly defined by the processor, which is able to interpret the opcodes. $\endgroup$
    – user16034
    Aug 18, 2022 at 14:31

4 Answers 4

2
$\begingroup$

There are many theoretical ways to express an (arbitrarily complex) function in numbers, historically starting with the abstract model known as the Turing Machine. Those aren't always efficient for real problems, and in engineering we've settled on a pretty straightforward model.

Microprocessors (CPU's) have an associated memory which holds instructions. (1) Instructions are discrete operations, which change the CPU is a well-defined way. There is a finite and numbered set of instructions. Instructions may have operands, such as registers to operate on, or constants to use, and these operands are also encoded as number.

The instruction pointer (or program counter) indicates where exactly in memory the next instruction is stored. It normally increments if an instruction finishes, but a jump or branch instruction can change it in different ways.

As instructions are stored as numbers, they must be decoded when the numbers are retrieved from memory. As you correctly assume, this is non-trivial. The instruction decoder will map an instruction number to a particular bit of hardware to implement the actual instruction.

Let's assume a new CPU design, not compatible with an existing CPU, to keep this simple. As a designer, we know have the freedom to choose which numbers are associated with which instructions. We're still talking CPU's, so a number is a bitstring. We can therefore decide that an instruction is a 32 bit number. We can say that the first bit decides whether the instruction is some type of jump instruction. If so, we send off the number bits to the hardware that changes the instruction pointer. Here we look at the 2nd bit to decide whether it's an unconditional jump. For simplicity, let's assume it is. The third bit may decide whether it's a branch (push IP on stack) or not. Decoding this bit is simple: if set, push. The 4th bit may indicate whether it's an absolute or relative jump. A relative jump would require us to use the arithmetic hardware of the CPU, so for simplicity assume we have an absolute jump. The 5th bit can decide whether to take the destination address from a register, or from an operand. Assuming we use an operand, we see that another number is needed from the instruction stream. This means we issue another read, using the incremented instruction pointer (operand follows instruction). The fetched operand value becomes the new instruction pointer.

1) It's irrelevant here whether this memory is shared with data, or if it's augmented with caches.

$\endgroup$
1
$\begingroup$

an instruction by definition is not a number but a process or some action to be followed)

Yes you are right, it is some kind of action to be followed but definitely every action has some code associated with it that tells CPU what to do.

what exactly does it mean to store an instruction at an address .

You can think it like , for example,a register has some opcode which tells CPU to add 5 to accumulator, that would be ,say like, ADD A,#5

This ADD A,#5 is actually a instruction that instructs Algorithmic unit to do addition and no doubt this instruction would be stored in some register, before it is executed.

$\endgroup$
3
  • $\begingroup$ Missing here: 1) Encode instructions as numbers. 2) Store these numbers in memory. 3) Concept of the program counter. $\endgroup$
    – Raphael
    Mar 15, 2017 at 6:33
  • $\begingroup$ If we associate numbers with instruction then that number will work as circuit selector number and data will be processed accordingly. $\endgroup$
    – Deep Joshi
    Mar 15, 2017 at 7:14
  • $\begingroup$ @DeepJoshi : Isn't that similar to what I was thinking about it $\endgroup$
    – itp dusra
    Mar 15, 2017 at 16:16
0
$\begingroup$

You say "If there is an ADD instruction in memory, then the adder is activated"...

You're missing something very important here: Your CPU doesn't know that there's an ADD instruction. So Step 1: Read the first byte or bytes of the instruction. Step 2: Figure out from the bytes read that it is an ADD instruction (or a JUMP instruction or whatever other instruction). Step 3: Knowing which kind of instruction it is, read however many further instruction bytes are needed. Step 4: Use the adder to perform the instruction. Step 5: Change the program pointer to point to the next instruction. And start all over again.

$\endgroup$
0
$\begingroup$

The text alludes to the fact in the early days of computing machines, the "program" was hard-wired, for instance via a board of switches or via electric wires drawn between terminals, or even directly read from punched tape/cards. Only data was stored in the working memory, instructions were... elsewhere.

But the engineers soon understood that the program itself could be handled like data and stored in memory instead of by separate hardware means. This is indeed how it universally works now, instructions being represented by numerical opcodes, kept in RAM at contiguous addresses and indexed by the Program Counter.

This is how the concept of a stored program emerged. Among the benefits, this gives the architecture much flexibility, allows very large programs and even lets the computer generate programs itself by transformation from other forms.

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.