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

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
leetow2003
Member
Member
Posts: 70
Joined: Fri Nov 19, 2010 6:54 pm

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

Post 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.
Tosi
Member
Member
Posts: 255
Joined: Tue Jun 15, 2010 9:27 am
Location: Flyover State, United States
Contact:

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

Post 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.
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

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

Post 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?
Every good solution is obvious once you've found it.
User avatar
qw
Member
Member
Posts: 792
Joined: Mon Jan 26, 2009 2:48 am

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

Post 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  |
+---------------+-------+-------+
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

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

Post 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?
Every good solution is obvious once you've found it.
User avatar
qw
Member
Member
Posts: 792
Joined: Mon Jan 26, 2009 2:48 am

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

Post by qw »

Solar wrote:That'd be it, no?
That's correct.
Tosi
Member
Member
Posts: 255
Joined: Tue Jun 15, 2010 9:27 am
Location: Flyover State, United States
Contact:

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

Post by Tosi »

I have been writing so much C (and C++ for school) code lately that my assembly has gotten inefficient.
Post Reply