0% found this document useful (0 votes)
24 views

Number of Ones and Zeros in A Given Data

The document discusses several topics related to binary data including counting the number of ones and zeros in data, counting even and odd numbers in an array, finding the maximum and minimum number in an array, and converting between packed and unpacked BCD formats.

Uploaded by

Krishna Prasad
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views

Number of Ones and Zeros in A Given Data

The document discusses several topics related to binary data including counting the number of ones and zeros in data, counting even and odd numbers in an array, finding the maximum and minimum number in an array, and converting between packed and unpacked BCD formats.

Uploaded by

Krishna Prasad
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Number of ones and zeros in a given data

Example: Data 91H

9 1 C
1 0 0 1 0 0 0 1 0

8 times

RCR − Used to rotate bits of byte/word towards the right, i.e. JC − Used to jump if carry flag CF = 1

LSB to CF and CF to MSB.


JNC − Used to jump if no carry flag (CF = 0)
RCL − Used to rotate bits of byte/word towards the left,

MSB to CF and CF to LSB.


Even and odd number count in a given array of data

Example: Data 91H

9 1 C
1 0 0 1 0 0 0 1 0

1 time

RCR − Used to rotate bits of byte/word towards the right, i.e. JC − Used to jump if carry flag CF = 1

LSB to CF and CF to MSB.


JNC − Used to jump if no carry flag (CF = 0)
Maximum and minimum number in a given array

Example: Data 91H

CHECK CF
CMP CX BX CX > BX (CF=0)
CX < BX (CF=0)

Repeat for entire string

CMP – CMP Destination, Source

JC − Used to jump if carry flag CF = 1

JNC − Used to jump if no carry flag (CF = 0)


Conversion of packed BCD to unpacked BCD

Unpacked BCD: Conversion Packed BCD to unpacked BCd:

-By using AND,F0H for upper Example: Decimal number 89h


- One digit per Byte
nibble
Example: Decimal number 8 Packed BCD value = 1000 1001
-By using AND,0FH for lower
Unpacked BCD value = 0000 1000 nibble
1 0 0 0 1 0 0 1

upper nibble Lower nibble


0 0 0 0 1 0 0 0

upper nibble Lower nibble


0 0 0 0 1 0 0 0
08H
0 0 0 0 1 0 0 1
09H

You might also like