Skip to main content

0s and 1s Count in 1 Byte Memory Word

This program will count all the 1s and 0s individualy presents in a 1 byte word. And store the result in individual places in Memory. Suppose, argument byte is stored in memory location 2050H and store the result of 1's count at 2060H memory location and 0's at 2061H

;Initiate 1's Counter
Memory LocationHex CodeLabelMnemonicsComment
3050
3051
3052
3A
50
20
START:LDA 2050H;Load Accumulator with the number stored at location 2050H
3053
3054
06
00
MVI B, 00H;Initiate 0's Counter
3055
3056
0E
00
MVI C, 00H
3057
3058
16
08
MVI D, 08H;Initiate Bit Counter
305907LOOP:RLC;Rotate Accumulator Left with Carry
305A
305B
305C
DA
61
30
JC ONE;If 1 is found count 1
305D04INR B;If 1 is not found it must be 0. So increase 0's Counter
305E
305F
3060
D2
62
30
JNC NEXT;Go to next Bit
30610CONE:INR C;Increase 1's Counter
306215NEXT:DCR D;Decrease the Bit Counter
3063
3064
3065
C2
59
30
JNZ LOOP;If all Bits is not checked execute for next Bit
306679MOV A, C;Move 1's Count Result to Accumulator
3067
3068
3069
32
60
20
STA 2060H;Store the Result for 1's Count
306A78MOV A, B;Move 0's Count Result to Accumulator
306B
306C
306D
32
61
20
STA 2061H;Store the Result for 0's Count
306E76HLT;End of the Program
Above program can be modified as,
  1. Count 1s from the Byte
  2. Store the Result for 1s count
  3. Deduce this result from 8
  4. Store the Result for 0s count (what is work out by deduction)

Comments

Popular posts from this blog

2's Complement of 2Byte Number

This program will work out the 2's Complement of a 2 Byte Number. As Microprocessor can perform 8 bits at a time in Accumulator, so we follow the foloowing Algo Fetch the 2 Byte Number in a Register Pair Bring Least Significant Byte of the Number from last Register into A (Accumulator) Make Complement of A and add 1 Store back the Updated LSByte into its source Register Bring MSByte of the Number from another Register into A Make Complement of A and add 1 if carry was genetrated at the time of LSByte opeartion Store back the Updated MSByte into its source Register Store the Result to a Memory location Suppose, Argument Number is stored in Location 1000H and 1001H Memory Location and store the value in 2000H and 2001H Memory Locations. Memory Location Hex Code Label Mnemonics Comment 3050 3051 3052 2A 00 10 START: LHLD 1000H ;Load the HL Register Pair with the content of Memory Location 1000H and 1001H 3053 7D MOV A, L ;Move the Content of L to A ( Accumulator ) 3054 2F

Flip-Flop Conversion

Flip-Flop is a memory element. You can say a basic element. It is a circuit that can hold a binary state (0 or 1 as low or high volts) until an input to change that state. We have many flip-flops as SR Flip-Flop (Set Reset) D Flip-Flop (Data) JK Flip-Flop T Flip-Flop (Toggle) Those Flip-Flops are available in market in IC Package Form. Now You have a circuit that uses 1 JK and 1 D Flip-Flop and 3 NOT Gates. So you have to buy three ICs- one for JK, one for D and other for NOT Gate. Ultimately you will see that a flip flop in IC of JK, a flip-flop in D IC and 3 NOT gates are not used. Now, if you convert a JK flip flop into D flip flop then you didn’t have to pay for the D flip flop IC. So, your circuit will be made by 2 ICs in place of 3 and in cheap cost. This article is for that reason. How the Flip-Flops are converted from one to other. Procedure: 1. Write Qt and Qt+1 Table with 4 combination of 0 and 1. 2. Write columns for inputs of destination Flop-Fl op. 3. Write the ce

How to set Set-Top Box to Resume automatically to last Channel after switch on?

How to set customised automatic Resume Channel to last viewed in Set-Top Box?  Introduction In the era of Digitally fast growing life WiFi enabled smart devices and also voice controlled smart devices are trying to be companion of every human being. But, all human do not change their habit at the same time. It may be cause of mental attachment or financial limits or unwillingness or though as unnecessary. What ever the reason may be, there exists the old technology, like IR(Infrared), RF(Radio Frequency), etc. So, this article for them who are using "Un-smart" TV like me in this time of Smart World. I was searching for a solution to set my Set-top Box of Videocon DTH (controlled by a RF Remote) to resume the last viewed channel when I power on my TV anytime. Suppose, I was watching NAT-Geo and switch off my (Un-smart) TV, even switch off the plug power at board. Now, after some time / on the next day, when I switch on my TV it will directly tune to the last viewed channel, i.