assembly lookup table

Go To Last Post
15 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'm trying to implement a sine lookup table in an AVRStudio 4 environment. I've looked around but just can't seem to find instructions or a good example in assembly.

I suppose I could switch to c, but I know assembly much better at this point.

I've tried just putting a .org statement and then a bunch of hex values after that in an attempt at placing said hex values in program memory, but it obviously didn't work.

Any help?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

.db 0x01, 0x02 etc.

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

.org won't work as the value after will point to a program memory space that could be an ISR.

John hit the nail on the head. Use .db instead

Jim

If you want a career with a known path - become an undertaker. Dead people don't sue! - Kartman

Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

can anyone tell me what the .db does? I imagine it stands for database, but where does it place the table values?

I wanted to start with a .org to place the table starting at 0x0100, which is well out of range of the interrupt vectors which only go to like 0x009c or something (per the ATMEGA128.inc file)

If i don't use the .org, does anyone know how to index the location of the start of the table to store in the z pointer?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

db=define byte
dw=define word

These, along with all the other directives) are explained in the manual (built into Studio help system)

You also want to get a copy of the opcode manual as the decription of LPM actually shows .db and the Z register being used.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
.ORG 0x0020 ;start table from 0020
.dw 7,8,9,10,11,12........

Remember to set up all your tables before writing down the rest of the code. AVR Studio can be stupid that way. If your table is in the middle of the rest of the code, there is a risk of your table being overwritten.

If you think education is expensive, try ignorance.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks for the help, folks. I'll let you know how it all turns out.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
but I know assembly much better at this point.......can anyone tell me what the .db does?
Now that's a bit contraddictory :roll:

.db are fundamental things in assember just like .org

Have you used another brand of assembler before or is the AVR assembler your fisrt one?
For Motorola/Freescale you have ds, rmb, db, fcb, dw, fdb.

There may be different ways of using the same directives but are always available.

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If you assign a name to the .db you won't need an .org because the assembler will put the correct address in place

ldi   zh,high(message*2)
ldi   zl,low(message*2)
lpm



message:     .db    0xXX,0xXX,0xXX

Jim

If you want a career with a known path - become an undertaker. Dead people don't sue! - Kartman

Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
If you assign a name to the .db you won't need an .org because the assembler will put the correct address in place

.org is very useful in forcing a lookup table to begin at a 256 byte boundary. This simplifies addressing repeating waveform
tables that are of 64, 128, 256, etc bytes in length. For the LPM instruction in the case of a 256 byte waveform table,
simply incrementing only the ZL register will cause the Z register pair address to wrap around to the beginning of the table
upon reaching the end. This greatly simplifies lookup table incremental addressing as no evaluation is required.

An excellent example can be seen in the ASM code at Jesper's Mini DDS project.
http://www.myplace.nu/avr/minidd...

Stan

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Stan,
From what I see in Jespers code is that he located the lookup tables at memory location 0x100 by using the .org. His code follows the lookup tables.

Still, it is a slick project

Jim

If you want a career with a known path - become an undertaker. Dead people don't sue! - Kartman

Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

things seem to be working well. Thanks for the help.

I hadn't had to use the .org directive before as this is the first table i've implemented. The message was a good idea as well, a bit cleaner.

I had to figure out that the .org directive placed it twice as many bytes out in memory than a pointer value of the same size.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

halcyon_m wrote:
I had to figure out that the .org directive placed it twice as many bytes out in memory than a pointer value of the same size.
If you had taken the short time to read the assembler documentation on org, you would have saved time from having to discover than on your own.
Quote:
Note that the SRAM and EEPROM location counters count bytes whereas the Program memory location counter counts words.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Gents and Ladys all, allow me please to pick your brain a bit please. I am completely new to assembler and I was given this project that requires to get a table of 8 hex values and this counter to count the pulses of a clock, I suppose to use the counter to offset the base address of the table to reach the corresponding value stored there to compare it with the data I read from the port. Sorry but I cannot get how to define the table much less how to address it correctly. I have been struggling with this for day and I've ot up to:
.dw $1,$2,$4,$8,$10,$20,$40,$80
Upto here it build ok on avrstudio 4.19 but I do not get how to reach the address of that table much less how to offset it with the value of the counter.
I would deeply appreciate a clear help even including any defining parameters or values.
Thanks a million

SPAG

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Put a label on the front like

label:
      .dw $1, $2, $4, $8, $10, $20, $40, $80

then you load the address of that into Z:

     ldi Zh, high(label * 2)
     ldi Zl, low(label * 2)

And now you can use LPM to read the data.