.global main
.type main%function
@ r4 = argc
@ r5 = current offset
@ r6 = end offset
@ r7 = array argv
main:
mov r4,r0
ldr r0,=message
mov r5,#0 // initialize offset
mov r6,#4
mul r6,r4,r6 // calculate end offset
mov r7,r1 // put array argv in r7
loop:
ldr r1,[r7,r5] // load the argv element with offset r5
push {ip,lr} // save lr
bl printf
pop {ip,lr}
add r5,r5,#4 // go to next word
cmp r5,r6
bne loop // if I haven't reached the end offset, it does another cycle
end:
mov r0,#0 // clear exit code
bx lr // returns
message:
.asciz "%s\n"
Output:
$ ./a.out a
./a.out
Segmentation fault
but:
$ ./a.out
./a.out
so apparently the problems comes when I try to access the next element of the array... really don't know why... I'm new with arm and assembly..