Solved Examples · Example 8
Q.Analyse the following program.
CLR C
MOV A, #5CH ; load A with value 5CH (A = 5CH)
SUBB A, #7EH ; subtract 7EH from A
INC NEXT ; if CY = 0, jump to NEXT target
CPL A ; if CY = 1, then take 1's compliment
INC A ; and increment to get 2's compliment
NEXT: MOV R1, A ; save A in R1
CLR C
MOV A, #5CH ; load A with value 5CH (A = 5CH)
SUBB A, #7EH ; subtract 7EH from A
INC NEXT ; if CY = 0, jump to NEXT target
CPL A ; if CY = 1, then take 1's compliment
INC A ; and increment to get 2's compliment
NEXT: MOV R1, A ; save A in R1
Karnataka PUCTextbookNumericImportance★★★★★est
36% · 41/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]
SUBB of 7EH from 5CH borrows, so CY = 1 (negative); complementing and incrementing A recovers the magnitude 22H, i.e. the result is -22H.
Concept - sign of a SUBB result. After SUBB A, source, CY = 0 means the result is positive and already correct, while CY = 1 means the result is negative and A holds the 2's complement of the magnitude. The 2's complement is undone by taking the 1's complement (CPL A) and then incrementing (INC A). (The line commented "if CY = 0, jump to NEXT target" is intended as a jump-if-no-carry to the NEXT label.)
Trace:
CLR C- clear the carry so SUBB is a plain subtract.MOV A, #5CH- A = 5CH.SUBB A, #7EH- compute 5CH - 7EH. Since 5CH (92) < 7EH (126), a borrow occurs: CY = 1 and A holds the 2's complement of the magnitude.
A -> 5CH 0101 1100 0101 1100
7EH - 0111 1110 2's compl = + 1000 0010
----------- -----------
-22H 0 1101 1110 …
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.