Accessing arrays in AVR assembly

Do you have a question? Post it now! No Registration Necessary

Translate This Thread From English to

Threaded View
           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[] )
array[1] = ...
array[2] = ...

Thank you

Re: Accessing arrays in AVR assembly

Quoted text here. Click to load it

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.


Re: Accessing arrays in AVR assembly

Quoted text here. Click to load it

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).


Tauno Voipio
tauno voipio @ iki fi

Site Timeline