This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

subtraction with borrow

Hi all

How to write a pragram to subtraction immediate data from accumulator with borrow in C51?

Parents
  • "So anyone can for explain a simple program."

    The subject of your question is a perfect example.
    The 8051 is an 8-bit processor, so all its instructions deal with only 8 bits at a time. Therefore, if you want to handle data larger than 8 bits in Assembler, you have to "manually" code it 8 bits at a time.

    The Subtract-with-Borrow (and, similarly, Add-with-Carry) instruction allows you to do subtraction on data larger than 8 bits by handling 8 bits at a time, and including a "borrow" from the previous 8-bit operation.

    In 'C', you don't mess about with all this detail - you just use the 16-bit data type (int) or 32-bit data type (long) built into the language!

    long a, b, c;
    
    a = b - c; // 32-bit subtraction in 'C' is just a simple use of the '-' operator!
    The whole point of high-level languages is that they allow you to concentrate on what you want to do, rather than how to achieve it with the available processor instructions!

Reply
  • "So anyone can for explain a simple program."

    The subject of your question is a perfect example.
    The 8051 is an 8-bit processor, so all its instructions deal with only 8 bits at a time. Therefore, if you want to handle data larger than 8 bits in Assembler, you have to "manually" code it 8 bits at a time.

    The Subtract-with-Borrow (and, similarly, Add-with-Carry) instruction allows you to do subtraction on data larger than 8 bits by handling 8 bits at a time, and including a "borrow" from the previous 8-bit operation.

    In 'C', you don't mess about with all this detail - you just use the 16-bit data type (int) or 32-bit data type (long) built into the language!

    long a, b, c;
    
    a = b - c; // 32-bit subtraction in 'C' is just a simple use of the '-' operator!
    The whole point of high-level languages is that they allow you to concentrate on what you want to do, rather than how to achieve it with the available processor instructions!

Children
No data