Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
990 views
in Technique[技术] by (71.8m points)

assembly - Reason to use the carry bit and the overflow bit

I am taking an Introduction to Embedded Systems Class. As I was reading, I encountered an interesting question on the implementations of the carry bit and overflow bit.

I know what a carry bit and overflow bit is, however I cannot think of a situation in where someone would use a carry bit. One reason i thought was to align memory. Can someone shed light on this issue please?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The carry flag is useful for efficiently performing arithmetic and logical operations on data that is wider than the processor's accumulator or registers. This may not be a concern on a modern 64-bit processor, but early microprocessors and some current microcontrollers may still have only an 8-bit or 16-bit accumulator. The carry bit would permit add/subtract and shift/rotate of any multi-word length with the single accumulator. Besides the basic add, subtract, shift and rotate instructions (to begin the operation on multi-word data), there would be add-with-carry, subtract-with-borrow, shift-with-carry and rotate-with-carry instructions (to operate on subsequent words). And to facilitate such code sequences, the INC reg and DEC reg instructions (for pointer and loop counter modification) would not modify (and therefore preserve) the carry flag, even though they were arithmetic instructions.

Some microcontrollers (e.g. Intel 8051) also use the carry flag as a read destination or write source for its single-bit port I/O operations.

The carry and overflow flags (and perhaps some other flags, e.g. half-carry, sign or zero flags, depending on the processor architecture) are set or cleared on various arithmetic and logical operations. The processor's instruction set should be consulted for what flags exist and the conditions for which they are modified by instructions.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...