Search code examples
czero8051unsigned-integer

Fastest way to zero


What is the fastest way to zero out an unsigned int?

I am currently just setting the value to 0, but I don't know if there are any tricks for zeroing out a variable? I need a few clock cycles back in my current project. I am using a standard 8051 processor and I have two different variables I need to get to zero if that helps at all.


Solution

  • The question is labelled 8051, so if the need is to zero out a register XORing the register with itself will be a faster way to zero it out, instead of moving a zero in it. One opcode fetch and decode vs opcode fetch decode and operand fetch.

    If you are using higher level language and not hand assembling or writing in asm, then it is better to use var = 0. The compiler will take care of the required optimizations.