flat assembler
Message board for the users of flat assembler.

Index > Heap > AH + AL = AX + E = EAX ... is that right?

Author
Thread Post new topic Reply to topic
Redragon



Joined: 27 Nov 2004
Posts: 101
Location: U.S.
Redragon
i not sure if this is right, but could someone tell me? this is what ive come up with, but i dont know if its true or if something is left out


AH + AL = AX + E = EAX

8 + 8 = 16 + 16 = 32

byte + byte = word + word = double word


thanks!
Post 09 Sep 2005, 00:57
View user's profile Send private message Reply with quote
HyperVista



Joined: 18 Apr 2005
Posts: 691
Location: Virginia, USA
HyperVista
Hi Redragon,

Quote:
AH + AL = AX + E = EAX

8 + 8 = 16 + 16 = 32


Well, yes and no, not exactly. When the x86 architecture was 16-bit, we had eight 16-bit general purpose registers (AX being one of those eight). When Intel expanded the x86 architecture to 32-bit, they doubled the size of these general purpose registers, going from 16 to 32 bits and gave them new names by placing an "E" in front of each reigster name resulting in EAX, EBX, ECX, EDX, EBP, ESI, EDI, and ESP.

Fyi, There is no addressable or manipulable "E" as there is an addressable AL and an AH. Unfortunately, we can't address the upper 16-bit portion of the 32-bit registers separately; the "E" part of your equation. We can get to the lower 16 bits by addressing AX, but to get to the upper 16 bits we have to refer to EAX and get entire 32-bit register.

I suggest your equation should be:

(AH + AL = 16) + 16 = 32

Hope that helps.

- Hypervista
Post 09 Sep 2005, 01:37
View user's profile Send private message Visit poster's website Reply with quote
Redragon



Joined: 27 Nov 2004
Posts: 101
Location: U.S.
Redragon
now i see exactly what you mean, E is an extended part, just there to make it 32 bits, but is not an addressable part.. so of eax, would that technically make AX the low, and EAX the high part of EAX, if i understood that right?

soo... (AH + AL = AX) + E = EAX ?


Last edited by Redragon on 09 Sep 2005, 02:31; edited 1 time in total
Post 09 Sep 2005, 02:01
View user's profile Send private message Reply with quote
Ancient One



Joined: 28 Feb 2005
Posts: 55
Ancient One
there's no name for the high word of eax.
Post 09 Sep 2005, 02:26
View user's profile Send private message MSN Messenger Reply with quote
HyperVista



Joined: 18 Apr 2005
Posts: 691
Location: Virginia, USA
HyperVista
@Redragon

Quote:
soo... (AH + AL = AX) + E = EAX ?


Yes, you've got it!

You can address the lower half (16 bits) of EAX by calling out AX. You can also get AX in two separate 8-bit chunks. AL and AH are the addressable lower 16-bits of EAX (AL being the lower 8-bits and AH being the higher 8 bits within that lower 16-bits). EAX is not the high part of EAX, it's simply the entire 32-bits of that register. To access the high 16 bits of EAX, or any of the other seven general purpose registers, you have to "grab" the entire 32 bits and "mask off" the lower 16 bits. You can't simply grab the high 16 bits separately.

AncientOne is correct, there is no name for the upper half of the 32-bit general purpose registers.

- Hypervista
Post 09 Sep 2005, 11:38
View user's profile Send private message Visit poster's website Reply with quote
Redragon



Joined: 27 Nov 2004
Posts: 101
Location: U.S.
Redragon
now i definitly understand what your saying, it makes perfect sense, but i was wondering though, how do you know in which situations to use which register of say 32 bits.. or 16 bits

say you were doing this

cmp al,0x01

or

mov eax,0

in some situations if that eax is changed to say ebx, it messes it up.. is that because it dosent matter which register you use, but that there may already be something being put in that register previously in the code?

it may be a bit hard to understand what im asking but thanks.
Post 09 Sep 2005, 23:55
View user's profile Send private message Reply with quote
HyperVista



Joined: 18 Apr 2005
Posts: 691
Location: Virginia, USA
HyperVista
@Redragon,

Quote:
....how do you know in which situations to use which register of say 32 bits.. or 16 bits?


The general purpose registers are just that, general purpose, which means you can use any of them for a number of tasks. For example, they can be used to store off-set addresses, which when paired with one of the 16-bit segment registers, gives an exact address in memory.

The decision to use the lower 16 bits of a 32 bit register (AX for example as opposed to EAX) depends on the size of the value you want to store. Naturally, if you have a 32 bit value to store, you use EAX. If you have only 16 bits to store, you'd use AX instead (in most cases). Obviously, the corollary is also true; you can't put a 32 bit value into a 16 bit register (can't fit 10 pounds of crap in a 5 pound bag, so to speak) Very Happy

- Hypervista
Post 10 Sep 2005, 02:18
View user's profile Send private message Visit poster's website Reply with quote
Redragon



Joined: 27 Nov 2004
Posts: 101
Location: U.S.
Redragon
i knew about the size; not using a 32bit command in 16 bit, etc. but you did clarify when to use them.. but i was wondering like you said

Quote:
if you have a 32 bit value to store, you use EAX


but, of those 32 bit registers, would the one that you are going to use, depend on the situation your going to use it for? for example


Code:
mov   eax,003A6EA5h 
               mov   ecx,800*600    
               mov   edi,[ModeInfo]    
               rep   stosd    


instead of ecx, could you change it to a different register? say, edx? or would it be dependent on only certain ones?
Post 10 Sep 2005, 02:24
View user's profile Send private message Reply with quote
HyperVista



Joined: 18 Apr 2005
Posts: 691
Location: Virginia, USA
HyperVista
Ahhh .... yes. Very good question. There are limitations to some of the general purpose registers. I refer you to some of the assembly language tutorials to get the details.

For example, in real mode you can not use AX, CX, or DX to hold an off-set. There are other restrictions in the use of various registers under certain circumstances. The best advise I can give you is to crack the books on assembly language to learn those situations. Understanding these nuances of assembly language is the beauty and hell of learning to program in assembly.

- Hypervista
Post 10 Sep 2005, 02:48
View user's profile Send private message Visit poster's website Reply with quote
Ancient One



Joined: 28 Feb 2005
Posts: 55
Ancient One
Quote:

instead of ecx, could you change it to a different register? say, edx? or would it be dependent on only certain ones?

no u can't.. actually u can find this kind of info in the intel instruction set (volume II) manual. in ur example, ecx must be use as a counter for the rep instruction. the edi register is used as target destination, etc, etc. in some instructions, there are certain register that have special purpose. but for most instructions like add, sub, and others, u can use any combination of general purpose registers. read also volume I of the manual - the basic environment of the intel processor.
Post 10 Sep 2005, 03:41
View user's profile Send private message MSN Messenger Reply with quote
Matrix



Joined: 04 Sep 2004
Posts: 1171
Location: Overflow
Matrix
well i think this htread is fully related to assembly programming, instead heap, i'd recommend newbie section instead.

hmm, yes, its sometimes (many times if you make reg procedures) that whould be nice to access the high 16 bit part of eax,

but if you really need it, you can access it like
Code:
org 256

; put thing in high part eaxh
mov ax,[thing]
shl eax,16 ; make eaxl be eaxh

or, you can do it without affecting ax:
rol eax,16 ; roll eax by 16 bits
mov ax,[thing] ; this is hi part now
rol eax,16 ; roll eax by 16 bits again

int 20h
thing: db "hi"
    
Post 10 Sep 2005, 07:32
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar.

Powered by rwasa.