Question
Assembler: ARM: String in Sting Hey guys, I need some help with my assembler program. My code does not count correctly at the hits. Can
Assembler: ARM: String in Sting
Hey guys, I need some help with my assembler program. My code does not count correctly at the hits. Can someone improve my code and comment everything out?
Here you will find the task:
Aims: Implementing algorithms in assembler programs with the smallest possible code size, as well as handling the debugger and simulator.
preparation Think of a subroutine (function) that should search for a character string in a text. The function receives the start address of the text to be searched (a string) and the start address of the character string to be searched for (a string) in registers R0 and R1. The number of times the character string to be searched for was found in the text should be returned in register R0. If the character string to be searched for is empty, the function returns the value 0. If the text to be searched is an empty string, the function returns the value 0. Possible calls: int searchStringInString (char *, char *); int main (void) { int number; char * text = "hello all right?"; char * search string = "ll"; char * empty string = ; Number = searchStringInString (text, search string); Number = searchStringInString (text, empty string); Number = searchStringInString (empty string, search string); Number = searchStringInString (empty string, empty string); return 0; } Think about further test cases
My Code is this:
@ 1. The address of the text to be searched is expected in R0. @ 2. The address of the text to be searched for is expected in R1. @ 3. R0 should point to an empty string, @ 4. or the searched text cannot be found, @ 5. the value 0 is returned in R0. @ 6. If R1 points to an empty string, the value 0 is returned in R0 .file "searchStringInString.S" .text .align 2 .global searchStringInString .type searchStringInString,% function
searchStringInString:
push {r5, r6}
mov r3, # 0
LDRB r4, [r0] @ String LDRB r5, [r1] @ search string
@ empty string CMP r4, # 0 BEQ end CMP r5, # 0 BEQ end
loop:
LDRB r4, [r0], # 1
LDRB r6, [r1]
CMP r4, # 0 BEQ end
CMP r4, r6 ESD innerloop
innerloop:
LDRB r4, [r5], # 1 LDRB r6, [r1, # 1]!
CMP r6, # 0 BEQ hit
CMP r4, r6 BEQ innerloop ESD loop
hit:
ADD r3, r3, # 1 B loop
end:
MOV r0, r3 Pop {r5, r6} MOV pc, lr
.size searchStringInString,.-searchStringInString
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started