"Hello World" at ARM Assembly

This is my ASM Hello World symp:

.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 on b loop , I expect it to print only one "Hello world". but actually it does not stop, like the b loop command. Why?

+4
source share
1 answer

bne - conditional branch if the branch is not equal, basically the branch if the zero flag is clear. If it does not branch, it continues to run. Once you find the null termination, you do not go into a loop; instead, you execute the bytes that make up β€œHell” as an instruction. Try the following:

 .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 forever: b forever hello: .asciz "Hello world.\n\r" 

give the hand something to do after bne, something else besides the data. it should go through the data line once, and then fall into an infinite loop.

+4
source

Source: https://habr.com/ru/post/1414474/


All Articles