我有一个字符串," Kwjlmfhrdsb%atm%azi3 \ n",如果十进制中的ascii值为奇数或偶数,则必须读取和更改。我的字符串在每个位置都被更改。预期的输出是:" Froqhkmwing \ yh \ d。"但是,我得到了输出:" .roqhkmwing \ yh \ d。"我尝试逐步检查gdb,但似乎' F' F' F' F' (' K'更改为' F')正确存储到r1中。我不明白为什么它只是字符串中第一个具有错误字符的索引。如果有人能够了解这里发生的事情,我们将不胜感激。
.global _start
_start:
mov r7, #4
mov r0, #1
ldr r1, =string @ get addresss of string
mov r5, #0 @ index
loop:
ldrb r3, [r1, r5] @getting value at string[i]
@ add r6, r1, r5
cmp r3,#10 @checking for new line at end of string
beq print
and r4, r3, #1 @if odd, r4 = 1
cmp r4, #1 @checking if odd
beq odd @branch if odd
@ else add 5 if even
add r3, #5
b temp
mid_loop:
add r5, #1 @incrementing index
bal loop @go back to loop
temp:
strb r3, [r1] @storing new character back into the same index
@ strb r3, [r6]
bal mid_loop
odd:
sub r3, #5
bal temp
print:
mov r7, #4
mov r0, #1
mov r2, #21
ldr r1, =string
swi 0
b _exit
_exit:
mov r7, #1
swi 0
.data
string: @ 12345678901234567890
.asciz "Kwjlmfhrdsb%atm%azi3\n"