assembly - What's wrong with this code in ARM -


i compiled simple program add 2 number , print on console.i have compiled on rpi board.i think compiled fine when run getting segmentation fault.

.text  .global main .extern print  out:    .ascii "the sum %d\n\0"  main:  push {ip,lr}  mov r0,#5  mov r1,#4  add r2,r1,r0   ldr r2,=out      bl printf  pop {ip,pc}  stop: b stop 

is because didn't follow arm eabi properly?

could let me know doing wrong?

the format string printf (out) needs go in r0, not r2. change:

ldr r2,=out 

to:

ldr r0,=out 

also if want print sum of 4 , 5 should in r1 (otherwise you're printing 4). change:

add r2,r1,r0  

to:

add r1,r1,r0  

Comments

Popular posts from this blog

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

php - Magento - Deleted Base url key -

android - How to disable Button if EditText is empty ? -