Search code examples
assemblyalignment

Test address is aligned at n byte just checks the lower 8-bit not the whole bits


i have a question about testing address whether is aligned at N-BYTE boundary ....

consider that we are in 64-BIT mode ....

in C language, we do something like this :

if(((unsigned long) str & 15) == 0) {}

here we check the whole 64-BIT address (test str & 15)

but i saw the generated assembly code and the generated code is:

test dil, 15

in fact, it's going to test just the lower 8-bit !!! so why it's just test the lower 8-bit and it's not something like this

test rdi, 15

or even this

test edi, 15

?


Solution

  • i found my answer .... when we want to check an address is aligned at 16-byte boundary or not, it's just important to check the first 4-bit of address whether is zero or not ... so it's ok to check just the lower 8-bit of the address ...