Assembly 如何重写没有特定单词的字符串?
好吧,问题是检测不到这个词。我遇到的问题是在不删除单词的情况下重写字符串的过程 我循环遍历字符串,然后使用“检测”算法查找单词。我将单词的第一个字符的索引保存在一个寄存器中,以便以后使用(我们称之为Assembly 如何重写没有特定单词的字符串?,assembly,arm,Assembly,Arm,好吧,问题是检测不到这个词。我遇到的问题是在不删除单词的情况下重写字符串的过程 我循环遍历字符串,然后使用“检测”算法查找单词。我将单词的第一个字符的索引保存在一个寄存器中,以便以后使用(我们称之为badWordIndex) 然后通过再次遍历整个字符串来删除该单词。一旦到达badWordIndex,我会在字符串中间循环的索引中添加#3,这样我就可以跳过指定的单词,而不会被strb指令存储 在我调试时,内存映射似乎没有跳过检测到的单词。它像任何其他单词一样加载它的字符,存储它们,然后继续(基于内存
badWordIndex
)
然后通过再次遍历整个字符串来删除该单词。一旦到达badWordIndex
,我会在字符串中间循环的索引中添加#3,这样我就可以跳过指定的单词,而不会被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
如果看不到你的代码,几乎不可能说出你做错了什么。不清楚
r4
和r6
被初始化为什么。一些明显的问题是,您正在寻找一个值为0的字节,即使您没有将这样一个字节放在STRING1
之后(使用dcb“foobar”,0
获得一个以NUL结尾的字符串),并且您只在STRING2
处为一个字节保留了空间。那么字符串中的第二个“the”
呢?您将3添加到skip,而不是4(包含空格),因此“它们”
也将包含您的子字符串。另外,您的strb r3,[r2]
在测试字符是否为子字符串的开头之前已经存储了该字符。所以你跳过了错误的3个字符。