ARM ldrb将Wt设置为-1

时间:2017-04-25 14:35:07

标签: algorithm assembly arm

我在ARM中创建了一个函数,如果前一个位置中存在相同的字符,则删除重复的字符。如果找到一个,它将删除重复的字符并将所有值移过。

第一个参数(r0)是要检查重复项的字符的索引,第二个参数(r1)是要查看的数组。例如,如果r0是3并且r1指向“hello”,它将查看字符串中的第三个元素('l')并且在运行之后,字符串r1指向将变为“helo”并且r0将返回1,在r0。

我遇到的当前问题是第一个ldrb r2, [r1, r0]将r2设置为-1。我检查了ARM手册,ldrb返回了这样的错误,但是我找不到类似的东西。我想知道是否有人知道解决方案。

谢谢!

check_if_duplicate:
    push {r4, r5, lr}
    @ Get character at value i in r4
    ldrb r2, [r1, r0]
    mov r3, #0
duplicate_loop:
    @ Check if the target index is greater than the current index
    cmp r0, r3
    ble duplicate_done
    @ Check if current index is a duplicate
    ldrb r4, [r1, r3]
    cmp r4, r2
    @ Increment iterator and repeat loop if they are not equal
    addne r3, r3, #1
    bne duplicate_loop
    @ If they are equal, then shift all values over
duplicate_shift_loop:
    @ Find next value
    add r3, r3, #1
    @ Load next value
    ldrb r2, [r1, r3]
    @ Check if new value is the end of the array
    cmp r2, #0
    beq duplicate_shift_done
    @ Use previous index to store value
    sub r5, r3, #1
    @ Store vaue in previous address
    strb r2, [r1, r5]
    @ Do process again
    b duplicate_shift_loop
duplicate_shift_done:
    @ Store string ending byte
    sub r3, r3, #1
    mov r2, #0
    strb r2, [r1, r3]
    @ Set 1 as the return value
    mov r0, #1
    b d_done
duplicate_done:
    mov r0, #0
d_done:
    pop {r4, r5, pc}

0 个答案:

没有答案