SlideShare a Scribd company logo
1 of 19
Download to read offline
Prof. Nitin Ahire 1
Singed number concept
in
8051 Microcontroller
Nitin Ahire
XIE Mahim
Prof. Nitin Ahire 2
Singed number concept
• In everyday life, numbers are used that
could be +Ve or –Ve
• In the 8051 the MSB bit is set aside for the
sign
• If MSB(D7) =1 represent negative number
• If MSB(D7) =0 represent positive numbers
• The remaining bit D0 to D6 used for
magnitude.
Prof. Nitin Ahire 3
As 8051 is a 8 bit controller here
we consider the 8 bit numbers
D7 D6 D1D2D3D4D5 D0
SIGN MAGNITUDE
Prof. Nitin Ahire 4
POSITIVE NUMBERS
• The range of positive numbers can be
represent by the format as shown in figure
• It range from 0 to +127
0 0000 0000
+1 0000 0001
+5 0000 0101
+127 0111 1111
Prof. Nitin Ahire 5
NEGATIVE NUMBERS
• For negative number D7=1 however the
magnitude is represented in it’s 2’s
compliment form
• Steps
1 write the magnitude of the number in 8 bit
binary
2 invert each bit
3 add one to it
Prof. Nitin Ahire 6
• Show how the 8051 would represent – 5
• Sol:
0000 0101 5 in 8-bit binary
1111 1010 invert bit
1111 1011 add 1 ( which is FB h )
Prof. Nitin Ahire 7
• Show how the 8051 would represent -128
• Sol:
1000 0000
0111 1111
1000 0000 ( which become 80h)
Prof. Nitin Ahire 8
Range of singed numbers
• Decimal binary Hex
-128 1000 0000 80
-127 1000 0001 81
-126 1000 0010 82
… ….. …… ….
-2 1111 1110 FE
-1 1111 1111 FF
0 0000 0000 00
+1 0000 0001 01
+2 0000 0010 02
… …… ……. ….
+127 0111 1111 7F
Prof. Nitin Ahire 9
Overflow problem in signed number
• What is an overflow?
• If the result of an operation on the signed
numbers is too large for the register, an
overflow has occurred
CY AC -OVRS0RS1FO P
Prof. Nitin Ahire 10
Example
• Examine the following code and analyze
the result
MOV A,# +96
MOV R1, # +70
ADD A,R1
Prof. Nitin Ahire 11
Solution
+ 96 0110 0000 60h
+ 70 0100 0110 46h
-------- ---------------
+166 1010 0110 A6 and OV =1
according to CPU the result -90h which is wrong.
( OV = 1)
+166 is not the valid signed number. ( 0 to +127)
Prof. Nitin Ahire 12
When is the OV flag set?
1. There is carry from D6 to D7 but no carry
out of D7 (CY=0).
2. There is a carry from D7 out (CY=1) but
no carry from D6 to D7.
Prof. Nitin Ahire 13
Example 1
• MOV A, #-2 (FEh) ( 1111 1110)
• MOV R1,#-5 (FBh) ( 1111 1011)
• ADD A,R1 (F9h=-7, 1111 1001correct),
• So CPU generate OV=0
Prof. Nitin Ahire 14
Example 2
MOV A, #-128 ; (80H)
MOV R4,#-2 (FEH)
ADD A,R4 ( A=7EH =+127 INVALID )
So CPU generate OV =1
Prof. Nitin Ahire 15
Example 3
• MOV A,#+7; A=0000 0111 (A=07H)
• MOV R1,#+18; R1= 0001 0010 (R1=12H)
• ADD A,R1; A=0001 1001 (A=19H=+25)
According to CPU, this is +25, which is
correct (OV=0)
Prof. Nitin Ahire 16
• In any signed number addition OV
indicates whether the result is valid or not
• If OV=1, the result is erroneous
• If OV=0, the result is valid.
Prof. Nitin Ahire 17
BCD ADDITION
• Assume that 5 BCD data items are stored
in RAM location starting at 40H, write a
program to find the sum of all numbers.
The result must be in BCD.
Prof. Nitin Ahire 18
• Data 40=(71)
• 41=(11)
• 42=(65)
• 43=(59)
• 44=(37)
Prof. Nitin Ahire 19
Solution
• MOV R0,#40H
MOV R2,05H
CLR A
MOV R7,A
AGAIN:ADD A,@R0
DA A
JNC NEXT
INC R7
NEXT: INC RO
DJNZ R2,AGAIN
END

More Related Content

What's hot

General register organization (computer organization)
General register organization  (computer organization)General register organization  (computer organization)
General register organization (computer organization)rishi ram khanal
 
