-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathAdd_n_8_bit_numbers.asm
30 lines (22 loc) · 989 Bytes
/
Add_n_8_bit_numbers.asm
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
;8085 Program to add
;n 8-bit numbers
;addition of n 8-bit numbers can give 16-bit
;answer, so we use A register to store the
;lower order 8-bit and D to store the higher
;order 8-bit of the answer
LXI H, 5000 ;starting address, stores size of array
MOV C, M ;store array size in C
MVI D, 00 ;initialize D to 0
INX H ;increment address
MOV A, M ;store 1st value in A
Loop: DCR C ;decrement counter
JZ Exit ;if counter = 0, jump to Exit
INX H ;increment address
ADD M ;add next value to A
JNC Skip ;if carry is not generated, jump to skip
INR D ;increment D (if carry is generated)
Skip: JMP Loop ;jump to Loop
Exit: STA 5501 ;store A, lower order answer in memory location 5501
MOV A, D ;move higher order (D) into A
STA 5500 ;store A, higher order answer in memory location 5500
HLT ;HALT program