number system (review)

43
Introduction to Microprocesso rs 1 Number system Number system (Review) (Review)

Upload: mikkel

Post on 12-Feb-2016

33 views

Category:

Documents


0 download

DESCRIPTION

Number system (Review). The Decimal Number System. ประกอบไปด้วย สัญลักษณ์ใช้แทนค่า จำนวน 10 ตัว คือ 0 - 9 น้ำหนักของตำแหน่ง ในกรณีหน้าจุด จะเป็น 10 + เริ่มจาก 10 0 10 1 10 2 … ในกรณีหลังจุด จะเป็น 10 - เริ่มจาก 10 -1 10 -2 10 -3 …. ตัวอย่างเช่น - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Number system (Review)

Introduction to Microprocessors 1

Number systemNumber system(Review)(Review)

Page 2: Number system (Review)

Introduction to MicroprocessorsIntroduction to Microprocessors 22

The Decimal Number SystemThe Decimal Number System ประกอบไปด้วย สญัลักษณ์ใชแ้ทนค่า จำานวน ประกอบไปด้วย สญัลักษณ์ใชแ้ทนค่า จำานวน 10 10 ตัว คือ ตัว คือ

- 0 9 - 0 9 นำ!าหนักของตำาแหน่งนำ!าหนักของตำาแหน่ง

• ในกรณีหน้าจุด จะเป็น ในกรณีหน้าจุด จะเป็น 1010++ เริม่จาก เริม่จาก 101000 10 1011 101022 … …

• ในกรณีหลังจุด จะเป็น ในกรณีหลังจุด จะเป็น 1010-- เริม่จาก เริม่จาก 1010-1-1 10 10-2-2 1010-3-3 …. ….

ตัวอยา่งเชน่ตัวอยา่งเชน่• 25732. 25732. = = 2 2 x 10x 1022 + 5 x 10 + 5 x 1011 + 7 x 10 + 7 x 1000

+ 3 x 10+ 3 x 10-1-1 + 2 x 10 + 2 x 10-2-2

Page 3: Number system (Review)

Introduction to MicroprocessorsIntroduction to Microprocessors 33

The Binary Number SystemThe Binary Number System ประกอบไปด้วย สญัลักษณ์ใชแ้ทนค่า จำานวน ประกอบไปด้วย สญัลักษณ์ใชแ้ทนค่า จำานวน 2 2 ตัว คือ ตัว คือ

0 1, 0 1, นำ!าหนักของตำาแหน่งนำ!าหนักของตำาแหน่ง

• ในกรณีหน้าจุด จะเป็น ในกรณีหน้าจุด จะเป็น 22++ เริม่จาก เริม่จาก 2200 2 211 2 222 … …• ในกรณีหลังจุด จะเป็น ในกรณีหลังจุด จะเป็น 22-- เริม่จาก เริม่จาก 22-1-1 2 2-2-2 2 2-3-3

…. …. ตัวอยา่งเชน่ตัวอยา่งเชน่

•1011010110 22 = 1= 1 x 2x 222 + 0 x 2 + 0 x 211 + 1 x 2 + 1 x 200 + + 1 x 21 x 2-1-1 + 1 x 2 + 1 x 2-2-2

Page 4: Number system (Review)

Introduction to MicroprocessorsIntroduction to Microprocessors 44

Decimal to Binary ConversionDecimal to Binary Conversion ใชว้ธิกีารหารสั!นด้วย ใชว้ธิกีารหารสั!นด้วย 22 หารไปเรื่อย ๆ จนกวา่จนกวา่ผลลัพธท่ี์ได้จะเป็น ศูนย์หารไปเรื่อย ๆ จนกวา่จนกวา่ผลลัพธท่ี์ได้จะเป็น ศูนย์ พจิารณาเฉพาะเศษท่ีได้จากการหาร แต่ละครั !งพจิารณาเฉพาะเศษท่ีได้จากการหาร แต่ละครั !ง ตัวอยา่งเชน่ ตัวอยา่งเชน่ 57571010 = ?= ?22

57571010 = = 11100111100122

572814

731

222222

0

100111

Page 5: Number system (Review)

Introduction to MicroprocessorsIntroduction to Microprocessors 55

