We can apply if statement by using the following method. This is how we generally define If statement.
if ( condition )
{
----statement----------
}
The part in the curly bracket can be replaced by assigning a label
krm : --------------------------------------------
------Statement/Code-------------
--------------------------------------------
Here condition can have three types :
1) a<b
2) a==b
3) a>b
We will see how to convert each condition in assembly language.
Let assume b=05H and if the condition is true then Program Counter should go to label krm. Value of a is in the accumulator.
1)if( a<b)
For less than condition use following code
CJNE A,#05H,dio
dio : JC krm
2) if(a==b)
For equality condition use following code :
CJNE A,#05H,krm
3) if(a>b)
For greater than condition use following code
CJNE A,#05H,dio
dio : JNC krm
Here we have considered that data with which we want to compare the value of b is in accumulator. You can take other registers also like R0,R1 etc. To know more about how to use CJNE instruction visit on below link.
if ( condition )
{
----statement----------
}
The part in the curly bracket can be replaced by assigning a label
krm : --------------------------------------------
------Statement/Code-------------
--------------------------------------------
Here condition can have three types :
1) a<b
2) a==b
3) a>b
We will see how to convert each condition in assembly language.
Let assume b=05H and if the condition is true then Program Counter should go to label krm. Value of a is in the accumulator.
1)if( a<b)
For less than condition use following code
CJNE A,#05H,dio
dio : JC krm
2) if(a==b)
For equality condition use following code :
CJNE A,#05H,krm
3) if(a>b)
For greater than condition use following code
CJNE A,#05H,dio
dio : JNC krm
Here we have considered that data with which we want to compare the value of b is in accumulator. You can take other registers also like R0,R1 etc. To know more about how to use CJNE instruction visit on below link.