fistpunch
Newbie level 4
I need to write an ARM assembly language routine that will replace a character in a string with another specified character and print the resulting string. You should return the pointer to the new string to the C program
The C driver code is below.
#include <stdlib.h>
#include <stdio.h>
extern char * subit( char *string, char this_c, char that_c ) ;
int main( int argc, char *argv[] )
{
char this_c= ‘e’ ;
char that_c = ‘x’ ;
char orgstr[] = "The quick brown fox jumped over the lazy dog" ;
char * result ;
result = subit( orgstr, this_c, that_c ) ;
printf( “old: %s\n”, orgstr ) ;
printf( “new: %s\n”, result ) ;
exit( 0 ) ;
}
I have part of the code done to check the length of the string which is:
stmfd sp!, {v1-v6, lr} ; standard entry
mov v1, #0 ; set index to zero
mov v2, #0 ; set count equal to zero
loop
ldrb v3, [a1, v1] ; get element
add v2, v2, #1 ; increment count
add v1, v1, #1 ; increment index
cmp v3, #0 ; end of string
bne loop ; end loop
sub v2, v2, #1 ; one less element
mov a1, v2 ; return value to C
I dont know how to finish the rest. Can anyone help?
The C driver code is below.
#include <stdlib.h>
#include <stdio.h>
extern char * subit( char *string, char this_c, char that_c ) ;
int main( int argc, char *argv[] )
{
char this_c= ‘e’ ;
char that_c = ‘x’ ;
char orgstr[] = "The quick brown fox jumped over the lazy dog" ;
char * result ;
result = subit( orgstr, this_c, that_c ) ;
printf( “old: %s\n”, orgstr ) ;
printf( “new: %s\n”, result ) ;
exit( 0 ) ;
}
I have part of the code done to check the length of the string which is:
stmfd sp!, {v1-v6, lr} ; standard entry
mov v1, #0 ; set index to zero
mov v2, #0 ; set count equal to zero
loop
ldrb v3, [a1, v1] ; get element
add v2, v2, #1 ; increment count
add v1, v1, #1 ; increment index
cmp v3, #0 ; end of string
bne loop ; end loop
sub v2, v2, #1 ; one less element
mov a1, v2 ; return value to C
I dont know how to finish the rest. Can anyone help?