# 16 Bit operations and Time of execution

## Recommended Posts

I am writing some very time-critical code (all loops must execute in the same amount of the all the time) and am using 16bit variables.  I am noticing diferentials in the loops and think this is due to the 16bit math and logic.  Does anyone know if the 16bit math takes different amounts of time depending on carry or not etc?  Also, does the 16bit logic take different amounts of time?  I dread writing my own 16bit math and logic but will do so if I must.

Thanks,

George

##### Share on other sites

I realize after reading this a day later that it does not make much sence....  Let me rephrase with an example.

If I add two variables together, lets say one 8 bit variable added to a 16bit variable, does the add opperation always take the same amount of instructions (time)?  Example:

char num8bit;

short num16bit;

num16bit = 10;

num8bit = 10;

num16bit += num8bit;  // This takes "X" amount of time

num16bit = 250;

num8bit = 10;

num16bit += num8bit; // This takes "Y" amount of time

Does X = Y?  In example 2, a carry took place.

Also, does the logic vary depending on time?

Example:

num16bit = 100;

if (num16bit > 100) // This takes X amount of time

{

}

num16bit = 1000;

if (num16bit > 1000) // this takex Y amount of time

{

}

Again... does X always = Y?

Thanks Pavel.

Let me know

##### Share on other sites
If I add two variables together, lets say one 8 bit variable added to a 16bit variable, does the add opperation always take the same amount of instructions (time)?

The answer is no. The number of instructions executed in the same expression but with different values may be different. This happens more often in conditional expressions because sometimes there is no need to execute all instructions in an expression when the result is already known. A simplified example can be a comparison of 8 and 16 bit variables. If hight byte of the 16 bit variable isn't zero there is no need to compare low bytes as it's already known that 16bit variable contains bigger value.

Regards,

Pavel

## Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.