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?
Try with qemu-arm -L /usr/arm-linux-gnueabi/ ./a. out. before that you need to install arm-linux-gnueabi-gcc. And compile also using arm-linux-gnueabi-gcc.
qemu-arm is able to execute the ARM executable successfully on x86 machine. This enables us to write and test code of any architecture on usual x86 systems and then port only the final code on to the real system.
You are trying to run qemu in user mode. You also need to link the libraries which corresponds to arm.
take a look at the script files in below pkg.
http://wiki.qemu.org/download/linux-user-test-0.3.tar.gz
You will need to run qemu -L library_PATH_ARM ./a.out
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With