Arduino assembler logical not or bit wise not

Hi to all,

I'm learning Arduino by programming in assembler, it is something new for me. I wrote my successfully first program to blink a led.

Now I'm looking at instruction set manual and I was wondering whether there is a logical instruction to negate a register or a single bit. I would like to rewrote the branchless blinking version.

Now I'm using the sbi and cbi, I'm searching for something similar but to negate a bit.

Thank you.

This might work:

Load r0 with 0xFFFF
Load r1 with the byte you want to "negate"
XOR r1,r0 Exclusive OR

You can XOR the bit or bits to be flipped with a mask value whose bits to be flipped are set to 1 ?

The equivalent of

  byte b;
  b = 0b11111111;
  b ^= 0b00000001;
  Serial.println(b, BIN);
  b ^= 0b01010101;
  Serial.println(b, BIN);
  b ^= 0b01010101;
  Serial.println(b, BIN);

Note: The "Exclusive OR" instruction is named "EOR", not "XOR". It works on two registers: Destination,Source
Further note: The "CLR" instruction is just the EOR instruction with both registers the same.

There is a "Load and Toggle" (LAT) instruction. It fetches a byte through the pointer register 'Z', XOR's it with the named register, and stores it back through Z.

ard_newbie:
This might work:

Load r0 with 0xFFFF

In an eight bit register? :wink:

tanoz:
Hi to all,

I'm learning Arduino by programming in assembler, it is something new for me. I wrote my successfully first program to blink a led.

From a technical / pedantic perspective this does not make sense.
"Arduino" can refer to many things, from h/w to s/w.
Arduino does not really refer to any specific board although many often refer to AVR based boards like the UNO as simply "Arduino".

But from a s/w perspective, Arduino is about creating an easy to use environment that provides a core library (in C) that hides all the raw h/w from the user using abstraction APIs and then provides C++ libraries on top of that for additional functionality.
If you are directly accessing the h/w - which you would be when using assembler, you are stepping outside the Arduino programming environment.

When programming in assembler, using the assembler from gcc toolset is a bit messy since the gcc tools (which is what comes with the Arduino IDE) don't use the official/Atmel assembler mnemonics/language.

There are other tools like Atmel Studio (if using Windows) that, IMO, would better if wanting to program directly to the h/w in assembler.

--- bill

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.