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

Categories

0 votes
1.1k 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 Reply

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...