1 / 21

Lecture 2

Lecture 2. Number Representations. Number Representations. Decimal 8547 = 8*10 3 + 5*10 2 + 4*10 1 + 7*10 0 Common form V(D) = d n-1 *10 n-1 + d n-2 *10 n-2 + … + d 0 *10 0 Binary V(B) = b n-1 *2 n-1 + b n-2 *2 n-2 + … + b 0 *2 0. Number Representations. Binary to Decimal

Download Presentation

Lecture 2

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Lecture 2 Number Representations

  2. Number Representations • Decimal 8547 = 8*103 + 5*102 + 4*101 + 7*100 • Common form V(D) = dn-1*10n-1 + dn-2*10n-2 + … + d0*100 • Binary V(B) = bn-1*2n-1 + bn-2*2n-2 + … + b0*20

  3. Number Representations • Binary to Decimal (1101)2 = 1*23 + 1*22 + 0*21 + 1*20 = 8 + 4 + 0 + 1 = 13 • Decimal to Binary 2 13 LSB LSB 6 2 1 13 = (1101)2 3 2 0 MSB 1 2 1 1 0 MSB

  4. Number Representations • Octal (เลขฐาน 8) • มีตัวเลขที่มีค่าตั้งแต่ 0 ถึง 7 • กลุ่มของ Octal digit จะแสดงโดยใช้จำนวนบิต 3bits • การแปลง Binary number ให้เป็น Octal number ทำโดยการแบ่งกลุ่มของ Binary number ทีละ 3 บิต โดยให้เริ่มที่ฝั่ง LSB (least significant bit) • Example (101011010111)2 = 101011010111 = (5327)8

  5. Number Representations • Hexadecimal (เลขฐาน 16) • ตัวเลขมีค่าตั้งแต่ 0 ถึง 9 และ ตัวอักษรตั้งแต่ A ถึง F • กลุ่มของ Hexadecimal จะแสดงโดยใช้จำนวนบิต 4bits • การแปลง Binary number ให้เป็น Hexadecimal ทำโดยการแบ่งกลุ่มของ Binary number ทีละ 4 บิต โดยให้เริ่มที่ฝั่ง LSB (least significant bit) • Example (AF25)16 = (1010111100100101)2 • ทำไมต้องใช้ Octal และ Hexadecimal เนื่องจากเป็นทางลัดในการอ้างถึง Binary (shorthand notation)

  6. Sign-and-magnitude • Sign-and-magnitude • คือ Binary number ที่มีลักษณะในการบ่งบอกค่าบวกและลบเหมือนกับ Decimal number • ใช้ extra bit สำหรับการบ่งบอกว่าเป็นค่าบวกหรือลบ • Extra bit จะอยู่ที่ตำแหน่ง MSB เพื่อเป็นตัวบ่งบอกว่าเป็นบวกหรือลบ • MSB = 0 ; number is positive • MSB = 1 ; number is negative • Example 0101 = +5 1101 = -5 Extra bit

  7. 1’s complement • 1’s complement • ค่าที่เป็น negative หรือค่าลบสามารถทำได้โดย complement แต่ละบิตรวมทั้ง bit ที่เป็น MSB ด้วย • Example 0101 = +5 1010 = -5

  8. 2’s complement • 2’s complement • ค่าที่เป็น negative หรือค่าลบสามารถแสดงได้โดยการบวก 1 ให้กับ 1’s complement • Example 0101 = +5 1’s complement = 1010 2’s complement = 1010 + 1 1011 = -5

  9. Sign-and-magnitude • เป็นการแสดงตัวเลขแบบง่าย แต่ไม่ได้ใช้ในระบบคอมพิวเตอร์ปัจจุบันเนื่องจาก เช่นเมื่อเราต้องการบวกตัวเลข 2 ตัวที่มีค่าเป็น opposite sign เช่น +5 กับ -2 จะต้องทำการหาก่อนว่าตัวไหนเป็นตัวที่มากกว่า และตัวไหนมีค่าน้อยกว่า • จำเป็นต้องมี extra logic circuit เพื่อที่จะหาการเปรียบเทียบค่าระหว่างตัวเลข 2 ตัวก่อน

  10. 1’s complement • 1’s complement สามารถคำนวณตัวเลขสองตัวได้โดยไม่ต้องผ่าน comparing circuit • Example 5 + 0101 + -2 1101 3 10010 1 0011 • ต้องนำ carry bit บวกเข้าไปกับผลลัพธ์อีกครั้งหนึ่ง 1’s complement Carry bit

  11. 2’s complement • ผลลัพธ์ที่ได้จากการทำ 2’s complement ไม่ต้องมี comparing circuit และไม่ต้องมีการนำ carry bit มาบวกเข้าอีกทีหนึ่ง • Example 5 + 0101 + -2 1110 3 10011 ignore ดังนั้น 0011 = 3

  12. Arithmetic Overflow • Arithmetic overflow จะเกิดขึ้นเมื่อมีการบวกหรือลบตัวเลข แล้วเกิดผลลัพธ์ขึ้นมาแล้วทำให้มี bit เกินมาจากผลลัพธ์ เราเรียกว่า overflow • ภายใน Processor มีวงจรในการตรวจจับ Overflow โดย Overflow = Cn-1 Cn (C คือ carry bit ที่เกิดขึ้นจากการคำนวณ)

  13. Arithmetic Overflow • Example 7 + 0 1 1 1 + 2 0 0 1 0 9 1 0 0 1 c2 c1 c4 c3 C3 = 1 C4 = 0 C3  C4 = 1 Overflow occurs

  14. Arithmetic Overflow • Example -7 + 1 0 0 1 + 2 0 0 1 0 -5 1 0 1 1 c2 c1 c4 c3 C3 = 0 C4 = 0 C3  C4 = 0 No Overflow

  15. Memory locations & addresses • Memory ประกอบด้วย set ของ storage cell ซึ่งแต่ละ cell จะเก็บข้อมูลได้ 1bit, กลุ่มของ bit เมื่อนำมารวมกันเพื่อทำการประมวลผลเราจะเรียกว่า word ซึ่ง word เป็นหน่วยที่ใช้ในการเข้าถึงและเก็บข้อมูล • การเข้าถึงข้อมูลที่เป็น word จำเป็นจะต้องอ้างถึง address(ที่อยู่) โดยปกติ Memory address จะมีค่าตั้งแต่ 0 ถึง 2k-1 ,2kคือ Address size space • Example 32 bit address = 232 = 4,294,967,296 ประมาณ 4 gig

  16. Memory locations & addresses 32 bit is 4 bytes

  17. Memory locations & addresses (a) A signed integer (b) Four characters Example of encoded information in a 32-bit word

  18. Memory locations & addresses • 1 byte = 8 bits • 1 word = 16 to 64 bits, โดยทั่วไปจะเป็น 32 bits • ส่วนใหญ่จะใช้ byte-addressable เข้าถึง address ใน Memory, ทุก ๆ byte ใน 1word จะถูกเก็บต่อ ๆ กันใน Memory address space • ถ้าใน 1word มี 4byte การไล่ตำแหน่งของ word ลำดับต่อไปก็จะเป็น 0, 4, 8 ,16, ……

  19. Big endian & Little endian (a) Big-endian assignment (b) Little-endian assignment

  20. Big endian & Little endian • Big-endian : lower byte address จะอยู่ทางซ้ายมือ หรือ most significant byte (left most of the word) • Little-endian : higher byte address จะอยู่ทางซ้ายมือ หรือ most significant byte

  21. Memory Operations • Load • Read or fetch data from a memory to a processor • Store • Write data from processor back to a memory

More Related