I am learning arm assembly language in my one course. I am having little problem in getting started. I have written a simple c code:
int main()
{
int a = 10;
int b = 20;
int c = a+b;
}
And then I converted it to assembly code using gnu arm by giving the command:
arm-elf-gcc -S first.c
This generated a file first.s containing assembly code:
.file "first.c"
.text
.align 2
.global main
.type main, %function
main:
@ args = 0, pretend = 0, frame = 12
@ frame_needed = 1, uses_anonymous_args = 0
mov ip, sp
stmfd sp!, {fp, ip, lr, pc}
sub fp, ip, #4
sub sp, sp, #12
mov r3, #10
str r3, [fp, #-16]
mov r3, #20
str r3, [fp, #-20]
ldr r2, [fp, #-16]
ldr r3, [fp, #-20]
add r3, r2, r3
str r3, [fp, #-24]
mov r0, r3
sub sp, fp, #12
ldmfd sp, {fp, sp, pc}
.size main, .-main
.ident "GCC: (GNU) 3.4.3"
Then I compiled the assembly code using following command:
arm-elf-gcc -g first.s
This generated a.out binary file. Then I tried to run a.out with qemu using command:
qemu-arm a.out
But this generates output
Segmentation fault
I can't find the mistake, what am I doing wrong?