Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 8621

General • Re: Assign variables to specific addresses?

$
0
0
What is this sequence supposed to do ? ...
I am not sure whether you are asking what it does because you don't know, are asking whether I know what it does, or pondering why GCC has generated that.

I am no ARM Assembler expert but it seems to me to be implementing -

Code:

u32_one = 1;u32_two = 2;
Or GCC optimised whatever you gave it to be that equivalent.

That GCC has generated a word holding the address of a variable, loaded that word into a register so it points to the variable where data can then be read or written doesn't come as a great surprise to me. It's how I've done it in my compilers.

This is my test code -

Code:

#include <stdio.h>#include "pico/stdlib.h"extern volatile uint32_t u32_one; asm("u32_one = 0x20010000");extern volatile uint32_t u32_two; asm("u32_two = 0x20010004");#define PEEK_U32(adr) (*( (uint32_t *) adr ))int main(void) {  stdio_init_all();  while (!stdio_usb_connected()) {    sleep_ms(100);  }  while (true) {    u32_one += 1;    u32_two += 2;    printf("u32_one @ 0x%p = %lu %lu\n", &u32_one, u32_one, PEEK_U32(0x20010000));    printf("u32_two @ 0x%p = %lu %lu\n", &u32_two, u32_two, PEEK_U32(0x20010004));    sleep_ms(1000);    printf("\n");  }}
The generated Assembler all looks correct to me and it does what I would expect it to.

Statistics: Posted by hippy — Sat Mar 22, 2025 11:01 pm



Viewing all articles
Browse latest Browse all 8621

Trending Articles