ARITHMETIC INSTRUCTIONS 

The arithmetic operations modify arithmetic flags carry (CY or C), overflow (OV) and auxiliary carry (AC). 

  • Addition 
  • Subtraction 
  • Signed arithmetic 
  • Decimal (Binary Coded Decimal -BCD) arithmetic 
  • Multiplication 
  • Division 
  • Increment and decrement

Addition

The 8051 support both additions. 
  • Half addition 
  • Full addition 

The half addition is used to add two operands (of 8 bits each) specified in an instruction. The full addition includes carry flag in the addition


Half addition 


ADD A, source // A=A+ source. 
                            // Add contents of A with operand source and place result in to A. 

ADD A, #data // add contents of A with immediate data and store result in A 
ADD A, #10H // A= A+10H, If A=05H→A=05H+10H=15H, C=0 ADD A, Rn 
                        // add contents of A with contents of Rn and store result in A 
ADD A, R0 // A = A+ R0, If A= F5H, R0=10H → A=F5H+10H=05H, C=1 

ADD A, direct // add A with contents of address direct and store result in A 
ADD A, 40H // A= A + (40H), If A=10H, (40H) =15H → A=10H+15H=25H, C=0 

ADD A, @Ri // add A with contents of address in Ri, store result in A 
ADD A, @R0 // A= A+ (R0), If A=20H, R0=10H, (10H) =30H
                         //→A=20H+ (10H) = 20H+30H=50H,C=0


Full addition 


ADDC A, #data // add contents of A, immediate data and carry, store result in A // i.e. A = A + data + C 
ADDC A, #10H // A= A+10H+C, If A=05H, C=1→A=05H+10H+1=16H, C=0 

ADDC A, Rn // add contents of A, contents of Rn and carry, store result in A // i.e. A= A+ Rn + C 
ADDC A, R0 //A=A+ R0+C,If A=20H,R0=30H,C=0→A=20H+30H+0=50H, C=0 

ADDC A, direct // add A, contents of address direct and carry, store result in A // i.e. A= A+ (direct) + C 
ADDC A, 40H // A= A + (40H) +C, If A=F0H, (40H) =15H, C=1 → // A=F0H+15H+1=06H, C=1 

ADDC A, @Ri // add contents A, contents of address in Ri and C, store result in A // A= A+ (Ri) + C 
ADDC A, @R0 // A= A+ (R0) + C, If A=20H, R0=10H, (10H) =30H ,C=1 //→A=20H+ (10H)+1 = 20H+30H+1=51H,C=0



Subtraction 


The mnemonic for subtraction is SUBB, it means subtract with borrow. 

SUBB A, source // A= A – source – CY // subtract carry and operand source from A and place result in to A.
 SUBB A, #data // subtract immediate data and carry from A, store result in A // i.e. A = A – data – C 
SUBB A, #10H // A= A–10H–C, If A=20H, C=1→ A=20H–10H–1=0FH, C=0 

SUBB A, Rn // subtract contents of Rn and carry from A, store result in A // i.e. A= A– Rn – C 
SUBB A, R0 //A= A– R0–C, If A=30H, R0=20H,C=0 → A=30H–20H–0=10H, C=0 

SUBB A, direct // subtract contents of address direct and carry from A, store result in A // i.e. A= A– (direct) – C 
SUBB A, 40H // A= A – (40H) –C, If A=10H, (40H) =15H, C=0 → // A=10H–15H–0=FBH, C=1 

SUBB A, @Ri // subtract contents of address in Ri and C from A, store result in A // A= A– (Ri) – C 
SUBB A, @R0 // A= A– (R0)–C, If A=50H, R0=10H, (10H) =30H ,C=1 //→A=50H– (10H)–1 = 50H–30H–1=1FH, C=0



Signed arithmetic 


 Positive numbers 

Bit D7 is ‘0’ for positive numbers , since only seven bits (D0 to D6) are used for magnitude, the range of positive number that can be represented by 8 bit signed number is 0 to +127.

Negative numbers 

Bit D7 is 1 for negative numbers, however, negative numbers are not represented in true binary form, but it is represented in 2’s complement form. 






There are four types of operations in signed arithmetic






1. Addition of unlike signed numbers 

