2

It seems like blocks and loops can be synonymous to each other

block $loop
   foo
   br $loop
end

Here the branch instruction would transfer the control to the end which acts like a "break".

In case of a loop,

loop $loop
   foo
   br $loop
end

Here the control is transferred to the beginning.

This is confusing because I could write either synonymously to each other by removing the "br" and either would work as a normal loop with "break" and "continue" from what I can see. So, which one should be used when, and what is the reasoning behind this design choice? Is it trying to solve a particular problem with other ISAs?

I found this thread What's the difference between "block" and "loop" in WebAssembly spec? which talks about forward/backward jumpers, but I am still confused. A simple explanation about their use cases would be really nice!

1
  • 1
    Maybe don't name block labels with the word loop in it? Commented Apr 21, 2023 at 20:30

0

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.