Search code examples
assemblygoto

How to avoid goto and jump when coding in assembly?


I'm aware of the numerous posts here and elsewhere on avoiding goto in high-level programming languages. However from the (admittedly small) experience I've had coding in MIPS assembly, there doesn't seem to be an obvious way to avoid goto and jump statements in assembly when implementing control flow.

For example how would this code be implemented in assembly (C equivalent):

if (x < 2)
  { ans = 0; }
else
  { ans = 1; } 

Would the use of a goto or jump statement be necessary, or is there a proper way of avoiding them in favor of more appropriate code practices?


Solution

  • The recommendation to avoid goto in high-level programming languages only applies to - well - high-level languages.

    Assembler is a low-level language and jumps are essential.