Copyright © Cay S. Horstmann 2011 
This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 United
States License.
int fun(int x, int y)
{
int a;
int b;
...
while (a > b)
{
int x;
int a;
...
}
}
int x; // Global
int main()
{
int x; // Local
}



% means register: %eax$ means immediate value: movl $1, %eaxmovl $1, %eax ; 1 -> eax or eax = 1
addl $1, %eax ; eax = eax + 1
movl $1, 4(%esp) ; esp[4] = 1
push or
call, esp gets smallercall pushes return address, ret pops it into
eip. espesp is saved in ebp, and all
variables are accessed through ebp
pushl %ebp ; save old ebp
movl %esp, %ebp
subl $n, %esp ; skip over local variables
-n(%ebp)
movl $1, -16(%ebp) ; Translation of C instruction i = 1

Submit lab work to Sakai.
setup.exe
again and pick gcc4-core and gdb from the package
selection list, then run the installersudo
apt-get install gcc-4.5-base. libx11-dev and libncurses-dev and configure as
./configure --disable-werror. test.c
#include <stdio.h>
void fun()
{
int a = 1;
int b = a + 10;
printf("%d\n", b);
}
main() /* we don't look into main--it is special */
{
fun();
}
gcc -S test.c
Then look at the file test.s in a text editor
a and b allocated?int b = a +
10;printf statement with
while (a < b)
{
int a = b;
b--;
{
int b = a + 1;
printf("%d\n", b);
}
}
Where are the outer and inner a and b
allocated?
a into a global variable. How is a global
variable accessed in assembly? gcc -o test -g test.c
insight test
SOURCE to MIXED. fun by clicking on the code
line.fun, click on the
first {i} (Step Asm Inst) icon. movl $0x1,-0xc(%ebp)
ebp register?-0xc(%ebp) before the movl
instruction?movl instruction. What is the contents of
-0xc(%ebp) now?