Decimal to Binary ConversionDecimal to Binary Conversion ในกรณีของจุดทศนิยม จะใชว้ธิคีณูจุดทศนิยมนั!นด้วย ในกรณีของจุดทศนิยม จะใชว้ธิคีณูจุดทศนิยมนั!นด้วย 2 2

แล้วพจิารณาตัวเลขท่ีอยูห่น้าจุด ท่ีได้จากการคณู แล้วนำาแล้วพจิารณาตัวเลขท่ีอยูห่น้าจุด ท่ีได้จากการคณู แล้วนำาตัวเลขทศนิยม ไปคณูด้วยเลข ตัวเลขทศนิยม ไปคณูด้วยเลข 2 2 อีก ทำาเชน่นี!เรื่อย ๆ อีก ทำาเชน่นี!เรื่อย ๆ จนกวา่ตัวเลขท่ีอยูห่ลังจุด จะเป็น ศูนย ์หมดจนกวา่ตัวเลขท่ีอยูห่ลังจุด จะเป็น ศูนย ์หมด034375.034375. 1010 = ?= ?222 x 0.343752 x 0.34375 = = 00.6875.68752 x 0.68752 x 0.6875 = = 11.375.3752 x 0.3752 x 0.375 = = 00.75.752 x 0.752 x 0.75 = = 11.5.52 x 0.52 x 0.5 = = 11.0.0 คำาตอบคือ คำาตอบคือ 001011001011 22

Page 6: Number system (Review)

Introduction to MicroprocessorsIntroduction to Microprocessors 66

ในกรณีท่ีมทัี!งตัวเลข ท่ีอยูข่า้งหน้าจุดและหลังจุด ใหคิ้ดแยกในกรณีท่ีมทัี!งตัวเลข ท่ีอยูข่า้งหน้าจุดและหลังจุด ใหคิ้ดแยกกันแล้วนำามารวมกันภายหลังกันแล้วนำามารวมกันภายหลัง

12125.12125. 1010 = ?= ?22 2 0125x . 2 0125x . 025= . 025= . 2 025x . 2 025x . 05= . 05= . 2 05x . 2 05x . 10= . 10= .

12121010 = 1100 = 110022 0125.0125. 1010 0001= . 0001= . 22

คำาตอบ คำาตอบ 12125.12125. 1010 1100001= . 1100001= . 22

12631

2222

0

0011

Decimal to Binary ConversionDecimal to Binary Conversion

Page 7: Number system (Review)

Introduction to MicroprocessorsIntroduction to Microprocessors 77

Hexadecimal Hexadecimal vs.vs. Binary Number Binary Number

เลขฐาน เลขฐาน 16 16 และ ฐาน และ ฐาน 2 2 มคีวามสมัพนัธกั์น สามารถมคีวามสมัพนัธกั์น สามารถทำาการการแปลงฐานซึ่งกันและกันได้ทำาการการแปลงฐานซึ่งกันและกันได้

เลขฐาน เลขฐาน 2 2 จำานวน จำานวน 4 4 หลัก จะเท่ากับเลขฐาน หลัก จะเท่ากับเลขฐาน 16 16 จำานวน จำานวน 1 1 หลัก โดยเริม่นับแบง่ตั!งแต่จุดทศนิยมไปทางซา้ยและขวาหลัก โดยเริม่นับแบง่ตั!งแต่จุดทศนิยมไปทางซา้ยและขวา

ถ้าไมค่รบ ถ้าไมค่รบ 4 4 หลักใหท้ำาการเพิม่เลข หลักใหท้ำาการเพิม่เลข 0 0 เขา้ไปจนครบ เขา้ไปจนครบ 4 4 หลักหลัก เชน่ เชน่ 10011110100101011001111010010101 22

= ?= ?161600100010 01110111 1010 . 1010 .01010101 0100010022

22 77 .. .. 55 441616

Page 8: Number system (Review)

Introduction to MicroprocessorsIntroduction to Microprocessors 88

Binary AdditionBinary Addition

TermTerm Binary Addition Binary AdditionCarryCarry 1111 111 1111 111AddendAddend 0110 0011 0110 0011

AugendAugend 0101 1111 0101 1111

SumSum 1100 0010 1100 0010

+ A ddend0 1

Augend 0

10 1

01 C arry

Page 9: Number system (Review)

Introduction to MicroprocessorsIntroduction to Microprocessors 99

