News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Question about mov(constant, mem);

Started by ketchup, March 16, 2008, 11:28:15 PM

Previous topic - Next topic

ketchup

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

Sevag.K

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


ketchup

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

Sevag.K

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.

Randall Hyde

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


DarkWolf

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 ?
--
Where's there's smoke, There are mirrors.
Give me Free as in Freedom not Speech or Beer.
Thank You and Welcome to the Internet.

Randall Hyde

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