如何在没有特定单词的情况下重写字符串?

时间:2015-03-18 04:33:47

标签: assembly arm

好吧,麻烦就是没有发现这个词。我遇到的问题是实际上重写字符串的过程没有需要删除的单词。

我遍历字符串,然后使用我的'检测'算法来查找单词。我在一个寄存器中保留了该单词的第一个字符的索引以供稍后使用(让我们称之为badWordIndex)。

然后我再次遍历整个字符串来删除该单词。一旦我到达badWordIndex,我将#3添加到字符串mid-loop的索引中,这样我就可以跳过指定的单词,并且它不会被我的strb指令存储。

在调试时,内存映射似乎没有跳过检测到的字。它像任何其他单词一样加载它的字符,存储它们并继续(基于内存映射中的红色十六进制)。

任何人都知道会出现什么问题?我怎么能以另一种方式做到这一点?

        AREA Question_1, CODE, READONLY
        ENTRY
        ldr r0, =STRING1 ;r0 points to STRING1 so that it can be accessed and used
EoS     equ 0
SpaceCh equ 32
        ldr r2, =STRING2 ;r5 points to STRING2 so that it can be accessed and used.

        ;'Detection Algorithm', it jumps to the 'remove' branch after an index of "the" substring is found.


remove  mov r0, r6
Loop    ldrb r3, [r0], #1
        strb r3, [r2], #1 ;POST-INDEXED
        cmp r0, r4 ;compare r0 to index of "the" substring..
        beq delete ;..otherwise add 3 to r0 so it skips the "the" substring thus 'deleting' it.
        cmp r3, EoS ;compare r3 to null ascii char..
        bne Loop ;.if they aren't equal, continue traversing the string.
        mov r0, r6
        b Case1
delete  add r0, r0, #3  ;add 3 to r0 so that it skips the "the" substring- this does not work as intended..

        b Loop ;continue traversing string since we know that Case1 is not complete.
skip            ;skip removal since no "the" substring exists.

endless b endless ;loop endlessly as requested in instructions for assignment.

STRING1 dcb "and the man said they must go" ;String1
;EoS        dcb "" ;null char in ascii
;SpaceCh    dcb " " ;space char in ascii
STRING2 dcb " " ;the destination of the string after all "the" words are removed.
        END

0 个答案:

没有答案