Binary AdditionBinary AdditionTermTerm Binary Addition Binary AdditionCarryCarry 0001 111 0001 111AddendAddend 1000 1001 1000 1001AugentAugent 0000 1111 0000 1111SumSum 1001 1000 1001 1000

TermTerm Binary Addition Binary AdditionCarryCarry 1011 1101 11 1011 1101 11

11 100 11 100AddendAddend 0100 0010 01 0100 0010 01

10 1100 10 1100AugentAugent 0101 1110 10 0101 1110 10

01 0110 01 0110SumSum

1010 0001 0000 0 1010 0001 0000 0 010 010

+ A ddend0 1

Augend 0

10 1

01 C arry

Page 10: Number system (Review)

Introduction to MicroprocessorsIntroduction to Microprocessors 1010

Binary SubtractionBinary Subtraction

TermTerm Binary SubtractionBinary SubtractionBorrowBorrow 0 1 1 0 0 0 00 1 1 0 0 0 0MinuendMinuend 0 1 1 0 1 1 0 10 1 1 0 1 1 0 1SubtrahendSubtrahend 0 0 1 1 0 0 0 10 0 1 1 0 0 0 1DifferenceDifference 0 0 1 1 1 1 0 0 0 0 1 1 1 1 0 0

- S ubtrahend0 1

Minuen

d 01

0 101

B o rro w

Page 11: Number system (Review)

Introduction to MicroprocessorsIntroduction to Microprocessors 1111

TermTerm Binary Subtraction Binary SubtractionBorrowBorrow 0001 110 0001 110MinuendMinuend 1111 0001 1111 0001SubtrahendSubtrahend 0000 0011 0000 0011DifferenceDifference 1110 1110 1110 1110

TermTerm Binary Subtraction Binary SubtractionBorrowBorrow

1111 1011 1100 000 1111 1011 1100 000MinuendMinuend

1001 0011 1001 1001 1001 0011 1001 1001SubtrahendSubtrahend

0101 1101 1111 0001 0101 1101 1111 0001DifferenceDifference

0011 0101 1010 1001 0011 0101 1010 1001

Binary SubtractionBinary Subtraction

Page 12: Number system (Review)

Introduction to MicroprocessorsIntroduction to Microprocessors 1212

การเก็บตัวเลขแบบคิดการเก็บตัวเลขแบบคิดเครื่องหมายเครื่องหมาย

แบบ แบบ Sign and Magnitude methodSign and Magnitude method• จะใช ้จะใช ้Bit Bit ท่ีแรกสดุ ในการเก็บเครื่องหมาย ถ้าท่ีแรกสดุ ในการเก็บเครื่องหมาย ถ้า

เป็น เป็น 0 0 คือ ค่าบวก และถ้าเป็น คือ ค่าบวก และถ้าเป็น 1 1 จะเป็น ค่าจะเป็น ค่าลบ เชน่ลบ เชน่

BinaryBinary DecimalDecimal0001 11000001 1100 +28+281001 11001001 1100 -28-28

Page 13: Number system (Review)

Introduction to MicroprocessorsIntroduction to Microprocessors 1313

การเก็บตัวเลขแบบคิดการเก็บตัวเลขแบบคิดเครื่องหมายเครื่องหมาย

แบบ แบบ One’s Complement One’s Complement • จะให ้จะให ้Bit Bit แรกเป็น แรกเป็น Sign Bit Sign Bit เชน่กัน แต่ถ้าเชน่กัน แต่ถ้า

หากขอ้มูลเป็นลบ จะทำาการกลับ หากขอ้มูลเป็นลบ จะทำาการกลับ Bit Bit ของขอ้มูลของขอ้มูลจาก จาก 0 0 เป็น เป็น 1 1 และ จาก และ จาก 1 1 เป็น เป็น 00

BinaryBinary DecimalDecimal0001 11000001 1100 +28+281110 00111110 0011 -28-28

Page 14: Number system (Review)

Introduction to MicroprocessorsIntroduction to Microprocessors 1414

การเก็บตัวเลขแบบคิดการเก็บตัวเลขแบบคิดเครื่องหมายเครื่องหมาย

Two’s Complement Two’s Complement• จะกระทำาเชน่เดียวกับ การทำา จะกระทำาเชน่เดียวกับ การทำา 1’s 1’s แต่ในกรณีที่แต่ในกรณีที่

