In: Computer Science
Greetings!!
Code:
;MAIN STARTS HERE
.CODE
MOV AX,@DATA
MOV DS,AX
CALL COUNT ;calling COUNT procedure to count the occurance of
AA
HLT
;MAIN ENDS HERE
;procedure count definition
PROC COUNT NEAR
MOV AX,0 ;initialize AX with 0 for counting
MOV CX,100 ;load count into CX register[130A-120A=100].
MOV SI,120AH ;load the starting address into SI for reading the
element from the memory
NEXT:
MOV BL,[SI] ;load the number into BL
INC SI ;point to next element in the memory
CMP AL,99H ;check the count less than 99
JNE CONTINUE ;if not 99 then continue
CALL TOBCD ;if 99 call TOBCD procedure
CONTINUE:
CMP BL,0AAH ;compare the number loaded from memory is AA or
not
JNZ SKIP ;if not AA then skip
ADD AL,1 ;if AA, then increment the COUNT in AL
DAA ;adjust to BCD after each addition
SKIP:
LOOP NEXT ;repeat the process
RET
;DEFINITION OF TOBCD FUNCTION
PROC TOBCD NEAR
INC AH ;increment AH if the count in AL is 99
MOV AL,00 ;clear the AL count and start from 0 again
RET
Output screenshot:
Tested with more than 100 elements Iin an array and the count is shown below
Hope this helps