When unlike signed number are added then result will be always within a range of –128d to +127d

Example: Add –02d with +30d




2. Addition of like signed numbers


 If two positive numbers are added, it is possible that sum may exceed +127d.

 Example : Add +40d with +70d






3. Subtraction of unlike signed numbers


 If two, unlike numbers, are subtracted, it is possible that the result may exceed the range of –128d to +127d. 

Example : Subtract +100d from –70d




There is borrow in to bit portion of 6 but not in to bit7. OV=1 and C=0. Because OV=1, the result is incorrect.


4. Subtraction of like signed numbers


 The situation here is similar to adding unlike numbers. The result will be always correct i.e always within the range –128 to +127. 

Example : Subtract +120d from +101d






Decimal (Binary Coded Decimal - BCD) arithmetic 


The binary representation of decimal digits (0 to 9) is called binary coded decimal. Four bits are required to represent the decimal number from 0 to 9

There are two types of BCD. 
1. Unpacked BCD 
2. Packed BCD 



  • Unpacked BCD

 In unpacked BCD numbers the lower four bits of the number are used to represent the decimal digit and the upper four bits are 0. 

  • Packed 

BCD In packed BCD numbers two BCD numbers are placed (packed) in to a single byte.


• DA A 


Decimal adjust Accumulator for addition. 

DA A works only on the contents of register A, it must be kept in mind that DA A must be used after the addition of BCD numbers and BCD numbers can never have any digit greater than 9. 

Operation of DA A 

DA A instruction performs the following operations. After ADD or ADDC instruction,
 If lower nibble is greater than 9 or if AC=1, add 6 to lower nibble (4 bits) 
If upper nibble is greater than 9 or if CY=1, add 6 to upper nibble.



Multiplication 


The 8051 supports 8 bit integer multiplication. Multiplication instruction uses only A and B registers as both source and destination for the operation. 
MUL AB // multiply contents A with B; put the lower byte of result in A 
// higher byte of result in B. 

Division 


The 8051 supports 8 bit integer division. Divide instruction uses only A and B registers as both source and destination for the operation. The number in A is divided by number in B. Quotient (result) is placed in A and remainder is placed in B. 

DIV AB // divide A by B,store the result in A and remainder in B 

Increment and decrement 


INC destination // add one to the destination operand 
DEC destination // subtract one form the destination operand 

INC INC A // Increment the contents of A by 1, A=A+1 
INC A // A=A+1, If A=10H→A=11H 

INC Rn // Increment the contents of Rn by 1, Rn= Rn+1 
INC R3 // R3= R3+1, If R3=1AH→ R3=1BH 

INC @Ri // Increment the contents of address pointed by Ri by 1, (Ri)= (Ri) +1 
INC @R0 // (R0)= (R0) +1, If R0=10H, (10H)=55H→ (R0)=(10H)=56H 

INC direct // Increment the contents of direct address by 1, (direct)=(direct) +1 
INC 40H // (40H)=(40H)+1, If (40H)=1FH → (40H)=20H
INC DPTR // Increment the contents of DPTR by 1, DPTR=DPTR+1 INC DPTR 
// DPTR=DPTR+1, If DPTR=1000H→ DPTR=1001H 

DEC DEC A // Decrement the contents of A by 1,A=A–1 
DEC A //A=A–1,IfA=10H→A=0FH 

DEC Rn // Decrement the contents of Rn by 1, Rn= Rn–1 
DEC R3 // R3= R3–1, If R3=1AH→ R3=19H 

DEC @Ri // Decrement the contents of address pointed by Ri by 1,(Ri)= (Ri) –1 
DEC @R0 // (R0)= (R0) –1, If R0=10H,(10H)=55H→ (R0)=(10H)=54H 

DEC direct //Decrement the contents of direct address by 1 (direct)=(direct) –1 
DEC 40H // (40H)=(40H) –1, If (40H)=1FH → (40H)=1EH 

It should be noted that there is no DEC DPTR instruction. 

LOGICAL INSTRUCTIONS 


1. Byte operations 
2. Unary operations 

1. Byte operations 
 AND operation 
 OR operation 
 EX-OR operation 

2. Unary operations 
 Clear 
 Complement 
 Rotate 
 SWAP 
 







Post a Comment

Previous Post Next Post