Do machine language instructions include input numbers or do they require inputs from user or other device?

StackOverflow https://stackoverflow.com/questions/14476272

Question

I have been reading about e.g. 32-bit microprocessor architectures. I have a simple question: if the maximum number of bits in a floating point number is 32 bits, then how does that number get into the microprocessor for processing? Can it be as part of a machine language instruction? Because if the answer is yes, wouldn't it have to constitute the entire machine language instruction (in other words, there would be no room left for control bits or opcodes or anything else, since all 32 bits would be used for the number itself). Is that how it is actually done, i.e. is there a machine language command that says "attention CPU: the next machine language command you will read is not actually a command; it is actually a number".

Or, alternatively, does all "data" that gets fed to a computer have to come in separately, not as part of the machine language instructions?

In particular, I would like to know how Intel microprocessors handle this issue.

Was it helpful?

Solution

My assembly is a bit rusty, but what I can remember is that there is specific registers for instructions, and specific registers for data. So you would literally move your next data item into the relevent registers, and then shove your desired instruction into the AX(?) register.

But, I caution - last time I wrote assembly was back in 2004....

OTHER TIPS

all the data on the cpu moves via a central bus or other channels. Data is stored either in memory or the caches although there is not much room in the cache. Let's say you use the inc eax; command, the inc itself is a information that was fetched from the RAM. Thing is, there are intra-cpu commands like the one above, where the EAX gets incremented. Then there are commands that required outside data. For these commands, a part of the instruction is an address itself. In later Intel cpus, it's possible to add an operand in the instruction itself, by it's smaller. The address in the instruction is either a pointer to the data you need or a pointer to a pointer of the data you need.

Bottom line, a CPU looks for instructions. If the first thing it gets booted with is not an instruction, the cpu would still treat it as a number and that'll mess up everything.

example: let's say we have a 8 bit CPU, the first thing in the memory that gets loaded in the cpu should be an instruction, so let's say it gets 01001010, then the opcode is 01, (add or w.e), then the instruction would be to add w.e is at the address 001010 to the accumulator

Damn I suck at explaining this

Often, machine language instructions can consist of several words. So one word is the instruction next word or words are associated immediate data (a value to put to register, or memory address to operate on). This is how things work on CISC processors, like Intel x86 related architectures.

But you are onto something. In RISC architectures, it's common that each instruction is exactly one word. In this case, to load a 32 bit value, two instuctions are needed. In other words, there is a one-word instruction to load a value with less bits, and then another one-word instruction to load rest of the bits, when needed. Very often 2nd instruction is not needed, the "small" value might still have 24 bits, which is enough for most number values in program code..

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