What does the following program do? When does it stop? What are the values in me
ID: 3882599 • Letter: W
Question
What does the following program do? When does it stop? What are the values in memory starting from the location pointed by String2?
AREA scan, CODE, READWRITE
Entry
ADR r0,String1 ;r0 points to the source string
ADR r1,String2 ;r1 points to the dest string
Copy LDRB r2,[r0],#1 ;read a byte and update pointer
STRB r2,[r1],#1 ;copy the byte and update ptr
CMP r2,#0x00 ;test for terminator
BNE Copy ;repeat until terminator found
SVC #0x123456 ;stop
String1 DCB "this is a string", 0x00 ;dummy string
String2 SPACE 20 ;reserve 20 bytes for copy
END
Explanation / Answer
Please follow the below explanations.
Answer:
1) Answer:
Entry
ADR r0,String1 ; r0 points to the source string
ADR r1,String2 ; r1 points to the destination string
Copy LDRB r2,[r0],#1 ; // r2 <- [r0+1] , read a byte and update pointer
STRB r2,[r1],#1 ; // r2 -> [r1+1] ,copy the byte and update ptr
CMP r2,#0x00 ;test for terminator
BNE Copy ; // check repeatedly up to null character or terminator is found
SVC #0x123456 ;stop
String1 DCB "this is a string", 0x00 ;dummy string
String2 SPACE 20 ;reserve 20 bytes for copy
END
So, in is above code, there is a comparing between two strings where string1 is copied to string2 with there corresponding address.
2) Answer:
After comparing string1 and string2 when the NULL character is found that implies the comparing is completed and according to program as both strings are equal ,then it must be stopped.
3) Answer:
As r2 <-- [r0+1] at the first step, then r2 --> [ r1+1]; and as r0 holds string1 address so string 2 ‘s starting address will be [#0x00 +1] which is pointed to r1.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.