Victor Rodriguez
Victor Rodriguez

Reputation: 571

Understanding SBI and CBI in Arduino Inline Assembly

I am attempting to write a small blink program in Arduino using inline assembly. The code under the first label (start:) works, and the LED turns on; however, the issue is with jumping to stop. In theory, this seems correct- I set the bit into register 5, bit 5 and then clear the bit, but this is not working.

void setup(){
    asm("sbi 0x05, 5");
}

void loop(){
    asm("start:");
    asm("sbi 0x05, 5");
    asm("jmp stop");

    asm("stop:");
    asm("cbi 0x05, 5");
    asm("jmp start");
}

I'm a newbie to inline assembly in Arduino, so any help would be appreciated

Upvotes: 0

Views: 5491

Answers (1)

Mir
Mir

Reputation: 30

According to GCC:

"asm statements may not perform jumps into other asm statements. GCC does not know about these jumps, and therefore cannot take account of them when deciding how to optimize. Jumps from asm to C labels are only supported in extended asm."

Considering the documentation, I think you will have better luck if you include all of the assembly in one asm call. This allowed me to acquire the desired functionality you describe in your question.

Upvotes: 1

Related Questions