This is the example code:

LDR r0, =n
LDR r0, [r0]
LDR r1, =array1
MOV r2, #0
LDR r4, =array2
LDR r3, [r1], #4
CMP r3, #58
BGT a_point
CMP r3, #47
BLT a_point
SUB r3, r3, #0x30
STR r3, [r4], #4

    subs r0, r0, #1
    BGT loop

    b stop

n: .word 6
array1: .word 0x30, 0xFFFFFFF5, 0x37, 0x4b, 0x18, 0x40
array2: .word 0x01, 0x0, 0x0, 0x0, 0x0, 0x0

I'm having trouble understanding how the loop works, what it does and specifically how the branch instruction work on pair with the -lt and -gt suffixes. What is the purpose of this simple program? Thanks in advance for your help.

  • could you re-check this code? It's kind of strange that r0 is decremented as a counter and not used within the loop. – Paweł Łukasik Jan 18 at 20:56
  • r0 = counter used to check n members unconditionally of array a = array1[1] if (a >58 || a < 47) goto dec n else a = a-30 array1[1] = a & dec n; – blabb Jan 18 at 22:23
  • 1
    @PawełŁukasik LDR increments the array pointer so there is no need to use the counter for indexing – Igor Skochinsky Jan 19 at 14:31
  • I got the code from my course. I double checked and it's correct, even if it's quite weird. I was hoping that someone that knows a bit more than me on assembly for arm could describe to me what's the purpose of the program. – m4mmt Jan 19 at 16:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.