COA课件-大连交大-lyx_Ch_09.ppt_第1页
COA课件-大连交大-lyx_Ch_09.ppt_第2页
COA课件-大连交大-lyx_Ch_09.ppt_第3页
COA课件-大连交大-lyx_Ch_09.ppt_第4页
COA课件-大连交大-lyx_Ch_09.ppt_第5页
已阅读5页,还剩37页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、William Stallings Computer Organization and Architecture6th Edition,Chapter 9 Computer Arithmetic,算术运算,9.1 Arithmetic & Logic Unit,Does the calculations Everything else in the computer is there to service this unit Handles integers May handle floating point (real) numbers,Page 284,ALU Inputs and Out

2、puts,Data from registers,Result to registers,Page 285,9.2 Integer Representation,Only have 0 & 1 to represent everything Positive numbers stored in binary e.g. 41=00101001 =32+8+1 No minus sign 没有负号 No period 没有小数点 Sign-Magnitude 符号-有效值表示法(原码) Twos complement 二进制补码表示法,Page 285,7 6 5 4 3 2 1 0,1.Sign

3、-Magnitude,Left most bit is sign bit 0 means positive 1 means negative E.g. +18 = 0 0010010 -18 = 1 0010010 Problems Need to consider both sign and magnitude in arithmetic Two representations of zero (+0 and 0: 00000000 & 10000000),Page 286,符号-有效值表示法,符号位有效值,Sign-magnitude,Defined(定义):n-bit integer 2

4、i ai if an-1=0 - 2i ai if an-1=1,n-2,n-2,i=0,i=0,Page 286,A=,2.Twos complement representation,A= -2n-1 an-1+ 2i ai The weight-value of Sign bit is negative. The weight-value of All other bits are positive. an-1 is also sign bit. an-1=0,positive an-1=1,negative,n-2,i=0,Page 288,(1)Value box(8-bit) 值盒

5、法,-128,+2,+1 = -125,-27 26 25 24 23 22 21 20,-120=,-128,+8,(a),(b),(c),Page 289,(2) Converting between different bit length,Sign-magnitude(原码) +18=0001 0010= +18= 000000000001 0010 -18=1001 0010= -18= 100000000001 0010 =Move sign bit to leftmost position, then fill in with zeros. Twos complement rep

6、resentation(补码) +18=0001 0010= +18= 000000000001 0010 -18=1110 1110= -18= 1?110 1110 = sign-extension rule . why? demonstrate,符号扩展,(2) Converting between different bit length Twos complement representation,An N-bit integer is stored in M-bit, and MN. How do you do? The N-bit integer is A: A= -2n-1 a

7、n-1+ 2i ai if A is positive, puts M-N bits zero on the left of the integer.,n-2,i=0,Page 289,If A is negative, must construct the M-bit of A A= -2m-1 am-1 + 2i ai The two values are equal: 等值扩展 (MN , am-1=1 & an-1 =1),m-2,i=0,符号位相等,-2m-1 + 2i ai = -2n-1 + 2i ai deletes the red part in both of equati

8、on -2m-1 + 2i ai = -2n-1,m-2,i=0,i=0,n-2,m-2,i=n-1,=,=,-2m-1 + 2i ai = -2n-1 Exchange 2n-1 + 2i ai = 2m-1 extend ( 2i = 2n-1 -1 ),m-2,i=n-1,m-2,i=n-1,i=0,n-2,1 + 2i + 2i ai = 1 + 2i deletes the red part 2i ai = 2i X 1 So, am-2 = =an-2 = an-1 =1 It is sign-extension rule.,n-2,m-2,m-2,i=0,i=n-1,i=0,m-

9、2,m-2,i=n-1,i=n-1,=,符号扩展,Converting between different bit length Twos complement representation,Positive number pack with leading zeros +18 = 00010010 +18 = 00000000 00010010 Negative numbers pack with leading ones -18 = 11101110 -18 = 11111111 11101110 i.e. pack with MSB (sign bit),9.3 integer arit

10、hmetic,One representation of zero Arithmetic works easily (see later) Negating(求负) is fairly easy 3 = 00000011 Boolean complement (bitwise not) gives11111100 Add 1 to LSB(Least Significant Bit) 11111101 (Value box: -128+64+32+16+8+4+1=-3),按位取反,最低有效位,Page 291,(1) Negation Rule 求负,In sign-magnitude re

11、presentation: 3= 00000011 (-3)=10000011 (Invert the sign bit) In twos complement, the negation of an integer can be formed with the following rules: bitwise not(including the sign bit).That is, set each 1 to 0 and each 0 to 1. Treating the result as an unsigned binary integer, add 1.,Page 291,Proof-

12、 Negation Rule (twos complement ),The N-bit integer is A: A= -2n-1 an-1+ 2i ai Now form the bitwise complement, and,treating this is an unsigned integer,add 1.,n-2,i=0,n-2,i=0,B= -2n-1 an-1+ 2i ai +1,Proof- Negation Rule (twos complement ),A+B=-2n-1 (an-1+ an-1 ) +2i (ai +ai )+1 =-2n-1 +2i +1 =-2n-1

