Program to find the sum of all negative numbers stored in an array.
This program finds the negative numbers in an array and adds them.Basically negative number is one whose carry bit is 1.
1)Initializing register R0 with the array address and register R1 with counter.
2)Storing the first value of array in accumalator.
3)Rotating it left to check whether the carry bit is 1 or 0.
4)If carry bit is 1 adding and if the carry bit 0 then repeating the above steps.
5)Repeating all the above steps till the counter is 0.
Code goes here:
<br />ORG 0000h<br />LJMP MAIN<br />ORG 40h<br />MAIN: MOV R0,#0XA0 ; the address of the stored array<br /> MOV R1,#10 ;the counter which counts the numbers stored in array<br /> MOV R2,#00<br />LOOP: MOV A,@R0<br /> RLC A ; rotating right to check whether the carry bit is 1<br /> JNC LABEL1 ; if the carry bit is 0 then it is positive so it should not be added and jump to label1<br /> MOV A,@R0<br /> ADD A,R2 ;adding if the number is negative<br /> MOV R2,A<br />LABEL1: INC R0<br /> DJNZ R1,LOOP ;checking the counter<br /> END<br /><br />