STRB instruction seems not working in ARM assembly

0

I'm trying to write string compare function in ARM assembly.
After comparing two strings A and B, one of them should be stored in memory.
If they are not equal, string B will be saved in the memory. In below code, storing operation is executed in the label named StoreA and StoreB(below code is not a complete code)

I expected below code to store a character H in 0x00040000 however STRB instruction seems not working.
Please give me a advice.

AREA Assignment1_2, CODE, READONLY
        ENTRY
Main
    LDR r0,=String1
    LDR r1,=String2

Compare             ; main loop
    LDRB r2, [r0, r5]
    LDRB r3, [r1, r5]

    CMP r2, #0
    BEQ IsEnd1

    CMP r3, #0
    BEQ IsEnd2

    ADD r5, r5, #1
    B Compare


; check if the string ends
IsEnd1
    CMP r3, #0
    BEQ StoreA      ; equal
    B       StoreB      ; not equal

IsEnd2
    CMP r2, #0
    BEQ StoreA      ; equal
    B       StoreB      ; not equal


; store string
StoreA                  ;equal
    SUB r0, r0, r5
    B Endline

StoreB                  ;not equal
    LDRB r3, [r1]
    STRB r3, TEMPADDR
    B Endline

Endline
    MOV pc, lr

TEMPADDR & &00040000
String1 DCB "Hi", 0
String2 DCB "Hik", 0

    END
assembly
arm
asked on Stack Overflow Oct 5, 2015 by soonoo

1 Answer

0

Your main loop Compare only checks for string terminators, and does not compare their content. I have only a very little experience in writing code for this processor, so I would only guess what instructions are needed to check the characters within each string.

Also, the two code blocks that are branched to when encountering the 0 end-of-string marker only compare if the strings are the same length.

And "one of them will be stored in memory" is a false belief. Both strings are already stored in memory.

answered on Stack Overflow Oct 5, 2015 by Weather Vane

User contributions licensed under CC BY-SA 3.0