1
play

1 Representing a range of numbers Signed magnitude representation o - PDF document

Our mutual friend Numeric Representation o Conversion to and from hex is not too Two's complement and friends BAD 16 = __________ 10 . o Octal is also useful* 0, 1, 2, 3, . . . o Why do machine language programmers confuse Halloween with


  1. Our mutual friend Numeric Representation o Conversion to and from hex is not too Two's complement and friends BAD 16 = __________ 10 . o Octal is also useful* 0, 1, 2, 3, . . . o Why do machine language programmers confuse Halloween with Christmas? CS240 Computer Organization Department of Computer Science Wellesley College *And the same conversion trick works between binary and octal. Why? Numeric representation 4-2 Frankly, other conversions are no Arithmetic is the same everywhere where as nice ... o Given a number num , we find d n d n-1 ... d 1 d 0 so that Addition Subtraction num = d n r n + d n-1 r n-1 + ... + d 1 r 1 + d 0 r 0 10011 2 � CDB 16 � + � 00101 2 - � C3E 16 o The algorithm* is simple, but tedious. for i ← 0 to n � � � � do � d i ← num mod r � Multiplication Division � � � � num ← num div r � 134 8 � x � 27 8 11 2 100011 2 * num = d n r n-1 + ... + d 1 r 1 + d 0 r 0 = ( num div r ) * r + ( num mod r ). Repeat. Numeric representation 4-3 Numeric representation 4-4 1

  2. Representing a range of numbers Signed magnitude representation o Using n bits, we could represent the natural numbers up o What range of numbers can be represented using an n-bit to 2 n - 1 . . . binary number. 0 1 2 3 4 5 . . . 2 n -1 � 0 1 1 0 0 1 1 1 � n-1 . . . 2 1 0 � 000...0 111...1 � o . . . or we could reserve one bit, usually the msb , to represent a number ’ s sign. -(2 n -1 -1) -2 -1 0 1 2 2 n-1 -1 � sign bit sign bit 111...1 011...1 � (positive) (negative) Numeric representation 4-5 Numeric representation 4-6 Some problems with signed magnitude Click and Clack ride again o Additional circuitry is needed to add positive numbers o An automobile odometer to negative numbers. 0 1 1 0 1 � represents +1101 � � provides an elementary solution, provided it runs � 1 1 1 0 1 � represents -1101 backwards as well as forwards � number line o And, how exactly does one represent zero?* � � -500 ... -3 -2 -1 0 1 2 3 ... 499 � � number line � � 500 ... 997 998 999 000 001 002 003 ... 499 � *Rule for taking the negative of a number: Subtract number from 999 *And why is this a problem? (to avoid borrowing) then add 1 Numeric representation 4-7 Numeric representation 4-8 2

  3. Digital Tappet Brothers Addition works perfectly* o We build a binary odometer o We retain our handy-dandy 3-bit binary odometer -1 � 3 � o The number line works exactly the same as before + � -2 + � -1 number line � � � -4 -3 -2 -1 0 1 2 3 � � -1 � 2 � number line + � -4 + � -3 � � � 100 101 110 111 000 001 010 011 � *Rule for taking the negative of a number: Subtract number from 111 *And there is no need for a separate circuit to do subtraction. (to avoid borrowing) then add 1 But overflow remains a clear and present danger. Numeric representation 4-9 Numeric representation 4-10 Detecting overflow Logical operations o Some language, C for add add $s1,$s2,$s3 $s1=$s2 + $s3 Arithmetic subtract sub $s1,$s2,$s3 $s1=$s2 - $s3 example, ignore integer add immediate addi $s1,$s2,100 $s1=$s2 + 100 overflow. Others require that the program be and and $s1,$s2,$s3 $s1=$s2 & $ s3 notified. or or $s1,$s2,$s3 $s1=$s2 | $s3 o MIPS detects overflow nor nor $s1,$s2,$s3 $s1=~($s2 | $s3) with an exception. Logical and immediate andi $s1,$s2,100 $s1=$s2 & 100 o The exception program or immediate ori $s1,$s2,100 $s1=$s2 | 100 counter (EPC) contains the sll sll $s1,$s2,10 $s1=$s2 << 10 address of the offending srl srl $s1,$s2,10 $s1=$s2 >> 10 instruction. Data transfer load word lw $s1,100($s2) $s1=Mem[$s2+100] store word sw $s1, 100($s2) Mem[$s2+100]=$s1 Numeric representation 4-11 Numeric representation 4-12 3

  4. andi $t2, $s0, 15 Alas, no NOT o AND applied can be used o In keeping with the two-operand format, the to mask or conceal certain designers of MIPS decided against a NOT bit patterns by forcing 0s. operation. o For example, suppose $s0 held the bit pattern o A NOR operation is offered in consolation.* 72 A8 8B AD? o Similarly, the OR nor $t0, $t1, $t2 # $t0 = ~($t1 | $t3) � operation may be used force 1s. *How does this help? Numeric representation 4-13 Numeric representation 4-14 4

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend