5

As titled, the spec says that "loop" is

a block with a label at the beginning which may be used to form loops.

and for "block":

the beginning of a block construct, a sequence of instructions with a label at the end.

But with the help of "br" (used for switching branch to a labeled block), I can form the same control structure even with "block", right?. So, what's the difference between these two instructions?

2 Answers 2

8

A br to a block label jumps to the end of the contained instruction sequence -- it behaves like a break statement in C.

A br to a loop label jumps to the start of the contained instruction sequence -- it behaves like a continue statement in C.

The former enables a forward jump, the latter a backwards jump. Neither can express the other.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks Andreas, the "br" and "br_if" instructions have one immediate operand stands for "relative_depth", what's the usage of this immediate?
It denotes the jump target, counting blocks inside out.
0

No you can't block has the label at end as it sayed block has the label at the end

LOOP START
label:
SOME CODE
IF condtion BR label:
EVEN MORE CODE
LOOP END

Will execute SOME CODE once. Than repeats SOME CODE until condition is not true. And than execute EVEN MORE CODE

BLOCK START
SOME CODE
IF condition BR label:
EVEN MORE CODE
label:
BLOCK END

Will execute SOME CODE only once. And than EVEN MORE CODE might be execute when contdtion is not true.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.