Use C++ variable in Assembly (Arduino)

Asked

Viewed 66 times

0

I have an interesting code in this page.

const uint8_t MachineCode[44] PROGMEM = {
0x25, 0x9A, 0x2D, 0x9A, 0x40, 0xE5, 0x5F, 0xEF,
0x6F, 0xEF, 0x6A, 0x95, 0xF1, 0xF7, 0x5A, 0x95,
0xE1, 0xF7, 0x4A, 0x95, 0xD1, 0xF7, 0x2D, 0x98,
0x40, 0xE5, 0x5F, 0xEF, 0x6F, 0xEF, 0x6A, 0x95,
0xF1, 0xF7, 0x5A, 0x95, 0xE1, 0xF7, 0x4A, 0x95,
0xD1, 0xF7, 0xEB, 0xCF
};

const uint8_t *ptr = MachineCode;

void setup() {
  //get address of code and call it
  //Creio que o ERRO esteja aqui:
  asm(
    "lds r30, ptr   \n\t"
    "lds r31, ptr+1 \n\t"
    "lsr r30        \n\t"
    "icall          \n\t"
  );
}

void loop() {
  //never reach here
}


I ran the code on my Arduino, but I got this error:

C:\Users\xxx\Documents\Arduino\xxx/xxx.ino:19: undefined reference to 'ptr'

I believe it is because the Assembly code is not able to access the variable ptr. I’m a beginner in C C++.

  • Remember that working with microcontrollers may require Ibraries, or in the case of PIC for example, a compiler, such as C18

1 answer

1


There’s nothing wrong with your code.

It is always good practice to include header Arduino.h in your code:

#include <Arduino.h>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.