This is my simpe “Hello world” program in ASM:
.global _start
_start:
adr r1, hello
b test
loop: ldr r12, =0x16000000
str r0, [r12]
test: ldrb r0, [r1], #1
cmp r0,#0
bne loop
@b loop
hello: .asciz "Hello world.\n\r"
After commenting out b loop, I expect it to print out only one “Hello world.” but actually it does not stop, like the command b loop was still there. Why?
bne is a conditional branch, branch if not equal, basically branch if the zero flag is clear. If it doesnt branch it continues executing. Once you have found the null termination you wont branch to loop, instead you execute the bytes that make up “Hell” as an instruction. Try this:
give the arm something to execute after the bne, something other than data. it should walk through the data string one time then fall into the infinite loop.