TITLE Sum of a long integer array ARAY_SUM.ASM
COMMENT |
Objective: To find sum of all elements of an array.
Input: None.
| Output: Displays the sum.
.MODEL SMALL
.STACK 100H
.DATA
value_A DB 8 DUP(?)
value_B DB 8 DUP(?)
char_prompt DB 'Please input a character: ',0
query_msg DB 'Do you want to continue (Y/N): ',0
.CODE
.486
INCLUDE io.mac
main PROC
.STARTUP
read_char:
;----------------------
PutStr char_prompt
mov AH,01h
int 21h
nwln
mov value_A,AL
;----------------------
PutStr char_prompt
mov AH,01h
int 21h
nwln
mov value_B,AL
;----------------------
mov CX,8
sub EAX,EAX ; sum := 0
sub ESI,ESI ; array index := 0
sub AH, AH ; set 8 bit register AH to 0
;----------------------
test_bit:
mov EBX,value_A[ESI*2]
test EAX,value_B[ESI*2]
jnz inc_count
jmp skip
inc_count:
inc AH
skip:
inc ESI
loop test_bit
nwln
PutInt AH
nwln
PutStr query_msg
GetCh AL
nwln
cmp AL,'Y'
jne read_char
done:
.EXIT
main ENDP
END main