Write a program to count the number of elements in an array
Solution
Mask => 10011000 => $98
Operand at the memory location pointed by 0,x 00100101 => Inv => 11011010
Operand provided by the mask in the instr => 10011000
AND result = 1
Execution will branch to the location specified in the label (yes)
//////////////////////CODE //////////////////////////////////////////////
N equ 12
org $900 ;starting address of the 1st element in the array
array db 1,2,3,4,5,6,7,8,9,10,11,12
total rmb 1 ;variable counting no.of elements with the pattern
org $C000 ;starting address of the program
clr total ;initializing counter to 0
ldx #array ;loading x with the address of the array, X= $900
ldab #N ;B is used as the loop counter
loop brset 0,x,$98,yes
bra chkend
yes inc total ;add 1 to total as the number has the required pattern
chkend inx ;move the array pointer
dbne b,loop
end
//////////////////////////////
