1

私はこのCドライバープログラムを持っています

#include <stdlib.h>
#include <stdio.h>

extern void subs( char *string, char this_c, char that_cr ) ;

int main(int argc, char *argv[] )
{
    char this_c= 'e' ;  
    char that_c = 'X' ;
    char orgstr[] = "sir sid easily teases sea sick seals" ;

    subs( orgstr, this_c, that_c ) ;
    printf( "Changed string: %s\n", orgstr ) ;

    exit( 0 ) ;
}

String の 'e' を 'x' に変更するアーム プログラムを作成する必要があります。これまでのところ、\

.global subs

subs:   
    stmfd sp!, {v1-v6, lr} //string entry
    mov v1, #0 //set index to 0
    mov v2, #0 // set count to 0


loop :
    ldrb    v3, [a1,v1] // get the first char
    cmp     a2,v3    //compare char if its the same to the one that has to b chang
    mov v3, a3   // change the character for the new character
    addeq   v2, v2, #1 //increment count
    add     v1, v1, #1 // increment index
    cmp v3,#0   //end of string
    bne     loop
    mov     a1,v2 //return value

    ldmfd   sp!, {v1-v6, pc}
.end

しかし、これは私に無限ループを与えており、私は立ち往生しています。問題がどこにあるかを理解するのを手伝ってくれる人はいますか??


だからこれは私がこれまで持っているものです、

.global subs

subs:   
    stmfd sp!, {v1-v6, lr} //string entry
    mov v1, #0 //set index to 0
    mov v2, #0 // set count to 0


loop :
    ldrb    v3, [a1,v1] // get the first char
    cmp     a2,v3    //compare char if its the same to the one that has to b chang
    moveq   v3, a3   // change the character for the new character
    addeq   v2, v2, #1 //increment count
    add     v1, v1, #1 // increment index
    cmp v3,#0   //end of string
    bne     loop
    mov     a1,v2 //return value

    ldmfd   sp!, {v1-v6, pc}
.end

実行されますが、文字は決して変更されません...、出力と最後は入力と同じです、何らかの理由で、a2レジストリはnullです...

4

2 に答える 2

1

コードにはいくつかの問題があります。これは宿題用ですか?

mov v3, a3無条件に新しい文字で上書きv3され、メモリに書き戻されることはありません (Pete Fordham が指摘したように)。v3文字列の終わりをチェックするときにも使用するため、に変更v3したばかりなので、ループを終了することはありませんa3voidCコードで戻り値を使用しようとすると問題が発生するとして宣言されている関数の戻り値も設定しています。

代わりに、おそらく次のようなことを行います(テストされていませんが、いくつかのアイデアが得られるはずです):

loop:
    ldrb v3, [a1], #1
    cmp a2, v3
    strbeq a2, [a1, #-1]
    cmp v3, #0
    bne loop
于 2012-11-08T15:20:53.257 に答える
1

この行は完全に間違っています

mov v3, a3   // change the character for the new character

これは、文字列への条件付きストアである必要があります。

streqb a3, [a1, v1]
于 2012-11-06T19:04:43.450 に答える