PinheadLarry
PinheadLarry

Reputation: 117

understanding the keywords eax and mov

I am trying to understand the registers in asm but every website I look at just assumes I know something about registers and I just cannot get a grip on it. I know about a books worth of c++ and as far as I know mov var1,var2 would be the same thing as var1 = var2, correct?

But with the eax register I am completely lost. Any help is appreciated.

Upvotes: 1

Views: 885

Answers (3)

Romaine Carter
Romaine Carter

Reputation: 655

Think of eax as a location in memory where a value can be stored, much like in c++ where int, long,... and other types specify the size of the location in memory of a variable. The eax register simply points to a storage location in memory, which on x86 computers is 32 bits. The e part of eax means extended. This register -> memory location is automatically used by the multiplication and division operators and normally called the extended accumulator register.

Upvotes: 0

davmac
davmac

Reputation: 20631

Consider registers as per-processor global variables. There's "eax", "ebx", and a bunch of others. Furthermore, you can only perform certain operations via registers - for example there's no instruction to read from one memory location and write it to another (except when the locations are denoted by certain registers - see movsb instruction, etc).

So the registers are generally used only for temporary storage of values that are needed for some operation, but they usually are not used as global variables in the conventional sense.

You are right that "mov var1, var2" is essentially an assignment - but you cannot use two memory-based variables as operands; that's not supported. You could instead do:

mov eax, var1
mov var2, eax

... which has the same effect, using the eax register as a temporary.

Upvotes: 3

Foo Bah
Foo Bah

Reputation: 26271

eax refers to a processor register (essentially a variable)

mov is an instruction to copy data from one register to another. So essentially you are correct (in a handwavey sense)

Do you have an example assembly block you want to discuss?

Upvotes: 0

Related Questions