# Translate from AVR pgm_read_byte to normal C array manipulation in STM8

I am trying to translate a couple of lines of code from AVR space data to STM8 normal C data manipulation.

As you should know, AVR has a program space which can storage data for read only operation, hence a special function should be used to read the data (pgm_read_byte()). In the case of STM8, it has a unique flash for program space and ram space, and storage data in program space is simple as using static constant keyword before the variable definition. The main problem for me is translate the AVR code to normal c code in STM8.

This is the line that I want to translate:

AMP[divider] = pgm_read_byte(envs[divider] + (((unsigned char*)&(EPCW[divider]+=EFTW[divider]))[1]))


And this is my translation:

EPCW[divider] += EFTW[divider];
AMP[divider] = EPCW[1+envs[divider]];


I am not sure if "EPCW[divider] += EFTW[divider];" is executed after or before of data reading in "pgm_read_byte()" function. And also I am not sure if the translated index are correct.

Since pgm_read_byte() as a macro resolves finally in __LPM() is looks like being a function call. Then all its arguments are calculated before the call.
The argument to pgm_read_byte() is a address, so I would try this:
AMP[divider] = *(envs[divider] + (((unsigned char*)&(EPCW[divider]+=EFTW[divider]))[1]));

#define pgm_read_byte(address) ((uint8_t)(*(address)))
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 0, "mathjax_display_tex": 0, "mathjax_asciimath": 1, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0, "math_score": 0.2020457237958908, "perplexity": 3453.167753778517}, "config": {"markdown_headings": true, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.18, "absolute_threshold": 10, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "plain"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "warc_path": "s3://commoncrawl/crawl-data/CC-MAIN-2020-34/segments/1596439738913.60/warc/CC-MAIN-20200812171125-20200812201125-00277.warc.gz"}