Code:
; PROGRAM TO ADDITION OF 8 BIT NUMBERS
; IN SERIES RESULT MAY BE GREATER THAN 16 BIT
.MODEL SMALL
.STACK 100H
.DATA
ARR1 DB 05FH,0F5H,08FH,0FFH,0FFH
SUM_LSB DB 0
SUM_MSB DB 0
.CODE
MOV AX , @DATA ; Initializing data segement
MOV DS , AX
MOV SI , OFFSET ARR1 ; Storing base address of ARR1
MOV CX , 5 ; Initializing CX to 5
CONT:
MOV AL , [SI] ; READ BYTE FROM MEMORY
ADD SUM_LSB , AL ; ADD WITH SUM
JNC NEXT ; IF SUM > 8 BIT
INC SUM_MSB
NEXT:
INC SI ; INCREMENT MEMORY POINTER
LOOP CONT ; DECREMENT COUNTER POINTER
; IF COUNTER == 0 THEN EXIT
; ELSE READ NEXT NUMBER
MOV DL , SUM_MSB ; Printing MSB value
MOV AH , 2
INT 21H
MOV DL , SUM_LSB ; Printing LSB value
MOV AH , 2
INT 21H
MOV AH , 4CH ; EXIT
INT 21H
END
Ouput:
; PROGRAM TO ADDITION OF 8 BIT NUMBERS
; IN SERIES RESULT MAY BE GREATER THAN 16 BIT
.MODEL SMALL
.STACK 100H
.DATA
ARR1 DB 05FH,0F5H,08FH,0FFH,0FFH
SUM_LSB DB 0
SUM_MSB DB 0
.CODE
MOV AX , @DATA ; Initializing data segement
MOV DS , AX
MOV SI , OFFSET ARR1 ; Storing base address of ARR1
MOV CX , 5 ; Initializing CX to 5
CONT:
MOV AL , [SI] ; READ BYTE FROM MEMORY
ADD SUM_LSB , AL ; ADD WITH SUM
JNC NEXT ; IF SUM > 8 BIT
INC SUM_MSB
NEXT:
INC SI ; INCREMENT MEMORY POINTER
LOOP CONT ; DECREMENT COUNTER POINTER
; IF COUNTER == 0 THEN EXIT
; ELSE READ NEXT NUMBER
MOV DL , SUM_MSB ; Printing MSB value
MOV AH , 2
INT 21H
MOV DL , SUM_LSB ; Printing LSB value
MOV AH , 2
INT 21H
MOV AH , 4CH ; EXIT
INT 21H
END