I learn assembly language in one course. I have few problems getting started. I wrote 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, specifying the command:
arm-elf-gcc -S first.c
This generated the first.s file containing the 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 build code using the following command:
arm-elf-gcc -g first.s
Generated binary a.out file. Then I tried to run a.out using qemu using the command:
qemu-arm a.out
But it generates a conclusion
Segmentation fault
I canβt find the error, what am I doing wrong?