IT관련 지식들 2010. 3. 11. 23:48
ARM에서 cmp를 사용하여 같은 수를 비교하였을때 과연 Carry와 oVerflow는 어떻게 설정이 될까에서 시작된 의문으로 언제 Carry가 발생하고 언제 oVerflow가 발생하는지 찾아보았습니다. (Overflow라고 쓰지 않은 이유는 보통 overflow를 V flag로 설정하기 때문)

먼저 ARM architecture reference guide에서

C Is set in one of four ways:
• For an addition, including the comparison instruction CMN, C is set to 1 if the addition produced a carry (that is, an unsigned overflow), and to 0 otherwise.
• For a subtraction, including the comparison instruction CMP, C is set to 0 if the subtraction produced a borrow (that is, an unsigned underflow), and to 1 otherwise.
• For non-addition/subtractions that incorporate a shift operation, C is set to the last bit shifted out of the value by the shifter.
• For other non-addition/subtractions, C is normally left unchanged (but see the individual instruction descriptions for any special cases).

덧셈 (CMN 명령 포함), 뺄셈(CMP 명령 포함), shift 연산, 특별한 경우 Carry가 발생합니다.


V Is set in one of two ways:
• For an addition or subtraction, V is set to 1 if signed overflow occurred, regarding the operands and result as two's complement signed integers.
• For non-addition/subtractions, V is normally left unchanged (but see the individual instruction descriptions for any special cases).

2's complement 방식으로 signed integers끼리의 덧셈과 뺄셈 연산과 특별한 경우에 발생을 합니다.


그래서 AVR instruction Set에서도 찾아보았습니다.

 C : Carry flag in status register
 V : Two's complement overflow indicator

 조심스럽게 결론을 내려보면

우선 Carry는 덧셈, 뺄셈, 곱셈, 나눗셈들에서 32bit (혹은 8bit)연산 도중에 그것을 초과할 경우 Carry가 발생한 것을 저장하기 위한 공간입니다.

oVerflow는 2의 보수 표현의 정수 연산에서 부호비트가 변한 것을 보여주기 위한 결과입니다.

Zero, Negative 등의 경우는 직관적으로 알 수 있기에 생략했습니다.





'IT관련 지식들' 카테고리의 다른 글

ctags사용법 - 소스분석  (0) 2010.06.19
USB로 부팅하기  (0) 2010.06.14
ARM Architecture / ARM Core / ARM Processor  (1) 2010.03.11
Big endian / little endian  (0) 2010.03.11
Harvard architecture / Von-Neumann architecture  (0) 2010.03.11
posted by 동글동글82
: