Jump to content

  • Log In with Google      Sign In   
  • Create Account

Immediate values come from the ALU?

  • You cannot reply to this topic
6 replies to this topic

#1 gasto   Members   -  Reputation: 243


Posted 24 February 2014 - 03:29 PM

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.


#2 Paradigm Shifter   Crossbones+   -  Reputation: 4784


Posted 24 February 2014 - 03:41 PM

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

#3 Álvaro   Crossbones+   -  Reputation: 10629


Posted 24 February 2014 - 04:16 PM

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).

#4 gasto   Members   -  Reputation: 243


Posted 24 February 2014 - 04:42 PM

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

#5 Paradigm Shifter   Crossbones+   -  Reputation: 4784


Posted 24 February 2014 - 04:57 PM

ALU is electronics though?

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

#6 frob   Moderators   -  Reputation: 16182


Posted 24 February 2014 - 07:37 PM

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.
Check out my personal indie blog at bryanwagstaff.com.

#7 King Mir   Members   -  Reputation: 1782


Posted 25 February 2014 - 01:10 AM

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.