flat assembler
Message board for the users of flat assembler.

Index > Main > Need Help With Quick Bounds Check

Author
Thread Post new topic Reply to topic
Hayden



Joined: 06 Oct 2005
Posts: 132
Hayden 07 Nov 2007, 09:33
I'ts a pretty dumb but I hope someone could save me some time. I want to take a memory address and calculate the upper and lower limits of that page.

so for memory mapping with 64k pages the address 12345 yields {0,65535} and address 98302 would yield {65536,131070}.

I know i can use MOD but i'm looking for the quickest and easeist way. ps. i can not assume pages to be 64k.

_________________
New User.. Hayden McKay.
Post 07 Nov 2007, 09:33
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 07 Nov 2007, 15:33
Code:
PAGE_SIZE = 65536 ; Always 2^n where n can go from 0 to 30
MOD_MASK = -PAGE_SIZE

calculate_bounds:; EAX = Address
mov edx, PAGE_SIZE-1
and eax, MOD_MASK
add edx, eax

ret ; EAX = lower limit; EDX = upper limit
    


[edit] Or maybe better
Code:
calculate_bounds:; EAX = Address 
and eax, MOD_MASK
lea edx, [eax+PAGE_SIZE-1]

ret ; EAX = lower limit; EDX = upper limit     
[/edit]
Post 07 Nov 2007, 15:33
View user's profile Send private message Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 4039
Location: vpcmpistri
bitRAKE 07 Nov 2007, 18:11
; assuming granularity is a power of two
add eax, granularity-1
and eax, 0-granularity
; EAX is upper bound (beyond page)
; just subtract page size to get lower bound
Post 07 Nov 2007, 18:11
View user's profile Send private message Visit poster's website Reply with quote
Hayden



Joined: 06 Oct 2005
Posts: 132
Hayden 08 Nov 2007, 08:53
thanks guys, the code i was useing was like this
persudo code...

UpperBounds = (address + grans) - (address mod grans)
LowerBounds = address - (address mod grans)

_________________
New User.. Hayden McKay.
Post 08 Nov 2007, 08:53
View user's profile Send private message 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 cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.