38 Program to find number of 0's from 16 bit number in 8086 Microprocessor

Code:

; Program to find number of 0s from 16 bit number
.MODEL SMALL
.STACK 100H
.DATA
   NUM DW 1234H
   COUNT DB 0H
.CODE
   MOV AX , @DATA   ;Initializing Data Segment
   MOV DS , AX

   MOV AX , NUM
   MOV CX , 16
   MOV BL , 00
   NEXT:
      ROR AX , 1H     ; Rotate right by 1 bit
      JC UP          ; Jump if carry
      INC BL     ; INC COUNT       
   UP:
      LOOP NEXT      ; Decrement CX if cx == 0 then exit

   MOV COUNT , BL

   MOV DH , 00
   MOV DL , COUNT
   MOV AH , 2        ; Service routine to print contain of DX
   INT 21H

   MOV AH , 4CH      ; Service routine 4ch to exit
   INT 21H
END




Ouput:


In this we have num = 1234H which is in binary = 0001 0010 0011 0100. 
So the number of zeros are : 11 which is in hexadecimal = B


To count zeros in 16bit number in 8086

Previous
Next Post »