ขอ้มูลมค่ีาเป็นลบ จะทำาการบวกเพิม่ขึ!นไปอีก ขอ้มูลมค่ีาเป็นลบ จะทำาการบวกเพิม่ขึ!นไปอีก 11

BinaryBinary DecimalDecimal0001 11000001 1100 +28+281110 01001110 0100 -28-28

Page 15: Number system (Review)

Introduction to MicroprocessorsIntroduction to Microprocessors 1515

การลบเลขด้วยวธิ ีการลบเลขด้วยวธิ ี11’s’s complementcomplement นำาเอาตัวลบไปทำา นำาเอาตัวลบไปทำา 11 ’s’s นำาเอาตัวตั!งและตัวลบ นำาเอาตัวตั!งและตัวลบ (1’s) (1’s) มารวมกัน แต่มารวมกัน แต่

จำานวนของหลังของตัวตั!งและตัวลบต้องเท่ากันจำานวนของหลังของตัวตั!งและตัวลบต้องเท่ากัน ผลท่ีได้จากการรวมกันผลท่ีได้จากการรวมกัน

• ถ้ามตัีวทด ใหน้ำาไปบวกเพิม่จากผลท่ีได้ คำาตอบถ้ามตัีวทด ใหน้ำาไปบวกเพิม่จากผลท่ีได้ คำาตอบจะมมีาเป็นค่าบวกจะมมีาเป็นค่าบวก

• ถ้าไมม่ตัีวทด ใหน้ำาผลที่ได้ ไปทำา ถ้าไมม่ตัีวทด ใหน้ำาผลที่ได้ ไปทำา 11 ’s ’s อีกครั!งอีกครั!งหนึ่ง คำาตอบจะออกมาเป็นค่าลบหนึ่ง คำาตอบจะออกมาเป็นค่าลบ

Page 16: Number system (Review)

Introduction to MicroprocessorsIntroduction to Microprocessors 1616

- 101000000 11101101 - 101000000 11101101

11 ’s ’s ของ ของ 011101101 011101101 = 1 0001 = 1 0001 00100010

1 0100 00001 0100 0000++ 1 0001 00101 0001 00101 0 0101 00101 0 0101 0010 * * มตัีวทดมตัีวทด++ 11 001010011 001010011

คำาตอบคือ คำาตอบคือ 10100111010011

การลบเลขด้วยวธิ ีการลบเลขด้วยวธิ ี11’s’s complementcomplement

Page 17: Number system (Review)

Introduction to MicroprocessorsIntroduction to Microprocessors 1717

- 100101000 101001 - 100101000 101001 0010 0010

11 ’s ’s ของ ของ 1010010010 1010010010 = 01 = 01 0110 11010110 1101

01 0010 100001 0010 1000++ 01 0110 110101 0110 11010 10 1001 01010 10 1001 0101 * * ไม่ไม่มตัีวทดมตัีวทด 0101101010 0101101010 * * ทำา ทำา 11 ’s’s

คำาตอบคือ คำาตอบคือ - 1 0110 1010- 1 0110 1010

การลบเลขด้วยวธิ ีการลบเลขด้วยวธิ ี11’s’s complementcomplement

Page 18: Number system (Review)

Introduction to MicroprocessorsIntroduction to Microprocessors 1818

การลบเลขด้วยวธิ ีการลบเลขด้วยวธิ ี22’s’s นำาเอาตัวลบไปทำา นำาเอาตัวลบไปทำา 22 ’s’s นำาเอาตัวตั!งและตัวลบ นำาเอาตัวตั!งและตัวลบ (2’s) (2’s) มารวมกัน แต่มารวมกัน แต่

จำานวนของหลังของตัวตั!งและตัวลบต้องเท่ากันจำานวนของหลังของตัวตั!งและตัวลบต้องเท่ากัน ผลท่ีได้จากการรวมกันผลท่ีได้จากการรวมกัน

• ถ้ามตัีวทด ใหต้ัดตัวทดทิ!ง คำาตอบจะออกมาถ้ามตัีวทด ใหต้ัดตัวทดทิ!ง คำาตอบจะออกมาเป็นค่าบวกเป็นค่าบวก

• ถ้าไมม่ตัีวทด ใหน้ำาผลที่ได้ ไปทำา ถ้าไมม่ตัีวทด ใหน้ำาผลที่ได้ ไปทำา 22 ’s ’s อีกครั!งอีกครั!งหนึ่ง คำาตอบจะออกมาเป็นค่าลบหนึ่ง คำาตอบจะออกมาเป็นค่าลบ

