0

When browsing through the x86 Assembly Language Reference Manual, I came across this definition of an immediate operand:

Operands can be immediate (that is, constant expressions that evaluate to an inline value), [...]

If I got it correctly, an expression returns a value. Does a constant expression then return a constant value? Does inline value mean that it will be substituted by some other value after having undergone the process of assembly?

2 Answers 2

5

Does a constant expression then return a constant value?

Yes. An immediate operand creates a constant value in an opcode. Like mov eax, 3 creates an opcode consisting of several bytes - according to x32/x64 Intel Manual.

B0+ rb ib MOV r8, imm8 OI Valid Valid Move imm8 to r8. B8+ rw iw MOV r16, imm16 OI Valid Valid Move imm16 to r16. B8+ rd id MOV r32, imm32 OI Valid Valid Move imm32 to r32. C6 /0 ib MOV r/m8, imm8 MI Valid Valid Move imm8 to r/m8. C7 /0 iw MOV r/m16, imm16 MI Valid Valid Move imm16 to r/m16. C7 /0 id MOV r/m32, imm32 MI Valid Valid Move imm32 to r/m32. 

For example: For 32-bit-mode the following byte combinations do represent the valid opcodes. This means for mov destination, 3 there are several possibilities:

 b0 03 mov al, 3 66 b8 03 00 mov ax, 3 b8 03 00 00 00 mov eax, 3 c6 45 00 03 mov byte ptr [xxx], 3 66 c7 45 00 03 00 mov word ptr [xxx], 3 c7 45 00 03 00 00 00 mov dword ptr [xxx], 3 

B0h and B8h represent a one-byte opcode, C6h and C7h represent a two-byte opcode consisting of an opcode byte and a Mod/RM-byte coding the addressing mode - in this case indirect addressing. 66h designates an Operand-Size Prefix indicating that the following instruction uses an 16-bit(out-of-address-mode) operand - an exception compared to the normal 32-bit mode operand. An 8-bit operand is encoded with another opcode. The remaining bytes are the encoding of a 8/16/32-bit value of 3.

Does inline value mean that it will be substituted by some other value after having undergone the process of assembly?

No. Assembl(y|ing) is the process of incorporating constant values into resulting opcodes(seqeunces of bytes). In a way, everything is inline in assembly.

Sign up to request clarification or add additional context in comments.

Comments

1

It just means that the expression must be a value that can be calculated during assembly. Examples of constant expressions include:

5 5+5 5*5 MyConstant (where this constant is defined somewhere else) MyConstant*4 

Values for all above can be determined by the assembler and substituted with the value of the expression.

In contrast, non-constant expressions have values that cannot be determined during assembly. Examples include:

ah (a register) ah*al (expression containing registers) [0x800] (a memory location) 

2 Comments

Would you mind telling me what the actual meaning of "inline" in the context of assembly languages is?
@MaxHerrmann I have not seen the word inline used in assembly manuals, but here it seems to just mean "a constant value". Note that mov eax, 1+2 and mov eax, 1+1+1 and other variants of constant expressions returning 3 all assemble into simply mov eax, 3. I.e. they are expressions that are evaluated by the assembler.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.