110 likes | 225 Views
מבנה המחשב + מבוא למחשבים ספרתיים תרגול 9#. Signed Addition. Example: The sign of the sum z is not signaled correctly by S[ n-1 ]. Set:. Proof: NEG = XOR(OVF,S[ n-1 ]). (1). (2). By substituting (2) in (1) ,. Correctness of S-ADDER( 2n ).
E N D
מבנה המחשב + מבוא למחשבים ספרתייםתרגול 9# Signed Addition
Example: The sign of the sum z is not signaled correctly by S[n-1]. Set:
Proof: NEG = XOR(OVF,S[n-1]) (1) (2) By substituting (2) in (1),
Correctness of S-ADDER(2n) We assume the correctness of S-ADDER(n) implementation in Figure 8.2 in chapter 8 of the lecture notes:
Negation circuit The circuit is correct when no overflow occurs: “C[n]” “A[n-1]” “B[n-1]” “S[n-1]”
A wrong implementation of ADD-SUB(n) The circuit errs ⇔ the “negation” of B errs
OVF and NEG flags in high level programming unsigned int lastBit( unsigned int num) { return num >> (8*sizeof(int) – 1); } unsigned int negBit( unsignedint bit) { return 1-bit; } void main() { //... suppose S = A ±B; int ovf = ( lastBit(A) & lastBit(B) & negBit(lastBit(S)) ) | ( negBit(lastBit(A)) & negBit(lastBit(B)) & lastBit(S) ); int neg = ovf ^ lastBit(S); }
Note: Short segments of low level language (Assembly) can be integrated in C programs using inline assembly. __asm { //assembly code// } Overflow and Negative result are indicated by flags: OF – Overflow flag which is set if an overflow occurs. SF – Sign flag which is a copy of the high-order bit of a result. Testing for overflow: jo target - jumps to “target” if OF = 1 jno target - jumps to “target” if OF = 0 Testing for sign: js target - jumps to “target” if SF = 1 jns target - jumps to “target” if SF = 0
Bi-directional cyclic shifting A reduction of right cyclic shifting to left cyclic shifting.
XOR(k) Bi-directional cyclic shifting – Cont’