Tuesday 24 February 2015

Sum of first 10 natural numbers

// A program to calculate the sum of first 10 numbers i.e. 1+2+...+10 //

                


                   ORG 0000H


                   MOV R1,#0AH               // loads R1 with 0Ah=10 //
                   MOV A,#00H
AGAIN:     ADD A,R1          //adding R1 & A's value, AGAIN is just a label ':' to point the address//
                  DJNZ R1, AGAIN       // Don't Jump till value Not Zero back to addition,if zero proceed//
                   DEC R1                          // DECrement of R1's value //
                   MOV R2,A                    // MOVe the final result in R2 (final answer is 37h=55) //



                   END

 

- R3DKn!9ht

No comments:

Post a Comment