The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: sayang on February 14, 2009, 07:05:54 AM

Title: Question from newbie
Post by: sayang on February 14, 2009, 07:05:54 AM
Hi,

just learn masm about 2 days and little bit confuse the benefit or usage of using eax,ah and al.

maybe this is such stupid question and so sorry about that but i still dont understand and need some reference.

my question is like this.

1.

mov al,1
mov ah,2

what's the value of EAX now? is it 3 ?

How to display value in integer for EAX?


Thank you to any help.





Title: Re: Question from newbie
Post by: donkey on February 14, 2009, 07:14:25 AM
Hi sayang,

No, the value is not 3. It works like this

EEEEEEEEEEEEEEEEHHHHHHHHLLLLLLLL
EEEEEEEEEEEEEEEEXXXXXXXXXXXXXXXX


Where E is the upper 16 bits, H is the high 8 bits of the (old) 16 bit X register and L is the lower 8 bits. So when you move something into AL it moves it into the lower 8 bits...

mov AL, 1

EAX = 00000000000000000000000000000001 = 1

If you move something into the AH register it is moved into the upper 8 bits of the X register...

mov AH, 1

EAX = 00000000000000000000000100000000 = 256

To move something into the complete lower half of the register you use AX...

mov AX, 257

EAX = 00000000000000000000000100000001 = 257

The E part or the Extended part of the register is not directly addressable, you have to move a full 32 bits into the register, replacing the contents of AL/AH/AX

So if you mov 1 into AL and 1 into AH the result is 257.
Title: Re: Question from newbie
Post by: sayang on February 14, 2009, 07:37:56 AM
Thanks  :U

you have enlighten me  :toothy
Title: Re: Question from newbie
Post by: PBrennick on February 14, 2009, 02:08:17 PM
Remember, even though the upper 16 bits of eax are not directly addressable, they will certainly have an impact on the result of any changes you may make to AX (or AH and/or AL). When doing 8 bit (or 16 bit calculations, it is always best to clear eax first (or mask the upper 16 bits.

Donkey sure hit on an easy way to see what is what.  :U

Paul