.db/.byte question

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

Hello,

 

I'm wondering if anyone has any insight into using .db and/or .byte for strings. In short, I feel like I've tried every permutation and combination of these, read over some docs, and I just can't get them to work quite as I'm expecting. Has anyone got any experience with this? Please see the screenshot that's attached. I even tried .dc8, which I stumbled across after making the screenshot; it seems to behave the same way .byte does. Removing the dot ahead of the directive causes the assembler to not recognize it which (naturally) produces an error.

 

I've read over this: http://ftp.iar.se/WWWfiles/avr/w...

...and this: http://www.atmel.com/webdoc/avra...

...and I just haven't been able to sort this out. I need to embed a string in the FLASH that the application refers to. It's absolutely possible I've overlooked another document somewhere or am misinterpreting something.

 

I'll admit, I'm relatively new to AVRs (only been at this for not quite three months now) but am a seasoned vet with assembly language on a number of other architectures. I just can't seem to work out this issue with the assembler here. :)

 

Thanks!

Attachment(s): 

This topic has a solution.

-kbx

Last Edited: Sat. Nov 19, 2016 - 07:33 PM
This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

As you have posted in a UC3 forum can we assume the assembler you are talking about is avr32-as?

 

While I don't have that installed I do have avr-as (8 bit) and if I ever want to see how to do something in that I see what the C compiler thinks:

$ cat avr.c
#include <avr/io.h>

uint8_t bytes[] = { 13, 29, 52, 176, 14 };
char text[] = "Hello world";

int main(void)
{
}

$ avr-gcc -Os -mmcu=atmega16 -save-temps avr.c -o avr.elf
$ cat avr.s
	.file	"avr.c"
__SREG__ = 0x3f
__SP_H__ = 0x3e
__SP_L__ = 0x3d
__CCP__ = 0x34
__tmp_reg__ = 0
__zero_reg__ = 1
	.text
.global	main
	.type	main, @function
main:
/* prologue: function */
/* frame size = 0 */
/* stack size = 0 */
.L__stack_usage = 0
/* epilogue start */
	ret
	.size	main, .-main
.global	bytes
	.data
	.type	bytes, @object
	.size	bytes, 5
bytes:
	.byte	13
	.byte	29
	.byte	52
	.byte	-80
	.byte	14
.global	text
	.type	text, @object
	.size	text, 12
text:
	.string	"Hello world"
.global __do_copy_data

As you can see it chooses to use .byte for the numeric data but actually .string for the text. Of course that implies a 0 terminator. Perhaps you don't want that in which case:

$ cat avr.c
#include <avr/io.h>

char text[11] = "Hello world";

int main(void)
{
}
$ cat avr.s
	.file	"avr.c"
__SREG__ = 0x3f
__SP_H__ = 0x3e
__SP_L__ = 0x3d
__CCP__ = 0x34
__tmp_reg__ = 0
__zero_reg__ = 1
	.text
.global	main
	.type	main, @function
main:
/* prologue: function */
/* frame size = 0 */
/* stack size = 0 */
.L__stack_usage = 0
/* epilogue start */
	ret
	.size	main, .-main
.global	text
	.data
	.type	text, @object
	.size	text, 11
text:
	.ascii	"Hello world"
.global __do_copy_data

And on the basis of "learn something new every day" I just did - never heard of .ascii before now!!

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

That's awesome -- and great info. I'll give that a shot and see if it works. If not, I'll try something similar in Atmel Studio.

 

Also, regarding your assumption...I've installed Atmel Studio 7 and am using that as my IDE. So whichever assembler that relies on out of the box...nothing special. :)

 

Thanks for the help & suggestion! I'll post back once I get a chance to try it out...

 

-kbx

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

So I tested this out tonight...

 

.ascii did exactly what I needed.

 

Thanks again! :D

-kbx

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

BTW this is a general technique - the C compiler is a far better author of GNU as code than you or I will ever be. So if you want to know how to achieve something in the assembler just sketch out your requirement in C/C++ then compile that with -save-temps then study the .s file.