edited by
1,836 views
5 votes
5 votes

Is the following code template for the if-then-else statement correct? if not, correct it.

  • $\text{if} \text{ expression then statement } 1$
    $\text{else statement }2$

Template:

Code for expression

  • (*result in $E, E > O$ indicates true *)
  • Branch on $E > O$ to $L1$
  • Code for statement $1$
  • $L1$: Code for statement $2$
edited by

2 Answers

Best answer
18 votes
18 votes

The given template is wrong. The following should be correct:

Code for Expression

  • Branch on $E>0$ to $L$
  • Code for segment $2$
  • Branch to $L1$
  • $L$: Code for statement $1$
  • $L1$:
edited by
0 votes
0 votes

What is expected from the code:

“if expression is true execute statement 1, else execute statement 2.”

What given code is doing:

“if expression (E > 0) is true execute statement 2, else execute statement 1.”

Modified Template:

Code for expression

  • (*result in E, E>O indicates true *)
  • Branch on E>O to L1
  • Code for statement 2
  • L1: Code for statement 1

Related questions

1 votes
1 votes
1 answer
1
makhdoom ghaya asked Nov 30, 2016
725 views
Consider the definition of macro $B,$ nested within the definition of a macro $A.$ Can a call to macro $B$ also appear within macro $A?$ If not, why not? If yes, explain ...
43 votes
43 votes
2 answers
2
makhdoom ghaya asked Nov 27, 2016
6,401 views
The number of possible commutative binary operations that can be defined on a set of $n$ elements (for a given $n$) is ___________.
3 votes
3 votes
1 answer
4
makhdoom ghaya asked Dec 5, 2016
1,271 views
Will recursion work correctly in a language with static allocation of all variables? Explain.