Sign in to follow this  
Followers 0
ATAIDE

Set Carry e Clear Carry.

3 posts in this topic

Hello,
Could someone explain to me the purpose of the STC(40) and CLC(41) instructions. If possible leave an example.
Thanks.

Share this post


Link to post
Share on other sites

it is the same thing you do when adding numbers by hand using nothing but a pen and paper.

 

for example adding  597 and 895

     597
     895
(+) ------
    ????

 

so you start from the right side (least significant digit) and add those values 7+5 = 12. so you write down 2 (result is ___2)and remember to carry 1 (representing 10 actually) to the next position.

then you are adding 9+9 but also must include value that was carried over (1) so sum here is really 9+9+1 = 19, and you write down 9 (result is __92), and carry 1 again.

then you have 8+5 and since we still carry value from previous digit addition, it becomes 8+5+1=14. so you write down 4 (result now is _492) and you continue to to next position.

since there is no more digits in the operands, we just have the carry (1). we write this down and result is 1492.

if this was clear, you should have no problem adding numbers that have many more digits. 

same is with the computers - they can only handle limited chunks of data (based on instruction type and size of registers). so to break free from this limitation and be able to handle even very large values, carry value need to be considered. and programming manual has the nice example as well.

before calculation one would reset the carry flag. setting flag is possible too but this is used less frequently

 

 

Omron CLC.png

3 people like this

Share this post


Link to post
Share on other sites

Thanks for your answer. Very well explained.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0