Using “If else” condition in Assembly language

FAQ about “IF…ELSE” condition in assembly language.

if else flow in assembly language

Usin If…else condition in assembly language can be fun

Question: Can we use “if….else” condition in assembly language?

Ans: Yes!!!!

Question: How to use “IF….ELSE” in assembly language?

Ans: you can access “IF….ELSE” same as any other higher level language.

Question: What is the syntax of “IF….ELSE” statement in assembly language?

Ans: This depends mostly in assembler to assembler but here is the example for Keil software which is widely used in development of 8051 and ARM series microcontrollers.

$IF (SWITCH = 1)
;
;your statements here
;
$ELSEIF (SWITCH = 2)
;
;your statements here
;
$ELSE
;
;your statements here
;
$ENDIF

Question: Do the syntax remain same for all the microcontroller and microprocessors?

Ans: No, you have to refer the device specific data sheet for that information.

Keil declares as “$if” where in some other there is “.if” there may be many other variants also.

 

Question: what other statements can i use other than “IF….ELSE”?

Ans :There are other statements also available for assembly language than “IF….ELSE” these are listed below

$IF Assemble block if condition is true.
$ELSE Assemble block if the condition of a previous $IF is false.
$ELSEIF Assemble block if condition is true and a previous $IF or $ELSEIF is false.
$ENDIF Ends a $IF block.
$SET Sets symbols, which may be tested by $IF or $ELSEIF, to true or a specified value.
$RESET Sets symbols, which may be tested by $IF or $ELSEIF, to false.
IF Assemble block if condition is true.
ELSE Assemble block if the condition of a previous IF is false.
ELSEIF Assemble block if condition is true and a previous IF or ELSEIF is false.
ENDIF Ends a IF block.

 

Go ahead do some programming in assembly language.

Reference: http://www.keil.com/support/man/docs/a51/a51_if.htm

 

If there are any questions or suggestions do let us know by commenting below.

Incoming search terms:

Amazon Auto Links: the template could not be found. Try reselecting the template in the unit option page.

by

Comments

  1. Bhavin Patel says:

    nice one…

Speak Your Mind

*