• 13
• 15
• 27
• 9
• 9

andl instruction

This topic is 3559 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

.file "hello.c" .def ___main; .scl 2; .type 32; .endef .text LC0: .ascii "Hello, world!\12\0" .globl _main .def _main; .scl 2; .type 32; .endef _main: pushl %ebp movl %esp, %ebp subl $8, %esp andl$-16, %esp movl $0, %eax movl %eax, -4(%ebp) movl -4(%ebp), %eax call __alloca call ___main movl$LC0, (%esp) call _printf movl $0, %eax leave ret .def _printf; .scl 2; .type 32; .endef In the above assembly, "andl$-16, %esp" This code "and"s ESP with 0xFFFFFFF0, aligning the stack with the next lowest 16-byte boundary. I don't understand this instruction andl. Could someone explain it for me?

Share on other sites
The instruction andl is a binary and on a long (32bit integer). In the example you gave, the value 0xFFFFFFF0 is anded with the esp register to perform stack alignment. The instruction in this form just sets the lowest four bits of esp to zero, while leaving the other bits as they are. This way esp ends up with a value that is a multiple of 16.

Share on other sites
It sounds to me like you just explained it to us [smile].

Do you understand what a bitwise 'and' does?
It performs the 'and' truth table operation on each bit from each of the numbers. If you and a binary bit with a one you get that bit, if you and with a zero you get zero. So since that hex number has all ones except for the last four bits, the last four bits become zero, hence truncating the original value of esp down to a multiple of 16 bytes.

Afaik the l means it operates on a long (32-bits).

Edit: Crosspost