The MASM Forum Archive 2004 to 2012

Project Support Forums => HLA Forum => Topic started by: ketchup on March 16, 2008, 11:28:15 PM

Title: Question about mov(constant, mem);
Post by: ketchup on March 16, 2008, 11:28:15 PM
Question about mov(constant, mem);

How is it possible that you can copy a constant to memory in one instruction, or is this not true?
Constants are also stored in memory. So is this also translated into a pair of instructions, like when copying from memory to memory?

Gr Eric
Title: Re: Question about mov(constant, mem);
Post by: Sevag.K on March 17, 2008, 12:06:46 AM
Constants are substitutions used at compile time and they don't exist in the memory of the object.

So if you have:

const myint := 1000;

These two instructions are identical as far as the assembler is concerned:

mov( myint, mem );
mov( 1000, mem );

Title: Re: Question about mov(constant, mem);
Post by: ketchup on March 17, 2008, 10:11:53 AM
Thx for your reply.

Where is 1000 located at runtime? Is it located in the code section?
I'm trying to understand what happens with the processor, the address bus, data bus, controle bus and memory when mov( 1000, mem ); is executed.
So actually my question is what happens step by step in a computer when mov( 1000, mem ); is executed.
Is this a useful questions to ask?

Gr Eric
Title: Re: Question about mov(constant, mem);
Post by: Sevag.K on March 17, 2008, 11:38:40 PM
Yes, it gets encoded as 6 bytes

66 B8 E8 03 00 00

As for the other part of your question, it could take a book to explain it all :)
Someone else might be able to give you a condensed version of an answer.
Title: Re: Question about mov(constant, mem);
Post by: Randall Hyde on March 20, 2008, 01:44:06 AM
Quote from: ketchup on March 17, 2008, 10:11:53 AM
Thx for your reply.

Where is 1000 located at runtime? Is it located in the code section?
I'm trying to understand what happens with the processor, the address bus, data bus, controle bus and memory when mov( 1000, mem ); is executed.
So actually my question is what happens step by step in a computer when mov( 1000, mem ); is executed.
Is this a useful questions to ask?

Gr Eric


The constant is encoded as part of the instruction.
MOV is a special case, the encodings $C6 (for byte operands) and $C7 (for word/dword operands) are encoded with a mod-reg-r/m byte containing %000 in the reg field and a register operand (if mod=%11) or a memory operand (if mod == %00, %01, or %10). The two-byte encoding is followed by zero to four bytes of address information (as specified by the MOD field) and 1 to 4 bytes of immediate data (depending upon the size of the instruction).

Other instructions have different immediate mode encodings (e.g., $80..$83 for the generic two-operand arithmetic instructions).

Someday, I'll finish "The Art of Disassembly" (due at the publisher in Sept) and it will explain all this in gory detail. In the meantime, the Intel or AMD documentation for the x86 can be your friend.
hLater,
Randy Hyde

Title: Re: Question about mov(constant, mem);
Post by: DarkWolf on March 22, 2008, 02:50:24 AM
Quote from: Randall Hyde on March 20, 2008, 01:44:06 AM

Someday, I'll finish "The Art of Disassembly" (due at the publisher in Sept) and it will explain all this in gory detail. In the meantime, the Intel or AMD documentation for the x86 can be your friend.


With the move to STDLIB v3 how out of date is the AOA tree edition ?
Title: Re: Beginners using stdlib v3.1
Post by: Randall Hyde on March 26, 2008, 05:50:12 PM
There is a frozen version of HLA, v1.99, that includes the stdlib v1.x.  That's what all beginners using AoA (treeware or electronic) should be using.  The HLA stdlib v3.x is just different enough that it would be frustrating for a beginner to try and figure things out. That, of course, is ignoring the issue of defects in the stdlib v3.1 (which, presumably, would go away at some point or another).

Once someone has mastered the basics, then upgrading to the latest HLA and stdlib might make sense. But when learning with AoA, they should stick with v1.99 (the frozen version).

hLater,
Randy Hyde