Let's say I load a file into memory. Now I go to offset 4df2 in there. How would I check that it's dword aligned?
At the moment I did this:
;ebx has offset in mem
start:
mov al bl
and al 00001111
cmp al 0
jz ok
cmp al 4
jz ok
cmp al 8
jz ok
cmp al 0C
jz ok
inc ebx
jmp start
ok:
Looks kindof silly to me though :rolleyes:
Anyone got a better idea?
:stupid:
At the moment I did this:
;ebx has offset in mem
start:
mov al bl
and al 00001111
cmp al 0
jz ok
cmp al 4
jz ok
cmp al 8
jz ok
cmp al 0C
jz ok
inc ebx
jmp start
ok:
Looks kindof silly to me though :rolleyes:
Anyone got a better idea?
:stupid:
To see if an address is DWORD aligned just AND it with 3 (ALIGNMENT - 1) and if the result is not zero it is not aligned...
mov eax, Address
and eax, 3
jnz NotAligned
mov eax, Address
and eax, 3
jnz NotAligned
I'm a fool.
Thanks Donkey !
btw: I saw this before:
add offset, 4
and offset, -4
but I couldn't somehow figure out how the hell that was supposed to work :tongue:
Thanks Donkey !
btw: I saw this before:
add offset, 4
and offset, -4
but I couldn't somehow figure out how the hell that was supposed to work :tongue:
It should be
add offset, 3
and offset, -4
IIRC
The add makes sure that if the offset is not dword aligned, it will round up. The and just make it aligned to dword.
add offset, 3
and offset, -4
IIRC
The add makes sure that if the offset is not dword aligned, it will round up. The and just make it aligned to dword.
Posted on 2004-06-22 23:19:16 by JimmyClif