Accessing arrays in AVR assembly

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

Reply to
Loading thread data ...

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.


Reply to
Thad Smith

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

Reply to
Tauno Voipio

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.