Page 19: Number system (Review)

Introduction to MicroprocessorsIntroduction to Microprocessors 1919

- 101000000 11101101 - 101000000 11101101

2’s 2’s ของ ของ 011101101 011101101 = 1 0001 = 1 0001 00110011

1 0100 00001 0100 0000++ 1 0001 00111 0001 00111 0 0101 00111 0 0101 0011 * * มตัีวทดมตัีวทด 001010011 001010011

คำาตอบคือ คำาตอบคือ 10100111010011

การลบเลขด้วยวธิ ีการลบเลขด้วยวธิ ี22’s’s

Page 20: Number system (Review)

Introduction to MicroprocessorsIntroduction to Microprocessors 2020

- 100101000 101001 - 100101000 101001 0010 0010

11 ’s ’s ของ ของ 1010010010 1010010010 = 01 = 01 0110 11100110 1110

01 0010 100001 0010 1000++ 01 0110 111001 0110 11100 10 1001 01100 10 1001 0110 * * ไม่ไม่มตัีวทดมตัีวทด 0101101010 0101101010 * * ทำา ทำา 22 ’s’s

คำาตอบคือ คำาตอบคือ - 1 0110 1010- 1 0110 1010

การลบเลขด้วยวธิ ีการลบเลขด้วยวธิ ี22’s’s

Page 21: Number system (Review)

Introduction to MicroprocessorsIntroduction to Microprocessors 2121

Binary MultiplicationBinary Multiplication

x M ul tip l i cation0 1

Multip

lier 01

0 010

Page 22: Number system (Review)

Introduction to MicroprocessorsIntroduction to Microprocessors 2222

Binary MultiplicationBinary Multiplication กำาหนดใหตั้วเก็บผลรวมมค่ีาเท่ากับ ศูนย์กำาหนดใหตั้วเก็บผลรวมมค่ีาเท่ากับ ศูนย์ นำาตัวคณูทำาการ นำาตัวคณูทำาการ Shift Shift ขวา ขวา 1 1 ครั!ง ถ้า ครั!ง ถ้า Carry Carry

ท่ีออกมาเป็น ท่ีออกมาเป็น 1 1 ใหน้ำาตัวตั!งไปบวกเพิม่ ในตัวเก็บใหน้ำาตัวตั!งไปบวกเพิม่ ในตัวเก็บผลรวม ถ้า ผลรวม ถ้า Carry Carry ท่ีออกมาคือ ท่ีออกมาคือ 0 0 ไมต้่องนำาไปไมต้่องนำาไปบวกเพิม่บวกเพิม่

ทำาการ ทำาการ Shift Shift ตัวตั!งไปทางซา้ย ตัวตั!งไปทางซา้ย 1 1 ครั!งครั!ง ทำาซำ!าในขอ้ ทำาซำ!าในขอ้ 2 2 และ และ 3 3 จนกวา่ ขอ้มูลในตัวคณูจะจนกวา่ ขอ้มูลในตัวคณูจะ

หมดหมด

Page 23: Number system (Review)

Introduction to MicroprocessorsIntroduction to Microprocessors 2323

Binary MultiplicationBinary Multiplication 00010001

x 00001100 00000000 Shift ครัง้ท่ี 1ได้ 0 00000000 Shift ครัง้ท่ี 2 ได้ 0 00010001 Shift ครัง้ท่ี 3 ได้ 1 00010001 Shift ครัง้ท่ี 4 ได้ 1 00000000 Shift ครัง้ท่ี 5ได้ 0 00000000 Shift ครัง้ท่ี 6 ได้ 0 00000000 Shift ครัง้ท่ี 7 ได้ 0 00000000 Shift ครัง้ท่ี 8ได้ 0 000000011001100

Page 24: Number system (Review)

Introduction to MicroprocessorsIntroduction to Microprocessors 2424

การหาร การหาร (Division)(Division) ในกรณี เลขฐาน ในกรณี เลขฐาน 10 10 ทำาได้ดังนี!ทำาได้ดังนี!

1717 12 204 12 204 Quotient Quotient

12 12 Divisor DividendDivisor Dividend 8484

8484 00

Page 25: Number system (Review)

Introduction to MicroprocessorsIntroduction to Microprocessors 2525

