Checking if an address is page-aligned
Posted: Sat Jan 28, 2012 1:29 pm
Hey,
I'm following JamesM's tutorial and I'm reading the part about paging. To check if an address is NOT page-aligned he uses this code:
I don't understand how AND can be used to do this. For the statement to be true the result of (placement_address & 0xFFFFF000) should be 1, right?
So first I tried doing the AND operation on a value that is page-aligned:
8192 AND 0xFFFFF000
000000000000000000010000000000000
AND
100000000000000000000000000000000
=
000000000000000000000000000000000
Then on a value that is not page-aligned:
000000000000000000010000000000001
AND
100000000000000000000000000000000
=
000000000000000000000000000000000
Which gave the same result, so how can that code be used to determine if its page-aligned?
Can MOD be used?
E.g.
It feels like there is something I don't understand, please help me!
Link to the tutorial: http://www.jamesmolloy.co.uk/tutorial_h ... aging.html
I'm following JamesM's tutorial and I'm reading the part about paging. To check if an address is NOT page-aligned he uses this code:
Code: Select all
if(placement_address & 0xFFFFF000) {
// NOT aligned
}
So first I tried doing the AND operation on a value that is page-aligned:
8192 AND 0xFFFFF000
000000000000000000010000000000000
AND
100000000000000000000000000000000
=
000000000000000000000000000000000
Then on a value that is not page-aligned:
000000000000000000010000000000001
AND
100000000000000000000000000000000
=
000000000000000000000000000000000
Which gave the same result, so how can that code be used to determine if its page-aligned?
Can MOD be used?
E.g.
Code: Select all
if(placement_address % 0x1000) {
// NOT aligned
}
Link to the tutorial: http://www.jamesmolloy.co.uk/tutorial_h ... aging.html