Click here to Skip to main content
15,748,477 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:

I am confused about the concept of the Offset Operator

Here is an example from my textbook (suppose bVal was located at offset 00404000):

bVal Byte ?

mov esi, OFFSET bVal ; ESI = 00404000

From what I understand from this example is that OFFSET simply returns the address of any variable, such as bVal.

This is ok so far, but the next example shows that OFFSET does something else, which is confusing.


byteVal BYTE 10h

mov esi, OFFSET byteVal
mov al, [esi] ; AL = 10h

Why is al = 10h? shouldn't AL contain the address of bVal, according to the previous example?

Also, how is it possible that esi can be moved to al, which is a smaller size than esi?

What I have tried:

I have tried to understand what the textbook is saying but the examples show contradicting information.
Updated 10-Jun-16 14:58pm

1 solution

The difference is between using the value directly or from memory address.

mov esi, OFFSET byteVal
Here the address of byteVal will be put into register esi (assume 00404000 as in the example)

mov al, [esi] ; AL = 10h
Here the esi is put between brackets, like [esi], meaning not to use the value directly (value is 00404000) but use it as an address and load the byte from that memory into register AL.

So the meaning changes using the brackets. An easier example would be:
Lets say that on address 1 in memory there is a value 5 stored.
Lets also say that AL is 0 (using for example XOR AL, AL)
When you would execute:
ADD AL, 1; AL would be 1 (0 + 1 = 1)

But, lets clear AL to 0 again and now do:
ADD AL, [1]; AL would now be 5. Instead of using value 1 directly it uses the value from memory address 1, which is 5.

Hopefully this will make it somewhat more clear.

Good luck!
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900