Solved Examples · Example 7
Q.Subtract 23H from 3FH when CY = 0, write the program and solve.
Karnataka PUCTextbookNumericImportance★★★★★est
31% · 36/115 Questions
You're viewing a preview — the full solution, concept, methods & PYQ mapping are locked.
Start your 14-day free trial to unlock the full solution →[!TLDR]
Clear the carry, load 3FH into A and SUBB 23H; A becomes 1CH and CY = 0 marks a positive result.
Concept - subtraction with SUBB. The 8051 provides only SUBB A, source (subtract with borrow), which computes A = A - source - CY. To perform an ordinary subtraction the carry must be cleared first (CLR C) so that no borrow is included. Internally the processor takes the 2's complement of the source, adds it to A and inverts the carry; after the operation, CY = 0 means the result is positive while CY = 1 means it is negative (and A then holds the 2's complement of the magnitude).
Program:
CLR C ; make CY = 0
MOV A, #3FH ; load 3FH into A
MOV R3, #23H ; load 23H into R3
SUBB A, R3 ; A = A - R3, result in A
Working:
A -> 3FH 0011 1111 0011 1111
R3 -> 23H - 0010 0011 2's compl = + 1101 1101 …
Unlock everything free for 14 days
- Full step-by-step solutions
- Concept-first explanations
- Methods, shortcuts & mistakes
- PYQ mapping + timed mock tests
Full access for 14 days. No credit card required.