13、 +(2n-1 -1) +1 =0 B=-A +2 = 00000010 -2 = 11111110,n-2,i=0,n-2,i=0,=,Negation Special Case 1,0 = 00000000 Bitwise not 11111111 Add 1 to LSB +1 Result 1 00000000 Overflow?(carriage) is ignored, so: - 0 = 0 = One representation of zero,进位, 不是溢出,Page 292,Negation Special Case 2,-128 = 10000000 bitwise

14、not 01111111 Add 1 to LSB +1 Result 10000000 So: -(-128) = -128 X (overflow) Monitor MSB (sign bit) It should change during negation,Range of Numbers,8 bit 2s compliment +127 = 01111111 = 27 -1 -128 = 10000000 = -27 16 bit 2s compliment +32767 = 011111111 11111111 = 215 - 1 -32768 = 100000000 000000

15、00 = -215 n bit 2s compliment,0 (2n-1 1) ( 2n-1 ) -1 (-2n-1 ) (2n-1 1),(2)Addition and Subtraction,Normal binary addition Monitor sign bit for overflow Take twos complement of subtrahend(减数) and add to minuend(被减数) i.e. a - b = a + (-b) So we only need addition and complement circuits in ALU,Page 29

16、2,观察符号位有无溢出,按位取反+1,Addition and Subtraction, A+B 补= A 补+ B补 Sum “+” All bits(include sign bit) to ADD A-B 补= A 补+ -B补 difference “-” All bits(include sign bit) to Sub ( -B补= B补 +1 ),Hardware for Addition and Subtraction,First integer,Sum or difference,Second integer,addition,subtraction,Page 296,fla

17、g=0 no overflow,flag=1 overflow,OF,Addition of Numbersin Twos Complement Respresentation,1001=-7 1100=-4 +0101= 5 +0100= 4 1110=-2 10000= 0 (a) (-7)+(+5) (b) (- 4)+(+4) 0011= 3 1100=-4 +0100= 4 +1111=-1 0111= 7 11011=-5 (c) (+3)+(+4) (d) (- 4)+(-1) 0101= 5 1001=-7 +0100= 4 +1010=-6 1001=overflow 100

18、11=overflow (e) (+5)+(+4)=+9 (f) (-7)+(-6)=-13,Page 293,overflow 溢出,If two numbers are add, and they are both positive or both negative, then overflow occurs if and only if the result has the opposite sign. NOTE: Difference of carriage & overflow NOTE:Overflow can occur whether or not there is a car

19、ry,进位,溢出,Page 293,(3) Multiplication 乘法,Complex 1x1=1, 1x0=0,0 x1=0,0 x0=0 Work out partial product for each digit Take care with place value (column) Add partial products,Page 294,部分乘积,对位,(a) unsigned integer,1011 Multiplicand (11 dec)被乘数 x 1101 Multiplier (13 dec) 乘数 1011 Partial products 部分乘积 000

20、0 Note: if multiplier bit is 1 copy 1011 multiplicand (place value) 1011 otherwise zero 10001111 Product (143 dec) 乘积 Note: need double length result,Page 296,Unsigned Binary Multiplication,Page 297,被乘数,乘数,Flowchart for Unsigned Binary Multiplication,Page298,(b) Signed integer (Negative),This does n

21、ot work! Solution 1 Convert to positive if required Multiply as above If signs were different, negate answer Solution 2 Booths algorithm,Multiplication Example Twos Complement,Negative x Negative 1011 Multiplicand (-5 dec)被乘数 x 1101 Multiplier (-3 dec) 乘数 11111011 Partial products 部分乘积 0000000 11101

22、1 00101(+5) 1 00001111 Product (+15 dec) 乘积 In fact, (-5)x(-3)=+15,Booths Algorithm,Page 301,算术移位,Division 除法,More complex than multiplication,Page 304,9.4 Floating-point representation,Numbers with fractions 带小数 Could be done in pure binary 1001.1010 = 23 + 20 +2-1 + 2-3 =9.625 N-bit integer and M-

23、bit fraction: A= 2i ai = 2i ai + 2i ai,Page 307,n-1,i=-m,n-1,i=0,-1,i=-m,整数部分 小数部分,3 2 1 0 -1 -2 -3 -4,Floating-point representation,Where is the binary point? Fixed? Very limited Moving? How do you show where it is? Floating point format 浮动小数点表示 e.g. 3.1415927 =0.31415927 x 101 =31415927 x 10-7 +S

24、x10+E,Significand 有效值,Exponent 指数,Base 基数,Floating Point 浮点数,+/- . significand x 2exponent Point is actually fixed between sign bit and body of mantissa(尾数) Exponent indicates place value (point position) Biased Exponent = Exponent+Bias value Bias value= 2K-1 -1 ,where K is the number of bits in the binary exponent,Sign bit,Biased Exponent,Significand or Mantissa,Page 308,符号 偏移指数 有效值部分,Floating Point Examples,Biased Exponent = True Exponent + (2K-1 -1) 10100 + 01111111 (K=8bits) 10010011,Page 308,10010011,0,1010001000,e.g. +1.1010001 x 210100

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论