Question

I am trying to write a while loop in ARM that checks if an array position contains a dash, if it does not, it will subtract the offset by 7 and check again. If it finds the dash, it will store an 'X' symbol there. When I run this, I get a segmentation fault. My prediction is that it is something wrong with the way I am storing it at the very last line of the program. Any ideas? Here is my code:

 /*Store input into array*/
store:    
    ldrb    r4,[sp]          /*store the value at sp in r4*/
    add     r4, r4, #34      /*increase r4 by 34 to give the offset*/
    ldr     r5, =array       /*r5 points to the first index in array*/
    mov     r2, #0x2D        /*r2 contains the dash symbol '-'*/
storeWhile:     /*While loop for store*/
    ldrb    r6, [r5,r4]      /*r6 contains address of array + the offset*/
    cmp     r6, r2           
    beq     empty            /*if(array[offset] == '-') branch*/
    sub     r4, r4, #7       /*else, subtract offset by 7*/
    cmp     r4, #0           
    bge     storeWhile       /*if(offset >= 0) branch back to start of loop*/
empty:  
    mov     r2, #0x58
    str     r2, [r6]         /*Store r2 (Uppercase X) into posotion at array + offset (r6)*/

Thanks a lot!

Était-ce utile?

La solution

mov     r2, #0x58
str     r2, [r6]

doesn't really make sense. Store instructions (str Rd, [Rn]) saves Rd in Rn. You probably want something like this

mov     r6, #0x58
str     r6, [r5,r4]

You should be also use subs instead of sub then cmp.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top