0

looping a subtraction 10 times in assembly komodo. I would like to loop at least 4 times but I can ony manage to loop infinite times. How do I loop x number of times.

        B main

    bottles     DEFW    4
    text        DEFB    " bottles sitting on a wall",0

        ALIGN

    main    

        LDR R0,text
        SWI 3

        LDR R0,bottles

loop    SUB R0,R0,#1
        SWI 4
        B loop
        SWI 2
ProtectorOfUbi
  • 317
  • 5
  • 13
  • 1
    I don't see how this wasn't answered in my answer for [one of your previous questions](http://stackoverflow.com/questions/33396123/how-do-i-count-down-from-4-and-stop-at-0-in-assembler) where your code also contained an infinite loop. – Michael Oct 29 '15 at 16:35
  • @Michael: It starts to look like the OP is waiting for complete code. – turboscrew Oct 30 '15 at 12:53
  • Now this is getting odd: http://stackoverflow.com/questions/33404573/assistance-with-an-assembly-language-task – turboscrew Oct 30 '15 at 12:57

1 Answers1

0

Just for safety, move 'SUB R0,R0,#1' after the 'SWI 4', and instead of 'B loop' (unconditional branch) use 'BNE loop' (branch if not equal/zero). Oh, and change 'SUB' to 'SUBS' (= SUB + sets the fags).

turboscrew
  • 676
  • 4
  • 13