Page 1 of 1

How to separate 32-bit address into high 16-bit address and

Posted: Thu Jan 13, 2011 5:58 am
by leetow2003
Look:
GATE STRUC
OFFSETL DW 0
SELECTOR DW 0
DCOUNT DB 0
GTYPE DB 0
OFFSETH DW 0
GATE ENDS

and I define a gate varible in LDT:
32GATEA GATE <Low 16-bbit BEGIN address, 10h, 0, 8CH, high 16-bit BEGIN address>

and I define a code segment:
CODESEG SEGMENT PARA USE32
ASSUME CS:CODESEG
BEGIN:
...
CODESEG ends

I want to know how to separate symbol BEGIN into Low 16-bbit BEGIN address and
high 16-bit BEGIN address in 32GATEA?Thank you.

Re: How to separate 32-bit address into high 16-bit address

Posted: Thu Jan 13, 2011 8:10 am
by Tosi
If your assembler supports it,

Code: Select all

High address = ((addr >> 16) & 0xFFFF)
Low address = (addr & 0xFFFF)
Otherwise, do it with code:

Code: Select all

mov edx, addr
mov eax, addr
shr eax, 16
and edx, 0xFFFF
; eax contains the high word, and edx contains the low word.

Re: How to separate 32-bit address into high 16-bit address

Posted: Fri Jan 14, 2011 2:36 am
by Solar
I have written next to zero functional lines of assembler in my life, so consider this a question rather than a suggestion.

But wouldn't it suffice to, say...

Code: Select all

mov eax, addr
...and then read the high word out of eh, and the low word out of el?

That's how I understood it so far. Am I wrong?

Re: How to separate 32-bit address into high 16-bit address

Posted: Fri Jan 14, 2011 2:56 am
by qw
Solar wrote:...and then read the high word out of eh, and the low word out of el?
I guess you mean AH and AL? Those are the high- and low-order byte of AX, and AX is the low-order word of EAX, but there is no name for the high-order word of EAX. It is designed as this:

Code: Select all

+-------------------------------+
|              EAX              |
+ - - - - - - - + - - - - - - - +
|               |       AX      |
+ - - - - - - - + - - - + - - - +
|               |   AH  |   AL  |
+---------------+-------+-------+

Re: How to separate 32-bit address into high 16-bit address

Posted: Fri Jan 14, 2011 3:10 am
by Solar
Ah... right.

Code: Select all

mov eax, addr
mov low_word, ax
shr eax, 16
mov high_word, ax
That'd be it, no?

Re: How to separate 32-bit address into high 16-bit address

Posted: Fri Jan 14, 2011 4:10 am
by qw
Solar wrote:That'd be it, no?
That's correct.

Re: How to separate 32-bit address into high 16-bit address

Posted: Fri Jan 14, 2011 3:43 pm
by Tosi
I have been writing so much C (and C++ for school) code lately that my assembly has gotten inefficient.