Accessing arrays in AVR assembly

Aug 22, 2003 2 Replies

Hello, Could anybody please send me an example of an assembly routine that shows how to access an array in AVTR assembly. I am using codevision compiler. I have a function in C that calls another function Getbyte(array[]) passing an array. In this function Getbyte(), I want to implement an assembly routine that can access this array elements byte by byte. Something like this: Call Getbyte( array ) . . . Getbyte( array[] ) { #asm array[1] = ... array[2] = ... #asm }



Thank you Gopal


My first suggestion is that if you are using C, write the GetByte routine in C. Why do you want to use assembly? If you still want to use assembly, study the processor manual to learn the architecture and instruction set. Write a version in C anyway, and look at the generated assembly (or read documentation) to see how parameters are passed, etc.

Thad

The trick is to use the X (r26,r27), Y (r28,r29) or Z (r30,r31) register as the array pointer.

Check the ld and ldd instructions in the instruction set reference.

You can step the pointer with the adiw instruction (if the AVR you're using supports it), otherwise just increment the registers and propagate carry (add, adc).

HTH

Tauno Voipio tauno voipio @ iki fi

Join the Discussion

Have something to add? Share your thoughts — no account required.

Didn't find your answer?

Ask the community — no account required