Q.Briefly explain signed and unsigned subprogram
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]
Unsigned arithmetic treats all 8 bits as magnitude (0–255) and uses the CY flag, while signed arithmetic treats bit D7 as a sign, stores negatives in 2's complement, and uses the OV flag; the 8051 handles both, and signed subtraction with SUBB reads the carry to tell positive from negative.
The 8051 is an 8-bit machine that supports unsigned arithmetic operations directly, but by using the OV (overflow) flag it can carry out both signed and unsigned addition and subtraction.
Unsigned numbers:
- All 8 bits of the byte represent the magnitude, so the range is 0 to 255 (00H to FFH).
- There is no sign; the numbers are always treated as positive.
- The 8051 supports unsigned addition, subtraction, multiplication (MUL AB) and division (DIV AB) directly through its instructions.
- The carry flag (CY) tells the programmer whether the result was too large for 8 bits (a carry out of D7 in addition, or a borrow in subtraction).
Signed numbers:
- The most significant bit D7 is used as the sign bit: 0 means a positive number and 1 means a negative number; the remaining 7 bits give the magnitude.
- Negative numbers are stored in 2's-complement form (take the 1's complement using CPL, then increment with INC to get the 2's complement).
- The overflow flag (OV), not the carry flag, indicates whether a signed result is valid.
Signed and unsigned subtraction: the 8051 has only the SUBB (subtract with borrow) instruction, so to make a plain subtraction the carry is first cleared (CLR C). SUBB performs the subtraction using the 2's-complement method — the CPU takes the 2's complement of the source, adds it to the accumulator, and inverts the carry. Reading the carry then tells the sign of the result:
- If CY = 0 after SUBB, the result is positive. …
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.