Site hosted by Angelfire.com: Build your free website today!
NaN Title


To help clear up the confusion with byte ptr and [eax], here are some basic
examples:

mov dh, [eax]

Here, the compiler knows 'dh' is 8 bits, and your intructing the processor 
to fill 'dh' with the value ([...]) found at the address of eax. Since
the compiler knows the boundry is 8 bits, implied by the register 'dh' 
in the destonation, there is no problem at all.

mov dh, byte prt [eax]

IS THE EXACT SAME THING.. (it is just over kill, and maybe a bit
more readable)


So, why would you want to use byte ptr or word ptr preceeding an 
"at-the-address-of" ([...]) statement??

The answer is seen here:

; ebx == some address
mov [ebx], 3


Here is a delema for the compiler, it says "move the value three to the 
memory location at the address of ebx". Sounds straight forward, but 
the compiler likes to think in bits, and then WANTS to ask back 
"so is 3 a byte?, or is it a word?, how about a DWORD...?". It doesnt 
know how many bits of memory to use to store the given value!! To 
correctly perform this, you then use the byte ptr to store 3 in one byte 
of memory at the specified address (and likewise word ptr would use up 2
bytes of memory to store 3 in memory, etc.)

Proper solution:

; ebx == some address
mov byte ptr [ebx], 3

The memory location would look like: (remember little endian)

Before:
Some address: A4 02 87 .. ..

After:
Some Address: 03 02 87 .. ..

If the mov was:

; ebx == some addrss
mov word ptr [ebx], 3


Before:
Some address: A4 02 87 .. ..

After:
Some Address: 03 00 87 .. ..


Bottom line, if your thinking you need to use (...) ptr, ask youself if the
computer can figure out how many bits to move, by some DIRECT indication
(like 'dh').

I hope this helps...

NaN

Go Back?