- Check out the following C program:
/home/cs255000/demo/c-asm/main.c
int x;
int main( )
{
x = x + 44;
}
|
- Compile the
main.c program
with this command:
/home/cs255001/bin/cc255 -S main.c
|
The cc255 (C compiler for 255)
will
produce the
assembler program
main.s:
...
ldr r3, .L3 // This is the variable x !!!
ldr r3, [r3]
add r3, r3, #44 // This is the add operation for x+44 !!
ldr r2, .L3
str r3, [r2]
mov r3, #0
mov r0, r3
...
.L3:
.word x // .L3 is the variable x
|
There are lots of stuff that you don't need to understand; but the
gist is:
- This example shows you that
the
compiler translates
the high level (C) program statements into
assembler instructions
that performs the
same operation (add !) specified
by the high level program statements
|
So Java/C is
an artificial language for
the computer.
The language that
the computer uses is:
the assembler langange !!!
Note:
- Every CPU (chip)
has its own
assembler language !!!
|
- You can compile
the assembler program
main.s with:
/home/cs255001/bin/cc255 -c main.s
|
The C compiler will
invoke the assembler
to
produce the
machine (object) program code
main.o
You can view the content of the
(binary) object file using this command:
/home/cs255001/bin/dump255 main.o
|
You will see this output:
Disassembly of section .text:
00000000 :
0: e52db004 push {fp} ; (str fp, [sp, #-4]!)
4: e28db000 add fp, sp, #0
8: e59f3020 ldr r3, [pc, #32] ; 30
c: e5933000 ldr r3, [r3]
10: e283302c add r3, r3, #44 ; 0x2c
14: e59f2014 ldr r2, [pc, #20] ; 30
18: e5823000 str r3, [r2]
1c: e3a03000 mov r3, #0
20: e1a00003 mov r0, r3
24: e28bd000 add sp, fp, #0
28: e49db004 pop {fp} ; (ldr fp, [sp], #4)
2c: e12fff1e bx lr
30: 00000000 .word 0x00000000
|
The list of hexadecimal numbers in
red represent
the binary machine instruction codes !!!
(The blue text
contains the source
assembler instructions).
These binary numbers are
the computer instructions that
are stored in memory when the program
is run --- the CPU will fetch them one by one and execute it when
the program is run.
|