Multiplication algorithm
Multiplication algorithmMultiplication algorithm
Multiplication algorithmGaurav Subham
 
Register in Digital Logic
Register in Digital LogicRegister in Digital Logic
Register in Digital LogicISMT College
 
Addressing modes of 8051
Addressing modes of 8051Addressing modes of 8051
Addressing modes of 8051SARITHA REDDY
 
Interfacing memory with 8086 microprocessor
Interfacing memory with 8086 microprocessorInterfacing memory with 8086 microprocessor
Interfacing memory with 8086 microprocessorVikas Gupta
 
Divide by N clock
Divide by N clockDivide by N clock
Divide by N clockMantra VLSI
 
8259 Programmable Interrupt Controller
8259 Programmable Interrupt Controller8259 Programmable Interrupt Controller
8259 Programmable Interrupt Controllerabhikalmegh
 
Floating point representation
Floating point representationFloating point representation
Floating point representationmissstevenson01
 
Arithmetic & logical operations in 8051
Arithmetic & logical operations in 8051Arithmetic & logical operations in 8051
Arithmetic & logical operations in 8051Jay Patel
 
Microcontroller-8051.ppt
Microcontroller-8051.pptMicrocontroller-8051.ppt
Microcontroller-8051.pptDr.YNM
 
Dual and cyclo converter
Dual and cyclo converterDual and cyclo converter
Dual and cyclo converterRutika Abhang
 
Instruction set of 8086
Instruction set of 8086Instruction set of 8086
Instruction set of 80869840596838
 
Clock-8086 bus cycle
Clock-8086 bus cycleClock-8086 bus cycle
Clock-8086 bus cycleRani Rahul
 
Decoders-Digital Electronics
Decoders-Digital ElectronicsDecoders-Digital Electronics
Decoders-Digital ElectronicsPaurav Shah
 
Interfacing of io device to 8085
Interfacing of io device to 8085Interfacing of io device to 8085
Interfacing of io device to 8085Nitin Ahire
 
Synchronous and asynchronous reset
Synchronous and asynchronous resetSynchronous and asynchronous reset
Synchronous and asynchronous resetNallapati Anindra
 

What's hot (20)

General register organization (computer organization)
General register organization  (computer organization)General register organization  (computer organization)
General register organization (computer organization)
 
I o ports.ppt
I o ports.pptI o ports.ppt
I o ports.ppt
 
Multiplication algorithm
Multiplication algorithmMultiplication algorithm
Multiplication algorithm
 
Register in Digital Logic
Register in Digital LogicRegister in Digital Logic
Register in Digital Logic
 
Addressing modes of 8051
Addressing modes of 8051Addressing modes of 8051
Addressing modes of 8051
 
Interfacing memory with 8086 microprocessor
Interfacing memory with 8086 microprocessorInterfacing memory with 8086 microprocessor
Interfacing memory with 8086 microprocessor
 
Divide by N clock
Divide by N clockDivide by N clock
Divide by N clock
 
Ripple Carry Adder
Ripple Carry AdderRipple Carry Adder
Ripple Carry Adder
 
8259 Programmable Interrupt Controller
8259 Programmable Interrupt Controller8259 Programmable Interrupt Controller
8259 Programmable Interrupt Controller
 
Floating point representation
Floating point representationFloating point representation
Floating point representation
 
Arithmetic & logical operations in 8051
Arithmetic & logical operations in 8051Arithmetic & logical operations in 8051
Arithmetic & logical operations in 8051
 
Microcontroller-8051.ppt
Microcontroller-8051.pptMicrocontroller-8051.ppt
Microcontroller-8051.ppt
 
Line coding
Line codingLine coding
Line coding
 
Dual and cyclo converter
Dual and cyclo converterDual and cyclo converter
Dual and cyclo converter
 
Instruction set of 8086
Instruction set of 8086Instruction set of 8086
Instruction set of 8086
 
Clock-8086 bus cycle
Clock-8086 bus cycleClock-8086 bus cycle
Clock-8086 bus cycle
 
Acc logic
Acc logicAcc logic
Acc logic
 
Decoders-Digital Electronics
Decoders-Digital ElectronicsDecoders-Digital Electronics
Decoders-Digital Electronics
 
Interfacing of io device to 8085
Interfacing of io device to 8085Interfacing of io device to 8085
Interfacing of io device to 8085
 
Synchronous and asynchronous reset
Synchronous and asynchronous resetSynchronous and asynchronous reset
Synchronous and asynchronous reset
 

Similar to 8051 singed number concept [compatibility mode]

Similar to 8051 singed number concept [compatibility mode] (20)

Unit-1 Digital Design and Binary Numbers:
Unit-1 Digital Design and Binary Numbers:Unit-1 Digital Design and Binary Numbers:
Unit-1 Digital Design and Binary Numbers:
 
Alu1
Alu1Alu1
Alu1
 
Representation Of Numbers and Characters
Representation Of Numbers and CharactersRepresentation Of Numbers and Characters
Representation Of Numbers and Characters
 
Binary Arithmetic
Binary ArithmeticBinary Arithmetic
Binary Arithmetic
 
Parallel adders
Parallel addersParallel adders
Parallel adders
 
Computer Architecture
Computer ArchitectureComputer Architecture
Computer Architecture
 
Computer Architecture
Computer ArchitectureComputer Architecture
Computer Architecture
 
L3 ARITHMETIC OPERATIONS.pptx
L3 ARITHMETIC OPERATIONS.pptxL3 ARITHMETIC OPERATIONS.pptx
L3 ARITHMETIC OPERATIONS.pptx
 
Signed numbers in 8051
Signed numbers in 8051Signed numbers in 8051
Signed numbers in 8051
 
Hemanth143
Hemanth143 Hemanth143
Hemanth143
 
Comp Arithmetic Basic.ppt
Comp Arithmetic Basic.pptComp Arithmetic Basic.ppt
Comp Arithmetic Basic.ppt
 
CA UNIT II.pptx
CA UNIT II.pptxCA UNIT II.pptx
CA UNIT II.pptx
 
Counit2
Counit2Counit2
Counit2
 
ARITHMETIC FOR COMPUTERS
ARITHMETIC FOR COMPUTERS	  ARITHMETIC FOR COMPUTERS
ARITHMETIC FOR COMPUTERS
 
UNIT - I.pptx
UNIT - I.pptxUNIT - I.pptx
UNIT - I.pptx
 
UNIT - I.pptx
UNIT - I.pptxUNIT - I.pptx
UNIT - I.pptx
 
number system.ppt
number system.pptnumber system.ppt
number system.ppt
 
CA Unit ii
CA Unit iiCA Unit ii
CA Unit ii
 
tCh10.ppt
tCh10.ppttCh10.ppt
tCh10.ppt
 
Data representation notes class 11
Data representation notes class 11Data representation notes class 11
Data representation notes class 11
 

More from Nitin Ahire

Microprocessor 8086 8087_nitin ahire
Microprocessor 8086 8087_nitin ahireMicroprocessor 8086 8087_nitin ahire
Microprocessor 8086 8087_nitin ahireNitin Ahire
 
8051 Microcontroller
8051 Microcontroller8051 Microcontroller
8051 MicrocontrollerNitin Ahire
 
8085 ppi 8255 and 8155
8085 ppi 8255 and 81558085 ppi 8255 and 8155
8085 ppi 8255 and 8155Nitin Ahire
 
Addressing mode of 8051
Addressing mode of 8051Addressing mode of 8051
Addressing mode of 8051Nitin Ahire
 
8051 micro controllers Instruction set
8051 micro controllers Instruction set 8051 micro controllers Instruction set
8051 micro controllers Instruction set Nitin Ahire
 
8051 (microcontroller)class1
8051 (microcontroller)class18051 (microcontroller)class1
8051 (microcontroller)class1Nitin Ahire
 
Serial communication in 8085
Serial communication in 8085Serial communication in 8085
Serial communication in 8085Nitin Ahire
 
Interrupt of 8085
Interrupt of 8085Interrupt of 8085
Interrupt of 8085Nitin Ahire
 

More from Nitin Ahire (9)

Microprocessor 8086 8087_nitin ahire
Microprocessor 8086 8087_nitin ahireMicroprocessor 8086 8087_nitin ahire
Microprocessor 8086 8087_nitin ahire
 
8051 Microcontroller
8051 Microcontroller8051 Microcontroller
8051 Microcontroller
 
8085 ppi 8255 and 8155
8085 ppi 8255 and 81558085 ppi 8255 and 8155
8085 ppi 8255 and 8155
 
Microprocessor
MicroprocessorMicroprocessor
Microprocessor
 
Addressing mode of 8051
Addressing mode of 8051Addressing mode of 8051
Addressing mode of 8051
 
8051 micro controllers Instruction set
8051 micro controllers Instruction set 8051 micro controllers Instruction set
8051 micro controllers Instruction set
 
8051 (microcontroller)class1
8051 (microcontroller)class18051 (microcontroller)class1
8051 (microcontroller)class1
 
Serial communication in 8085
Serial communication in 8085Serial communication in 8085
Serial communication in 8085
 
Interrupt of 8085
Interrupt of 8085Interrupt of 8085
Interrupt of 8085
 

