Specific element in an Assembly array in AVR

Asked

Viewed 64 times

1

In the following paragraph:

    ldi     r16,255
    out     IO(DDRB),r16
    ldi     r30,1
    subi    r30,lo8(-(array))
    sbci    r31,hi8(-(array))
    ld      r24,Z
    out     IO(PORTB),r24

Why is there a -(array) within both lo8 and Hi8 ? And why are the instructions up and subci used here ? How can the address for the 2nd element be obtained from this ? I’m using the avr-gcc.

1 answer

1

The goal is to calculate array+1. In the first moment the value 1 is born in the r30. I imagine some code before the register r31 because there is nothing there to do it. In sequence you must add the address of the array (16 bits) in the pair of registers r30 and r31. The problem is that the Assembly AVR does not have an instruction to add immediate. So instead of doing 1+array, he did 1-(-array).

subi    r30,lo8(-(array))
sbci    r31,hi8(-(array))

The two subtraction instructions capture the first and second byte of the denied array address and operate with the registers that now contain the number 1. The second instruction is sbci to carry the first.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.