Use C ++ variable in assembly (Arduino)

0

I've put an interesting code on 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 think it's because the assembly code is not getting access to the ptr variable. I'm a beginner in C \ C ++.

    
asked by anonymous 20.03.2018 / 20:41

1 answer

1

There's nothing wrong with your code.

It's always a good practice to include the header Arduino.h in your code:

#include <Arduino.h>
    
21.03.2018 / 14:36