Immediate values come from the ALU?

Started by
5 comments, last by King Mir 10 years, 2 months ago

Are immediate values extracted from the ALU(Arithmetic logic unit)?

More code seems to be created (and hence program file size) when using many immediate values, but I assume it is stored in the program duration memory stack.

Intel Core 2 Quad CPU Q6600, 2.4 GHz. 3GB RAM. ATI Radeon HD 3400.
Advertisement

They are embedded in the machine code opcodes. On a CISC architecture they follow the opcode whereas on a RISC processor where all instructions are the same size some of the bits in the opcode are used for parts of the immediate value (so in 32 bit RISC architecture loading a 32 bit immediate value needs 2 instructions, one to load 16 bits and zero the other half of a 32 but register and another to logical-OR in the other 16 bits to the register). Static memory locations are immediate values too (kind of), but accessing values from registers (e.g. the stack pointer) uses indexed addressing (something like: load reg, contents of (sp+8)), so are usually shorter since the offset is usually restricted in range (-128 to +127, perhaps).

"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley

Why is this thread tagged "C Language" and "C++"? I am pretty sure in the context of those languages there is no such thing as an ALU, and even "immediate value" is a foreign concept (although there are constants, which are related).

It's assembly. Some people use assembly in C and C++.

Intel Core 2 Quad CPU Q6600, 2.4 GHz. 3GB RAM. ATI Radeon HD 3400.

ALU is electronics though?

"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley
This is an implementation detail that doesn't matter.

As far as the assembly programmer is concerned the data resides in a register or a memory address. When something is processed inside the CPU the black box does its magic, and the result is again stored in a register or memory address.

If you are an expert writing the optimizer inside a major compiler, and if you have studied the exact micro-architecture details, including a detailed study of the processor's internal timings, then it is possible that those details might help you with some extreme pigeonhole reordering optimizations in order to save one or two total CPU cycles, so perhaps it might save a few nanoseconds.

It has nothing to do with either C or C++ languages, and really almost has nothing to do with assembly programming.
Immediate values in assembly are stored as part of the encoding of an instruction. For variable length instruction architectures, it may be that an instruction containing an immediate value has a longer encoding, than it's register or memory counterparts.

This topic is closed to new replies.

Advertisement