Monday, May 9, 2016

Counting

1. Program to find number of 1's and 0's in a given 8-bit number.The number is stored at memory location 5001H. Store the count of 1's & 0's at 5002H & 5003H.


;<Program to find number of 1's and 0's in a given 8-bit number.
;The number is stored at memory location 5001H. Store the count of
;1's & 0's at 5002H & 5003H>
jmp start
;code
start: lda 5001H
mvi b,00H
mvi c,08H
loop: rlc
jnc skip
inr b
skip: dcr c
jnz loop
mov a,b
sta 5002H
mvi a,08H
sub b
sta 5003H
hlt
view raw bits_count.asm hosted with ❤ by GitHub
Screenshot before counting. See the content of memory location 5001H.


Screenshot of  result. See the content of memory location 5001H(number), 5002(no. of 1's) and 5003H(no. of 0's).



2.Program to find number of positive and negative numbers in an given array. The length of array is given at 5000H and the array is stored from 5001H.


;<Program to find number of positive and negative numbers in an given
; array. The length of array is given at 5000H and the array is stored
; from 5001H>
jmp start
;code
start: lda 5000H
mov b,a
mvi c,00H ; count for positive numbers
mvi d,00H ; count for negative numbers
lxi h,5001H
loop: mov a,m
cpi 80H
jnc pos1
inr c
jmp pos2
pos1: inr d
pos2: inx h
dcr b
jnz loop
mov a,c
sta 6001H
mov a,d
sta 6002H
hlt

 Screenshot before counting. See the contents from memory location 5000H.


 Screenshot of  result. See the contents from memory location 5001H.


No comments:

Post a Comment