Consider the following C program from CLAB7:
/* clab71c.c (Clements, page 145) */ int main() { int i,j; i = 1; j = 2; return i + j; }This simple program has two integer local variables, i, j. The GCC assembler produces the following assembly language code (with a few of my comments inserted):
68K GAS clab71c.s page 1 1 .file "clab71c.c" 2 gcc2_compiled.: 3 __gnu_compiled_c: 4 .text 5 .even 6 .globl main 7 main: 8 0000 4E56 FFF8 link.w %a6,#-8 <-- stack frame for i, j set up 9 0004 2F02 move.l %d2,-(%sp) 10 0006 4EB9 0000 jsr __main 10 0000 11 000c 7401 moveq.l #1,%d2 12 000e 2D42 FFFC move.l %d2,-4(%a6) <-- i=1; 13 0012 7402 moveq.l #2,%d2 14 0014 2D42 FFF8 move.l %d2,-8(%a6) <-- j=2; 15 0018 222E FFFC move.l -4(%a6),%d1 16 001c D2AE FFF8 add.l -8(%a6),%d1 <-- i+j 17 0020 2001 move.l %d1,%d0 <-- return i+j; 18 0022 6000 0002 jbra .L1 19 .even 20 .L1: 21 0026 242E FFF4 move.l -12(%a6),%d2 22 002a 4E5E unlk %a6 <-- stack frame collapsed 23 002c 4E75 rts 68K GAS clab71c.s page 2 DEFINED SYMBOLS clab71c.s:2 e0:00000000 gcc2_compiled. clab71c.s:3 e0:00000000 __gnu_compiled_c e0:00000000 .text e1:0000002e .data e2:0000002e .bss clab71c.s:7 e0:00000000 main UNDEFINED SYMBOLS __main
Don't let the apparent complexity confuse you; note that:
ANU Engineering - ENGN3213