Presentation is loading. Please wait.

Presentation is loading. Please wait.

Microprocessor Technique Binary codes. Lecture 2 1/47 Binary codes in microprocessor technique Integer arithmetic Fix-point arithmetic Floating-point.

Similar presentations


Presentation on theme: "Microprocessor Technique Binary codes. Lecture 2 1/47 Binary codes in microprocessor technique Integer arithmetic Fix-point arithmetic Floating-point."— Presentation transcript:

1 Microprocessor Technique Binary codes

2 Lecture 2 1/47 Binary codes in microprocessor technique Integer arithmetic Fix-point arithmetic Floating-point arithmetic

3 Binary codes - NB 2/47 NB

4 Binary codes - NB 3/47 value ranges:

5 Binary codes - SM 4/47 SM - sign-magnitude

6 Binary codes - SM 5/47 value ranges:

7 Binary codes - C2 6/47 C2 - two’s complement

8 Binary codes - C2 7/47 value ranges:

9 Binary codes - C2 8/47

10 Binary codes - C1 9/47 C1 - one’s complement

11 Binary codes - BCD 10/47 BCD - binary coded decimal

12 Binary codes - Gray code 11/47 Gray code 0 0 0 0 0 1 0 1 1 0 1 0 1 1 0 1 1 1 1 0 1 1 0 0 generation of Gray code words:

13 Binary codes - ASCII 12/47 ASCII 128 codes (0..127) representing: 33 control codes i 95 alphanumeric chars Applications: communication (text), service of: mosaic display, printers, autonomous keyboards, etc. Extended ASCII - additional 128 codes (128..255) representing different chars and semigraphic

14 Arithmetic - NB 13/47 Addition and subtraction in NB Carry flag (CY) signals: overflow in addition borrow in subtraction

15 Arithmetic - C2 14/47 Addition and subtraction in C2 Let: S 1, S 2, S - signs of the operands (MSB of two arguments and result) Overflow occurs: in addition in C2 when S 1 =S 2  S in subtraction in C2 when S 1  S 2 i CY=S

16 Arithmetic - BCD 15/47 Addition and subtraction in BCD Carry flag (CY) after correction signals: overflow in addition BCD of numbers borrow in subtraction of BCD numbers

17 Arithmetic - long (multi-byte) numbers 16/47

18 Arithmetic - long (multi-byte) numbers 17/47 R:R: X X X N1: 80 02 N2: 88 C2 00 35 i= X CY= x i= 0 CY= 0 88h + 35h + 0 = 0BDh BD CY= 0 i= 1 80h + C2h + 0 = 142h CY= 1 42 i= 2 02h + 00h + 1 = 03h 03 CY= 0 i= 3 ( >= m=3)

19 Arithmetic - long (multi-byte) numbers 18/47

20 Arithmetic - multiplication without sign 19/47 ATTENTION: bit-length of product is equal the sum of bit-lengths of factors 1. Multiplication by repeated addition Let: N1,N2 - 1-byte factor, R - 2-byte product computational complexity: N2=0 & N1=x: CC MIN =2+1=3 N2=255 & N1=x: CC MAX =2+(1+2+1)*255=1023 so: CC AVR =513

21 Arithmetic - multiplication without sign 20/47 2. Multiplication 1215 10101 (21) x 204 x 110 (6) 4860 101010 2430 10101 247860 1111110 (126) Let: N1,N2 - 1-byte factor, R - 2-byte product computational complexity: N2=0 & N1=x: CC MIN =2+1+(1+2+1+1)*8=43 N2=11111111b & L1=x: CC MAX =2+1+(1+2+2+1+1)*8=59 so: CC AVR =51 previous method is faster only in 4% of cases

22 Arithmetic - multiplication without sign 21/47 3. Examples in Z80 machine language

23 Arithmetic - multiplication without sign 22/47

24 Arithmetic - multiplication without sign 23/47

25 Arithmetic - multiplication without sign 24/47 4. Multiplication of long (multi-byte) numbers manipulating of longer bit strings; using subroutine to partially multiplication (byte x byte): multiplication of nibbles (only for BCD numbers);