ขั!นตอนในการหารเลขฐาน ขั!นตอนในการหารเลขฐาน 22 (1) (1) นำา นำา Divisor Divisor มาทำา มาทำา 22 ’s ’s โดยเพิม่ โดยเพิม่ Sign bit Sign bit เขา้ไปเขา้ไป12121010 = 1100= 110022 จะได้จะได้Sign bitSign bit 01100 0110011 10011 100112’s2’s 10100 10100

2( ) 2( ) นำาค่าของ นำาค่าของ 2’s 2’s ของ ของ Divisor Divisor ท่ีได้ ไปรวมกับ ท่ีได้ ไปรวมกับ dividend (dividend (คือการลบนัน่เองคือการลบนัน่เอง) ) โดยเขยีนใหแ้ต่ละหลังโดยเขยีนใหแ้ต่ละหลัง

ตรงกัน โดยเริม่จากทางด้านซา้ย ตรงกัน โดยเริม่จากทางด้านซา้ย

Binary DivisionBinary Division

Page 26: Number system (Review)

Introduction to MicroprocessorsIntroduction to Microprocessors 2626

Binary DivisionBinary Division 3( ) 3( ) ถ้าผลของ ถ้าผลของ Sign bit Sign bit ออกมาเป็น ออกมาเป็น 0 0

• แสดงวา่ แสดงวา่ Quotient Quotient ในตำาแหน่งนั!นคือ ในตำาแหน่งนั!นคือ 1 1• แล้วทำาการ แล้วทำาการ Shift Shift ผลท่ีได้จากขอ้ ผลท่ีได้จากขอ้ 2 2 ไปทางซา้ย ไปทางซา้ย 1 1 bitbit• แล้วกลับไปทำาขอ้ แล้วกลับไปทำาขอ้ 2 2 ใหม่ใหม่

(4) (4) ถ้าผลของ ถ้าผลของ Sign bit Sign bit ออกมาเป็น ออกมาเป็น 1 1• แสดงวา่ แสดงวา่ Quotient Quotient ในตำาแหน่งนั!นคือ ในตำาแหน่งนั!นคือ 0 0• จะต้องทำาการ บวกเพิม่เขา้ไปอีกเท่ากับจำานวนของ จะต้องทำาการ บวกเพิม่เขา้ไปอีกเท่ากับจำานวนของ

Divisor Divisor แล้วทำาการ แล้วทำาการ Shift Shift ผลท่ีได้จากขอ้ ผลท่ีได้จากขอ้ 2 2 ไปทางไปทางซา้ย ซา้ย 1 1 bitbit

• แล้วกลับไปทำาขอ้ แล้วกลับไปทำาขอ้ 2 2 ใหม่ใหม่

Page 27: Number system (Review)

Introduction to MicroprocessorsIntroduction to Microprocessors 2727

Binary DivisionBinary Division ทำาเชน่นี!ไปเรื่อย ๆ จนกวา่ผลท่ีออกมาจาก การทำาเชน่นี!ไปเรื่อย ๆ จนกวา่ผลท่ีออกมาจาก การ

รวมจะมค่ีาเท่ากับ ศูนย ์รวมจะมค่ีาเท่ากับ ศูนย ์

ถ้าผลรวมออกมาเป็น ศูนย ์ในขณะท่ีจำานวนหลักถ้าผลรวมออกมาเป็น ศูนย ์ในขณะท่ีจำานวนหลักของผลที่ได้ มากกวา่จำานวนหลักของ ของผลที่ได้ มากกวา่จำานวนหลักของ Divisor Divisor ให้ให้เพิม่ศูนยท่ี์ เพิม่ศูนยท่ี์ Quotient Quotient เท่ากับจำานวนหลักท่ีเกินเท่ากับจำานวนหลักท่ีเกินมามา

Page 28: Number system (Review)

Introduction to MicroprocessorsIntroduction to Microprocessors 2828

204 204 ÷ ÷ 1212204204 10 10 = 11001100= 1100110022

12121010 = 1100= 110022= 0 1100= 0 11001’s1’s = 1 0011= 1 00112’s2’s = 1 0100= 1 0100

0 11001100 0 11001100 DividendDividend 1 01000000 1 01000000 SubtractSubtract 12 1200 00001100 00001100

1Quotient = x 1Quotient = x

