c - Assembly operator AND -


in order continue this: debugging c program (int declaration) decided test more code , see how compiler reacts it. decided try 1 test local variables:

#include <stdio.h> main() {   int a,b,c,d,e,f,g;   a=0xbeef;   b=0xdead;   c=0x12;   d=0x65;   e=0xfed;   f=0xaa;   g=0xfaceb00c;   a=a+b;   printf("%d",a); } 

ok did int a,b,c... test main's frame size , see sub $0x10,%esp growing up, (i'm under linux why maybe sub), sub $0x30,%esp here the gdb output "disas main" command:

   0x0804841c <+0>:  push   %ebp    0x0804841d <+1>:  mov    %esp,%ebp    0x0804841f <+3>:  ,    $0xfffffff0,%esp    0x08048422 <+6>:  sub    $0x30,%esp ;7 int vars 4-byte 7*4=28. 30 enough    0x08048425 <+9>:  movl   $0xbeef,0x14(%esp)    0x0804842d <+17>: movl   $0xdead,0x18(%esp)    0x08048435 <+25>: movl   $0x12,0x1c(%esp)    0x0804843d <+33>: movl   $0x65,0x20(%esp)    0x08048445 <+41>: movl   $0xfed,0x24(%esp)    0x0804844d <+49>: movl   $0xaa,0x28(%esp)    0x08048455 <+57>: movl   $0xfaceb00c,0x2c(%esp)    0x0804845d <+65>: mov    0x18(%esp),%eax    0x08048461 <+69>: add    %eax,0x14(%esp)    0x08048465 <+73>: mov    0x14(%esp),%eax    0x08048469 <+77>: mov    %eax,0x4(%esp)    0x0804846d <+81>: movl   $0x8048510,(%esp)    0x08048474 <+88>: call   0x80482f0 <printf@plt>    0x08048479 <+93>: leave      0x0804847a <+94>: ret     

this line: 0x0804841f <+3>:and $0xfffffff0,%esp , operator , why there large number?

and why offset in movl commands isn't negative like: movl $0xa,-0x4(%ebp) far know , logical operator 1 , 1 1, 0 , 0 0, 1 , 0 0 etc... if case, %esp has ebp value base frame address of called main function.

can of explain why compiled this?

i think i'm missing something. edit: saw "topics" on stackoverflow talking this. going share: link1 link2 link3

  • why offset in movl $0xbeef,0x14(%esp) not negative?

because unlike in other example, addressing relative esp, not ebp. esp on 1 end of stack, esp on other one. in order address inside current stack frame, need add esp or subtract ebp.

  • why and $0xfffffff0,%esp?

for alignment. @blackbear explains in answer previous question: debugging c program (int declaration)


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -