SlideShare a Scribd company logo
6
Most read
8
Most read
10
Most read
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

PPTX
Signed numbers in 8051
PPTX
HUMAN FOLLOWING ROBOT
PPTX
Wi-Fi Esp8266 nodemcu
DOCX
Vhdl code and project report of arithmetic and logic unit
PPTX
PIC18 TIMER PROGRAMMING IN ASSEMBLY AND C
DOCX
Final Year Project report on quadcopter
PPTX
Arithmetic instructions
PPT
Chp6 assembly language programming for pic copy
Signed numbers in 8051
HUMAN FOLLOWING ROBOT
Wi-Fi Esp8266 nodemcu
Vhdl code and project report of arithmetic and logic unit
PIC18 TIMER PROGRAMMING IN ASSEMBLY AND C
Final Year Project report on quadcopter
Arithmetic instructions
Chp6 assembly language programming for pic copy

What's hot (20)

PPTX
Arduino Interfacing with different sensors and motor
PPTX
Iai eitan
PPTX
Unmanned Aerial Vehicle-UAVs
PPTX
Sniffer for detecting lost mobiles
PPTX
DIGITAL ELECTRONICS- Minimization Technique Karnaugh Map
PDF
3 jump, loop and call instructions
PPT
PDF
8051-mazidi-solution
PPTX
ACCIDENT DETECTION SYSTEM PPT
PPTX
Drone project 2020 GROUP PPT
PPTX
ANTI SLEEP ALARM
PPTX
Digital object counter (group 12)
PDF
Unmanned Aerial Vehicle for Surveillance
PDF
Copy of syed muhammad zaidi caa
PPTX
Autonomous car
PPTX
PDF
Project report on wireless based traffic control for emergency vehicle
PPTX
Arithmetic and logical instructions 8051 microcontroller
PPTX
Distance Measurement equipment (DME)
Arduino Interfacing with different sensors and motor
Iai eitan
Unmanned Aerial Vehicle-UAVs
Sniffer for detecting lost mobiles
DIGITAL ELECTRONICS- Minimization Technique Karnaugh Map
3 jump, loop and call instructions
8051-mazidi-solution
ACCIDENT DETECTION SYSTEM PPT
Drone project 2020 GROUP PPT
ANTI SLEEP ALARM
Digital object counter (group 12)
Unmanned Aerial Vehicle for Surveillance
Copy of syed muhammad zaidi caa
Autonomous car
Project report on wireless based traffic control for emergency vehicle
Arithmetic and logical instructions 8051 microcontroller
Distance Measurement equipment (DME)
Ad

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

PPTX
Unit-1 Digital Design and Binary Numbers:
PPTX
Representation Of Numbers and Characters
PPTX
Binary Arithmetic
PPTX
Parallel adders
PPTX
Computer Architecture
PPTX
Computer Architecture
PPTX
L3 ARITHMETIC OPERATIONS.pptx
PPTX
Hemanth143
PPT
Comp Arithmetic Basic.ppt
PPTX
CA UNIT II.pptx
PDF
Computer Architecture: ARITHMETIC FOR COMPUTERS
PDF
Module 1 Digital Logic Design .pptx.pdf
PDF
MCS222-DDCA-Lec.7-111111111111111111.pdf
PPT
Counit2
PPTX
ARITHMETIC FOR COMPUTERS
PPT
Single Precision Floating Point Format.ppt
PPTX
UNIT - I.pptx
PPTX
UNIT - I.pptx
PPT
chapter 3 000Number_Systems.ppt
Unit-1 Digital Design and Binary Numbers:
Representation Of Numbers and Characters
Binary Arithmetic
Parallel adders
Computer Architecture
Computer Architecture
L3 ARITHMETIC OPERATIONS.pptx
Hemanth143
Comp Arithmetic Basic.ppt
CA UNIT II.pptx
Computer Architecture: ARITHMETIC FOR COMPUTERS
Module 1 Digital Logic Design .pptx.pdf
MCS222-DDCA-Lec.7-111111111111111111.pdf
Counit2
ARITHMETIC FOR COMPUTERS
Single Precision Floating Point Format.ppt
UNIT - I.pptx
UNIT - I.pptx
chapter 3 000Number_Systems.ppt
Ad

More from Nitin Ahire (10)

PDF
Microprocessor 8086 8087_nitin ahire
PDF
8051 Microcontroller
PDF
8085 ppi 8255 and 8155
PPTX
Microprocessor
PPT
Addressing mode of 8051
PDF
8051 micro controllers Instruction set
PDF
8051 (microcontroller)class1
PDF
Serial communication in 8085
PPT
Interfacing of io device to 8085
PDF
Interrupt of 8085
Microprocessor 8086 8087_nitin ahire
8051 Microcontroller
8085 ppi 8255 and 8155
Microprocessor
Addressing mode of 8051
8051 micro controllers Instruction set
8051 (microcontroller)class1
Serial communication in 8085
Interfacing of io device to 8085
Interrupt of 8085

Recently uploaded (20)

PPTX
SOPHOS-XG Firewall Administrator PPT.pptx
PPTX
Group 1 Presentation -Planning and Decision Making .pptx
PDF
cuic standard and advanced reporting.pdf
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
Empathic Computing: Creating Shared Understanding
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
PDF
Machine learning based COVID-19 study performance prediction
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
Encapsulation theory and applications.pdf
PPTX
A Presentation on Artificial Intelligence
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PPTX
Big Data Technologies - Introduction.pptx
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Electronic commerce courselecture one. Pdf
PDF
A comparative analysis of optical character recognition models for extracting...
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
SOPHOS-XG Firewall Administrator PPT.pptx
Group 1 Presentation -Planning and Decision Making .pptx
cuic standard and advanced reporting.pdf
Programs and apps: productivity, graphics, security and other tools
Empathic Computing: Creating Shared Understanding
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Building Integrated photovoltaic BIPV_UPV.pdf
Advanced methodologies resolving dimensionality complications for autism neur...
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
Machine learning based COVID-19 study performance prediction
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Encapsulation theory and applications.pdf
A Presentation on Artificial Intelligence
MIND Revenue Release Quarter 2 2025 Press Release
Big Data Technologies - Introduction.pptx
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Network Security Unit 5.pdf for BCA BBA.
Electronic commerce courselecture one. Pdf
A comparative analysis of optical character recognition models for extracting...
Mobile App Security Testing_ A Comprehensive Guide.pdf

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