Binary DivisionBinary Division

Page 29: Number system (Review)

Introduction to MicroprocessorsIntroduction to Microprocessors 2929

Binary DivisionBinary Division

0 0001100 0 0001100 Shift resultShift result1 0 1 0 0 0 0 01 0 1 0 0 0 0 0 Subtract 12 Subtract 12 11 0 1 0 1 1 0 0 0 1 0 1 1 0 0Quotient = 10xQuotient = 10x

1 0 1 0 1 1 0 01 0 1 0 1 1 0 00 1 1 0 0 0 0 00 1 1 0 0 0 0 0 Add 12Add 120 0 0 0 1 1 0 00 0 0 0 1 1 0 0

Page 30: Number system (Review)

Introduction to MicroprocessorsIntroduction to Microprocessors 3030

0 001100 0 001100 Shift result Shift result 1 010000 1 010000 Subtract 12 Subtract 1211 011100 011100

100Quotient = x 100Quotient = x

1 011100 1 011100 0 110000 0 110000 12Add 12Add 0 001100 0 001100

Binary DivisionBinary Division

Page 31: Number system (Review)

Introduction to MicroprocessorsIntroduction to Microprocessors 3131

0 01100 0 01100 Shift result Shift result 1 01000 1 01000 Subtract 12 Subtract 1211 10100 10100

1000Quotient = x 1000Quotient = x

1 10100 1 10100 0 11000 0 11000 12 12 0 01100 0 01100

Binary DivisionBinary Division

Page 32: Number system (Review)

Introduction to MicroprocessorsIntroduction to Microprocessors 3232

0 1100 0 1100 Shift result Shift result 1 0100 1 0100 SubtracSubtrac

t 12 t 12 0 0000 0 0000

10001Quotient = 10001Quotient = 22

17= 17= 1010

Binary DivisionBinary Division

Page 33: Number system (Review)

Introduction to MicroprocessorsIntroduction to Microprocessors 3333

10100010100022 ÷÷ 100 10022

10010022 0100 01001’s1’s 1011 101122 1100 1100

0 101000 0 101000 . ........ ....... 1 100000 1 100000 Subtract 100 Subtract 1002200 001000 001000 1Quotient = x 1Quotient = x

Binary DivisionBinary Division

Page 34: Number system (Review)

Introduction to MicroprocessorsIntroduction to Microprocessors 3434

0 01000 0 01000 Shift result Shift result 1 10000 1 10000 Subtract1 0 0 Subtract1 0 0 22

11 11000 11000 10Quotient = x 10Quotient = x

1 11000 1 11000

0 10000 0 10000 100Add 100Add 22

0 01000 0 01000

Binary DivisionBinary Division

Page 35: Number system (Review)

Introduction to MicroprocessorsIntroduction to Microprocessors 3535

0 1000 0 1000 Shi f t r esul t Shi f t r esul t 1 1000 1 1000 Subtract 100 Subtract 1002200 0000 0000

101Quotient = x 101Quotient = x

จำานวนหลัก มมีากกวา่ตัวหารอยู ่จำานวนหลัก มมีากกวา่ตัวหารอยู ่ 1 1 หลัก จะต้องหลัก จะต้องเพิม่ศูนยเ์ขา้ไปที่ เพิม่ศูนยเ์ขา้ไปที่ Quotient Quotient อีก อีก 1 1 ตัวตัวคำาตอบคือ คำาตอบคือ 1010101022

Binary DivisionBinary Division

Page 36: Number system (Review)

Introduction to MicroprocessorsIntroduction to Microprocessors 3636

Floating Point NumberFloating Point Number ในเลขฐาน ในเลขฐาน 1010

10N = M x 10N = M x EE

M = Mantissa M = Mantissa E= Exponent E= Exponentเชน่ เชน่ 65535, 65535, สามารถเขยีนได้เป็นสามารถเขยีนได้เป็น

65535 65535 x 10x 1000 65535 65535 x 10x 1011

65535. 65535. x 10x 1022 65535. 65535. x 10x 1033

65535. 65535. x 10x 1044 065535. 065535. x x 101055

0065535. 0065535. x 10x 1066 00065535. 00065535. x 10x 1077

Page 37: Number system (Review)

Introduction to MicroprocessorsIntroduction to Microprocessors 3737

Floating Point FormatFloating Point Format ในฐาน ในฐาน 2 2

