You know that C uses pointers to pass parameters by reference. Consider the following C program from CLAB7:
/* clab73c.c */
#define number 12
int adder(int x, int *py)
{
return x + *py;
}
int main()
{
int a, b, c;
a = 1; b = number;
c = adder(a, &b);
}
The GCC assembler produces the following assembly language code
(with a few of my comments inserted):
68K GAS clab73c.s page 1
1 .file "clab73c.c"
2 gcc2_compiled.:
3 __gnu_compiled_c:
4 .text
5 .even
6 .globl adder
7 adder:
8 0000 4E56 0000 link.w %a6,#0 <-- zero-length stack frame created
9 0004 206E 000C move.l 12(%a6),%a0 <-- address &b
10 0008 222E 0008 move.l 8(%a6),%d1 <-- value a
11 000c D290 add.l (%a0),%d1 <-- value of b added to a
12 000e 2001 move.l %d1,%d0 <-- value returned in D0
13 0010 6000 0002 jbra .L1
14 .even
15 .L1:
16 0014 4E5E unlk %a6 <-- stack frame collapsed
17 0016 4E75 rts
18 .even
19 .globl main
20 main:
21 0018 4E56 FFF4 link.w %a6,#-12 <-- stack frame for a,b,c set up
22 001c 4EB9 0000 jsr __main
22 0000
23 0022 7201 moveq.l #1,%d1
24 0024 2D41 FFFC move.l %d1,-4(%a6) <-- a=1;
25 0028 720C moveq.l #12,%d1
26 002a 2D41 FFF8 move.l %d1,-8(%a6) <-- b=12
27 002e 200E move.l %a6,%d0
28 0030 5180 subq.l #8,%d0
29 0032 2F00 move.l %d0,-(%sp) <-- &b pushed onto stack
30 0034 2F2E FFFC move.l -4(%a6),-(%sp) <-- a pushed onto stack
31 0038 4EB9 0000 jsr adder
31 0000
32 003e 508F addq.l #8,%sp <-- clean up stack
33 0040 2D40 FFF4 move.l %d0,-12(%a6)
34 .L2:
35 0044 4E5E unlk %a6 <-- stack frame collapsed
36 0046 4E75 rts
68K GAS clab73c.s page 2
DEFINED SYMBOLS
clab73c.s:2 e0:00000000 gcc2_compiled.
clab73c.s:3 e0:00000000 __gnu_compiled_c
e0:00000000 .text
e1:00000048 .data
e2:00000048 .bss
clab73c.s:7 e0:00000000 adder
clab73c.s:20 e0:00000018 main
UNDEFINED SYMBOLS
__main
Note:
ANU Engineering - ENGN3213