In: Electrical Engineering
Write an assembly language program for 8051 microcontroller to find the sum of the following
series,
1, -2, +3, -4, +5, -6,..., up to 100 terms.
Store lower byte in R0 and higher byte in R1.
// In the sereis all even numbers are negive and odd numbers are
positive
ORG 000h
MOV R1,#64H //Enter the final
number of Series
MOV A,#00H //Initilize
the Accumulator with zero
AGAIN:
MOV R0,R1 // Copy
the contenets of R1 to R0
RRC
R0
//Rotate R0 once to right if carry is zero then it is even number
else odd number
JNC EVEN_Number //if carry is not set then even nuber
and jump to EVEN_Number location
JC ODD_Number //if carry is set then odd
nuber and jump to ODD_Number location
EVEN_Number: CPL
R0
//ones complement R0
ADD R0, #01H //Add one to
complemented number
ODD_Number: ADD
A,R0 //Add Ro
to Acummulator
DJNZ R1, AGAIN //Decrement R1 if not zero jumber
AGAIN location else continue
MOV R2,A
//Move the final ansuer from Acummulator to R2
END
// End the program