Question

I'm very new to assembly language and what I need to do is find the value at a given position in a lookup table. So for example, given the table:

table: .db 1,2,3,4,5,6,7,8,9,10

How would I get the 3rd element of this table and load it into a register, say r16?

Thanks guys!

Was it helpful?

Solution

Load the base address of the table into register X, add the appropriate offset, then use LD to fetch the entry from data memory. If your table is in program memory, use register Z and the LPM instruction.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top