Assembly language program to take the input of of N numbers from memory location 2201 and store sum of even number at 2210 and sum of odd number at 2211
Program:
LDA 2200
MOV C,A ;C=4
MVI B,0 ;B=0 FOR EVEN
MVI D,0 ;D=0 FOR ODD
LXI H,2201
BACK: MOV A,M ;A=1 FROM
2201,A=2,3,4
ANI 01 ;AND 01 WITH A FOR
CHECKING EVEN OR ODD
JNZ ODD ; ODD IF NOT 0 THAT
IS 1,0,1,0
MOV A,B ;FOR EVEN A=B=>0,2
ADD M ;A=A+M=>0+2=2
,2+4=6
MOV B,A ;NOW B=2,6
JMP NEXT ; NEXT ADDRESS
ODD: MOV A,D ;A=D=>0,1
ADD M
;A=A+M=>0+1=1,1+3=4
MOV D,A ;D=A=>1,4
NEXT: INX H ;INCREMENT MEMORY
POINTER THAT IS 2202,2203,2204
DCR C ;C=3,2,1,0
JNZ BACK
MOV A,B
STA 2210
MOV A,D
STA 2211
HLT
Result:
Memory Location
|
Data value
|
2200
|
4
(Counter)
|
2201
|
1
|
2202
|
2
|
2203
|
3
|
2204
|
4
|
2210
|
6 (Sum
of even numbers)
|
2211
|
4 (Sum
of odd numbers)
|
Comments
Post a Comment