26 Arithmetic - multiplication without sign 25/47 faster (trick) multiplication: assume: x = B  x 1 + x 0 y = B  y 1 + y 0 (B=256) w = x  y = (B  x 1 + x 0 )  (B  y 1 + y 0 ) - 4 multiplications & 4 additions let: u = x 1 - x 0 i v = y 1 - y 0 then: u  v = x 1  y 0 + x 0  y 1 - x 1  y 1 - x 0  y 0  x 1  y 0 + x 0  y 1 = u  v + x 1  y 1 + x 0  y 0 w = B  B  x 1  y 1 + B  (x 1  y 0 + x 0  y 1 ) + x 0  y 0 = = B  B  x 1  y 1 + B  u  v + B  x 1  y 1 + B  x 0  y 0 + x 0  y 0 = = (B  B + B)  x 1  y 1 + B  u  v + (B + 1)  x 0  y 0

27 5. Multiplication by constant assume: constant value K is known at coding phase. K =Σ k i  2 i If only few (1..4) k i = 1, then it’s possible to use formula: L  K = L  2 i1 + L  2 i2 + L  2 i3 + L  2 i4 where i1, i2, i3, i4 are exponents of 2 for k iX = 1. Especially if K=2 m, then multiplication is equivalent m-times arithmetic shifting left of number L. Arithmetic - multiplication without sign 26/47

28 Arithmetic - multiplication without sign 27/47

29 Arithmetic - division without sign 28/47 1. Division by repeated subtraction Let: N1, N2 - 1-byte dividend & divisor, R - 1-byte quotient

30 Arithmetic - division without sign 29/47 2. Division by power of 2 equivalent to arithmetic shift right

31 Arithmetic - division without sign 30/47 3. Division zał: N1,N2 - 1-byte dividend & divisor, NN - 2-byte working variable (register) R - 1-byte quotient, R=NN L

32 Arithmetic - division without sign 31/47 Example: consecutive states of NN during division N1=31 by N2=7 0 0 0 0 0 0 0 00 0 0 1 1 1 1 1 NN: 0 0 0 0 0 0 0 00 0 0 1 1 1 1 1 0 0 0 0 0 0 0 0 00 0 0 1 1 1 1 1 0 0 0 0 0 0 0 0 0 00 0 0 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 00 0 0 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 00 0 0 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 1 1 1 N2: 0 0 0 0 0 1 1 1 -N2-N2 0 0 0 0 0 0 0 00 0 0 0 0 0 1 1 0 0 0 0 0 1 0 0 0 0 0 0 0 00 0 0 0 0 0 1 1 0 0 0 0 0 1 0 0 0 0 0 0 0 1 1 0 0 0 0 0 1 0 0 reminderR=quotient

33 Arithmetic - division without sign 32/47 4. Division examples in Z80 machine language 4.1. Division by repeated subtraction

34 Arithmetic - division without sign 33/47 4.2. Division

35 Arithmetic - with sign 34/47 Previous algorithms need separate determination of result sign

36 Arithmetic - with sign 35/47

37 Arithmetic - fix-point notation 36/47 1. Fix-point notation value range: 0.. 2 m -2 -n Example: let m=8 i n=4: 10,25  00001010.010010,20  00001010.0011 = 10,1875 number of bits of integer and fractional parts depends on:  needed precision;  needed value range. Positive and negative numbers are represented in C2 code.

38 Arithmetic - fix-point notation 37/47 Example of fix-point notations: 2. Addition and subtraction same as on integer numbers

39 Arithmetic - fix-point notation 38/47 3. Multiplication of fix-point numbers

40 Arithmetic - fix-point notation 39/47 4. Division of fix-point numbers Conclusions: 1. During multiplication and division rounding and precision errors can occur. 2. Fix-point notation should minimise these errors.

41 Arithmetic - floating-point notation 40/47 1. Floating-point notation - basis

42 Arithmetic - floating-point notation 41/47 Mantissa is usually stored in SM code (separate sign bit). Exponent e is stored in C2 either in “shifted” C2: Shifted C2 simplifies calculation algorithms, but needs an attention during multiplication and division.

43 Arithmetic - floating-point notation 42/47 2. Formulas for basic calculations

44 Arithmetic - floating-point notation 43/47 3. Examples of FP notations

45 Arithmetic - floating-point notation 44/47

46 Arithmetic - floating-point notation 45/47 4. Examples of algorithms 4.1. Addition and subtraction

47 Arithmetic - floating-point notation 46/47 4.2. Multiplication

48 Arithmetic - floating-point notation 47/47 4.3. Division


Download ppt "Microprocessor Technique Binary codes. Lecture 2 1/47 Binary codes in microprocessor technique Integer arithmetic Fix-point arithmetic Floating-point."

Similar presentations


Ads by Google