Recently uploaded

Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDGMarianaLemus7
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 

Recently uploaded (20)

Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDG
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 

8051 singed number concept [compatibility mode]

  • 1. Prof. Nitin Ahire 1 Singed number concept in 8051 Microcontroller Nitin Ahire XIE Mahim
  • 2. Prof. Nitin Ahire 2 Singed number concept • In everyday life, numbers are used that could be +Ve or –Ve • In the 8051 the MSB bit is set aside for the sign • If MSB(D7) =1 represent negative number • If MSB(D7) =0 represent positive numbers • The remaining bit D0 to D6 used for magnitude.
  • 3. Prof. Nitin Ahire 3 As 8051 is a 8 bit controller here we consider the 8 bit numbers D7 D6 D1D2D3D4D5 D0 SIGN MAGNITUDE
  • 4. Prof. Nitin Ahire 4 POSITIVE NUMBERS • The range of positive numbers can be represent by the format as shown in figure • It range from 0 to +127 0 0000 0000 +1 0000 0001 +5 0000 0101 +127 0111 1111
  • 5. Prof. Nitin Ahire 5 NEGATIVE NUMBERS • For negative number D7=1 however the magnitude is represented in it’s 2’s compliment form • Steps 1 write the magnitude of the number in 8 bit binary 2 invert each bit 3 add one to it
  • 6. Prof. Nitin Ahire 6 • Show how the 8051 would represent – 5 • Sol: 0000 0101 5 in 8-bit binary 1111 1010 invert bit 1111 1011 add 1 ( which is FB h )
  • 7. Prof. Nitin Ahire 7 • Show how the 8051 would represent -128 • Sol: 1000 0000 0111 1111 1000 0000 ( which become 80h)
  • 8. Prof. Nitin Ahire 8 Range of singed numbers • Decimal binary Hex -128 1000 0000 80 -127 1000 0001 81 -126 1000 0010 82 … ….. …… …. -2 1111 1110 FE -1 1111 1111 FF 0 0000 0000 00 +1 0000 0001 01 +2 0000 0010 02 … …… ……. …. +127 0111 1111 7F
  • 9. Prof. Nitin Ahire 9 Overflow problem in signed number • What is an overflow? • If the result of an operation on the signed numbers is too large for the register, an overflow has occurred CY AC -OVRS0RS1FO P
  • 10. Prof. Nitin Ahire 10 Example • Examine the following code and analyze the result MOV A,# +96 MOV R1, # +70 ADD A,R1
  • 11. Prof. Nitin Ahire 11 Solution + 96 0110 0000 60h + 70 0100 0110 46h -------- --------------- +166 1010 0110 A6 and OV =1 according to CPU the result -90h which is wrong. ( OV = 1) +166 is not the valid signed number. ( 0 to +127)
  • 12. Prof. Nitin Ahire 12 When is the OV flag set? 1. There is carry from D6 to D7 but no carry out of D7 (CY=0). 2. There is a carry from D7 out (CY=1) but no carry from D6 to D7.
  • 13. Prof. Nitin Ahire 13 Example 1 • MOV A, #-2 (FEh) ( 1111 1110) • MOV R1,#-5 (FBh) ( 1111 1011) • ADD A,R1 (F9h=-7, 1111 1001correct), • So CPU generate OV=0
  • 14. Prof. Nitin Ahire 14 Example 2 MOV A, #-128 ; (80H) MOV R4,#-2 (FEH) ADD A,R4 ( A=7EH =+127 INVALID ) So CPU generate OV =1
  • 15. Prof. Nitin Ahire 15 Example 3 • MOV A,#+7; A=0000 0111 (A=07H) • MOV R1,#+18; R1= 0001 0010 (R1=12H) • ADD A,R1; A=0001 1001 (A=19H=+25) According to CPU, this is +25, which is correct (OV=0)
  • 16. Prof. Nitin Ahire 16 • In any signed number addition OV indicates whether the result is valid or not • If OV=1, the result is erroneous • If OV=0, the result is valid.
  • 17. Prof. Nitin Ahire 17 BCD ADDITION • Assume that 5 BCD data items are stored in RAM location starting at 40H, write a program to find the sum of all numbers. The result must be in BCD.
  • 18. Prof. Nitin Ahire 18 • Data 40=(71) • 41=(11) • 42=(65) • 43=(59) • 44=(37)
  • 19. Prof. Nitin Ahire 19 Solution • MOV R0,#40H MOV R2,05H CLR A MOV R7,A AGAIN:ADD A,@R0 DA A JNC NEXT INC R7 NEXT: INC RO DJNZ R2,AGAIN END