• Mantissa Mantissa บางครั!งเรยีกวา่ บางครั!งเรยีกวา่ Coefficient or Coefficient or FractionFraction

• Exponent Exponent บางครั!งบางครั!งเรยีกวา่ เรยีกวา่ Characteristic or PowerCharacteristic or Power

ExponentExponent• จะเก็บอยูใ่นรูปแบบท่ี จะเก็บอยูใ่นรูปแบบท่ี Equivalent Equivalent ของเลขของเลข

22 ’S ’S ยกตัวอยา่งเชน่ การเก็บแบบ ยกตัวอยา่งเชน่ การเก็บแบบ XS-64XS-64

Page 38: Number system (Review)

Introduction to MicroprocessorsIntroduction to Microprocessors 3838

0

XS - 64

6 0...7

Floating Point FormatFloating Point Format ExponentExponent

RangRang 00000000 00000000

to 0111 1111 to 0111 1111- 64 63to +- 64 63to +

- 7 bit - 64XS 63+ 1111111

….32 1100000

….1 10000010 100 0000-1 0111111

….-32 0100000

….-63 0000001

-64 0000000

Page 39: Number system (Review)

Introduction to MicroprocessorsIntroduction to Microprocessors 3939

MantissaMantissa

Rang : Rang : 0100000000000000 0100000000000000 to to 0111111111111111 0111111111111111

0505 -to 1 2 -to 1 2-15-15

AndAnd 1100000000000000 1100000000000000 to 1000 0000 0000 0001 to 1000 0000 0000 0001

-05.-05. - -to (1 2 - -to (1 2-15-15)) Combined format Combined format ±± -05 102( . to . -05 102( . to . -15-15))

14 0...15

S ign

Page 40: Number system (Review)

Introduction to MicroprocessorsIntroduction to Microprocessors 4040

0

Validnegativenum ber

Va lidpositivenum ber

-(1-2 -15) x 2 63 -0.5 x 2 -64 0.5 x 2 -64 (1-2 -15) x 2 63

over flow over flowunder flow(S et to 0)

จากตัวอยา่งสามารถ อ้างจำานวนได้จากตัวอยา่งสามารถ อ้างจำานวนได้(0.5 x 2(0.5 x 2-64-64 to (1-2 to (1-2-15-15) x 2) x 26363))(2.7105 x 10(2.7105 x 10-19-19 to 0.9223 x 10 to 0.9223 x 101919))

Page 41: Number system (Review)

Introduction to MicroprocessorsIntroduction to Microprocessors 4141

Binary Code Decimal NumberBinary Code Decimal Number

หรอืเรยีกอีกอยา่งหนึ่งวา่ หรอืเรยีกอีกอยา่งหนึ่งวา่ BCD numberBCD numberDecimal NumberDecimal Number BCD NumberBCD Number00 0000000011 0001000122 0010001033 0011001144 0100010055 0101010166 0110011077 0111011188 1000100099 10011001

Page 42: Number system (Review)

Introduction to MicroprocessorsIntroduction to Microprocessors 4242

Addition of Unsigned BCD NumberAddition of Unsigned BCD Number

การบวกเลข การบวกเลข BCD BCD ทำาการบวกเหมอืนกับเลขฐาน ทำาการบวกเหมอืนกับเลขฐาน 16 16ธรรมดาธรรมดา

ถ้าการบวกในหลักใด มค่ีามากกวา่ ถ้าการบวกในหลักใด มค่ีามากกวา่ 9 9 ใหท้ำาการบวกเพิม่ใหท้ำาการบวกเพิม่ไปอีก ไปอีก 66

7 6+ = 7 6+ = ??7 =7 = 0000 01110000 01116 =6 = 0000 01100000 01100000 11010000 1101 เกิน เกิน 99

00000110 00000110 0001 0011 0001 0011 = 13= 13

Page 43: Number system (Review)

Introduction to MicroprocessorsIntroduction to Microprocessors 4343

67 34+ = ? 7 = 0111

4 = 0100 + 1011 > 9 0110 +1 0001 = 1

Carry

Addition of Unsigned BCD NumberAddition of Unsigned BCD Number

3 = 0011 6 = 0110 +1001

0001 + (Carry จาก 7 +4 )1010 > 90110 + 1 0000

คำาตอบคือ 0001000 00001

1 0 1