forked from YatinAdityaT/8085
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAdd_odds
64 lines (49 loc) · 1.12 KB
/
Add_odds
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
;Calculate the sum of series of odd numbers from the list of numbers. The length
;of the list is in memory location 2200H and the series itself begins from memory
;location 2201H. Assume the sum to be 8 bit number so you can ignore carry and store
;the sum at memory location 2210H.
JMP START
START: MVI A,05; LENGTH OF LIST
STA 2200;
; ELEMENTS OF LIST:
MVI A,01;
STA 2201;
STA 2203;
MVI A,03;
STA 2202
STA 2204
MVI A,02;
STA 2205
; ACTUAL PROGRAM ;
LXI H,2201; LOAD FIRST ELEMENT ADDRESS
LDA 2200;
MOV B,A; STORE NUMBER OF ELEMENTS IN B
MVI C,0;
LXI D,0; CLEAR DE PAIR
MVI A,0; CLEAR A
DCR B;
REPEAT: MOV A,M; MOVE CONTENTS OF MEMEORY TO A
CALL CHECK; CHECK IF ODD
JNC DONTADD;
MOV A,C;
ADD M;
MOV C,A;
DONTADD: INX H; INCREMENT HL PAIR
DCR B; DEC COUNTER
JNZ REPEAT
MOV A,C;
STA 2210;
HLT
CHECK: CPI 02; COMPARE WITH 2
JP ISBIG;
CPI 01; COMPARE WITH 1
JNZ EXIT; IF FLAG NOT 0 THEN A IS 0
STC; ELSE SET CARRY TO INDICATE ODD
JMP EXIT
ISBIG: SUI 02; A-2=>A
JZ EXIT; IS A BECOMES 0 THEN EVEN
JP JUMP;
STC; ELSE SET CARRY TO INDICATE ODD
JMP EXIT; EXIT
JUMP: JMP ISBIG
EXIT: RET