Skip to content

Instantly share code, notes, and snippets.

@mtei
Last active March 15, 2022 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mtei/4fd7beaa09116b2721145b01d901c7aa to your computer and use it in GitHub Desktop.
Save mtei/4fd7beaa09116b2721145b01d901c7aa to your computer and use it in GitHub Desktop.
avr-gcc PROGMEM tips

avr-gcc PROGMEM tips

//avr-gcc -mmcu=atmega32u4 -S -O2 -o - progtest1.c
#include <avr/pgmspace.h>
const char a = 100;
% avr-gcc -mmcu=atmega32u4 -O2 -S -o - vartest1.c
	.file	"vartest1.c"
__SP_H__ = 0x3e
__SP_L__ = 0x3d
__SREG__ = 0x3f
__tmp_reg__ = 0
__zero_reg__ = 1
	.text
.global	a
	.section	.rodata
	.type	a, @object
	.size	a, 1
a:
	.byte	100
	.ident	"GCC: (Homebrew AVR GCC 8.4.0_2) 8.4.0"
.global __do_copy_data
//avr-gcc -mmcu=atmega32u4 -S -O2 -o - progtest2.c
#include <avr/pgmspace.h>
const char b PROGMEM = 101;
% avr-gcc -mmcu=atmega32u4 -O2 -S -o - vartest2.c
	.file	"vartest2.c"
__SP_H__ = 0x3e
__SP_L__ = 0x3d
__SREG__ = 0x3f
__tmp_reg__ = 0
__zero_reg__ = 1
	.text
.global	b
	.section	.progmem.data,"a",@progbits
	.type	b, @object
	.size	b, 1
b:
	.byte	101
	.ident	"GCC: (Homebrew AVR GCC 8.4.0_2) 8.4.0"
<avr/pgmspace.h>
#define __ATTR_PROGMEM__ __attribute__((__progmem__))
#define PROGMEM __ATTR_PROGMEM__
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment