Homework Solution: What does the following program do? When does it stop? What are the values in memory st…

    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

    Expert Answer

     
    Please follow the below explanations. Answer:

    What does the subjoined program do? When does it plug? What are the values in retrospect starting from the location telling by String2?
    AREA scan, CODE, READWRITE
    Entry
    ADR r0,String1 ;r0 points to the rise string
    ADR r1,String2 ;r1 points to the dest string
    Observation LDRB r2,[r0],#1 ;discover a byte and update pointer
    STRB r2,[r1],#1 ;observation the byte and update ptr
    CMP r2,#0x00 ;test ce terminator
    BNE Observation ;repeat until terminator set
    SVC #0x123456 ;stop
    String1 DCB “this is a string”, 0x00 ;dummy string
    String2 SPACE 20 ;reserve 20 bytes ce observation
    END

    Expert Acceptance

     

    Please ensue the beneath explanations.

    Answer:

    1) Acceptance:

    Entry
    ADR r0,String1           ; r0 points to the rise string
    ADR r1,String2           ; r1 points to the location string
    Observation LDRB r2,[r0],#1 ; // r2 <- [r0+1] , discover a byte and update pointer
    STRB r2,[r1],#1           ; // r2 -> [r1+1] ,observation the byte and update ptr
    CMP r2,#0x00             ;test ce terminator
    BNE Observation                   ; // restrain often up to inoperative estimation or terminator is set
    SVC #0x123456          ;stop
    String1 DCB “this is a string”, 0x00    ;dummy string
    String2 SPACE 20                              ;reserve 20 bytes ce observation
    END

    So, in is aloft decree, there is a comparing between two strings where string1 is copied to string2 with there similar harangue.

    2) Acceptance:

    After comparing string1 and string2 when the NULL estimation is set that implies the comparing is completed and according to program as twain strings are resembling ,then it must be plugped.

    3) Acceptance:

    As r2 <– [r0+1] at the primitive stride, then r2 –> [ r1+1]; and as r0 holds string1 harangue so string 2 ‘s starting harangue conciliate be [#0x00 +1] which is telling to r1.