In: Computer Science
The first program is to count the number of zeros in $3855. Please
add comments to each line
org $1000
array db $38, $55 ; data to be tested
org $1100
zero_cnt ds.b 1
lp_cnt ds.b 1
org $1500
clr zero_cnt ;initialize the 0 count to 0
movb #16,lp_cnt
ldd array
again lsrd
bcs chk_end ;
inc zero_cnt
chk_end dec lp_cnt
bne again
swi
end
org $1000 # set the location counter to $1000
array db $38, $55 # data to be tested
initializes 2 bytes in memory to $38 $55 and the assembler will use array as the symbolic address of the first byte whose initial value is $38. The program can also force these 2 bytes to a certain address by adding the org directive. For example, the sequence
org $1000 db $38,$55 array
org $1100 # set the location counter to $1100
zero_cnt ds.b 1 # variable to store the number of zeroes
lp_cnt ds.b 1 # variable for the loop counter
org $1500 # set the location counter to $1500
clr zero_cnt # initialize the 0 count to 0
movb #16,lp_cnt # initialize lp_cnt to 16
ldd array #place 16 bit number in D
again lsrd #shift the lsb of D to the C flag
bcs chk_end #branch if the C flag (= LSB bits) is 1
inc zero_cnt #increment 0s count if the lsb is a 0
chk_end dec lp_cnt #check to see if D is already 0
bne again #check to see if we tested all
swi
end